How to use the koji.ActionNotAllowed function in koji

To help you get started, we’ve selected a few koji examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github koji-project / koji / tests / test_hub / test_user_groups.py View on Github external
def test_add_group_member(self):
        group, gid = 'test_group', 1
        user, uid = 'username', 2

        # no permission
        self.context.session.assertPerm.side_effect = koji.ActionNotAllowed
        with self.assertRaises(koji.ActionNotAllowed):
            kojihub.add_group_member(group, user)
        self.context.session.assertPerm.assert_called_with('admin')
        self.assertEqual(len(self.inserts), 0)

        # non-existent user
        def get_user1(username):
            if username == user:
                return None
            else:
                return {'id': gid, 'name': username, 'usertype': koji.USERTYPES['GROUP']}
        self.context.session.assertPerm.side_effect = None
        self.get_user.side_effect = get_user1
        with self.assertRaises(koji.GenericError):
            kojihub.add_group_member(group, user)
        self.assertEqual(len(self.inserts), 0)
github koji-project / koji / tests / test_lib / test_client_session.py View on Github external
def test_fastUpload_nologin(self):
        # without login (ActionNotAllowed)
        self.ksession.logged_in = False
        with self.assertRaises(koji.ActionNotAllowed):
            self.ksession.fastUpload('nonexistent_file', 'target')
github koji-project / koji / plugins / hub / save_failed_tree.py View on Github external
config = ConfigParser.SafeConfigParser()
        config.read(CONFIG_FILE)
        allowed_methods = config.get('permissions', 'allowed_methods').split()
        if len(allowed_methods) == 1 and allowed_methods[0] == '*':
            allowed_methods = '*'

    brinfo = kojihub.get_buildroot(buildrootID, strict=True)
    taskID = brinfo['task_id']
    task_info = kojihub.Task(taskID).getInfo()
    if task_info['state'] != koji.TASK_STATES['FAILED']:
        raise koji.PreBuildError("Task %s has not failed. Only failed tasks can upload their buildroots." % taskID)
    elif allowed_methods != '*' and task_info['method'] not in allowed_methods:
        raise koji.PreBuildError("Only %s tasks can upload their buildroots (Task %s is %s)." % \
               (', '.join(allowed_methods), task_info['id'], task_info['method']))
    elif task_info["owner"] != context.session.user_id and not context.session.hasPerm('admin'):
        raise koji.ActionNotAllowed("Only owner of failed task or 'admin' can run this task.")
    elif not kojihub.get_host(task_info['host_id'])['enabled']:
        raise koji.PreBuildError("Host is disabled.")

    args = koji.encode_args(buildrootID, full, **opts)
    taskopts = {
        'assign': brinfo['host_id'],
    }
    return kojihub.make_task('saveFailedTree', args, **taskopts)
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / builder_containerbuild.py View on Github external
signal.signal(signal.SIGINT, sigint_handler)

        self.logger.debug("Waiting for osbs build_id: %s to be scheduled.",
                          build_id)
        # we need to wait for kubelet to schedule the build, otherwise it's 500
        self.osbs().wait_for_build_to_get_scheduled(build_id)
        self.logger.debug("Build was scheduled")

        osbs_logs_dir = self.resultdir()
        koji.ensuredir(osbs_logs_dir)
        pid = os.fork()
        if pid:
            try:
                self._incremental_upload_logs(pid)
            except koji.ActionNotAllowed:
                pass
        else:
            self._osbs = None

            try:
                self._write_incremental_logs(build_id, osbs_logs_dir)
            except Exception as error:
                self.logger.info("Error while saving incremental logs: %s", error)
                os._exit(1)
            os._exit(0)

        response = self.osbs().wait_for_build_to_finish(build_id)
        if response.is_succeeded():
            self.upload_build_annotations(response)

        self.logger.debug("OSBS build finished with status: %s. Build "
github containerbuildsystem / koji-containerbuild / koji_containerbuild / plugins / hub_containerbuild.py View on Github external
def _get_task_opts_and_opts(opts, priority, channel):
    if opts is None:
        opts = {}

    taskOpts = {}
    if priority:
        if priority < 0:
            if not context.session.hasPerm('admin'):
                raise koji.ActionNotAllowed('only admins may create'
                                            ' high-priority tasks')
        taskOpts['priority'] = koji.PRIO_DEFAULT + priority
    if channel:
        taskOpts['channel'] = channel

    return opts, taskOpts
github henrysher / fedora-infra-ansible / roles / koji_hub / files / auth.py View on Github external
def assertUser(self, user_id):
        if not self.isUser(user_id) and not self.hasPerm('admin'):
            raise koji.ActionNotAllowed("not owner")
github henrysher / fedora-infra-ansible / roles / koji_hub / files / auth.py View on Github external
def assertLogin(self):
        if not self.logged_in:
            raise koji.ActionNotAllowed("you must be logged in for this operation")
github koji-project / koji / koji / auth.py View on Github external
def assertUser(self, user_id):
        if not self.isUser(user_id) and not self.hasPerm('admin'):
            raise koji.ActionNotAllowed("not owner")
github koji-project / koji / www / lib / kojiweb / util.py View on Github external
of the main koji library, at least for now...

    Returns a tuple: (str, level)
    str = explanation in plain text
    level = an integer indicating how much traceback data should
            be shown:
                0 - no traceback data
                1 - just the exception
                2 - full traceback
    """
    str = "An exception has occurred"
    level = 2
    if isinstance(error, koji.ServerOffline):
        str = "The server is offline. Please try again later."
        level = 0
    elif isinstance(error, koji.ActionNotAllowed):
        str = """\
The web interface has tried to do something that your account is not \
allowed to do. This is most likely a bug in the web interface."""
    elif isinstance(error, koji.FunctionDeprecated):
        str = """\
The web interface has tried to access a deprecated function. This is \
most likely a bug in the web interface."""
    elif isinstance(error, koji.RetryError):
        str = """\
The web interface is having difficulty communicating with the main \
server and was unable to retry an operation. Most likely this indicates \
a network issue, but it could also be a configuration issue."""
        level = 1
    elif isinstance(error, koji.GenericError):
        if getattr(error, 'fromFault', False):
            str = """\