How to use the koji.context.context 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 / koji / auth.py View on Github external
key = "%s-%s" %(user_id,
                ''.join([random.choice(alnum) for x in range(1, 20)]))
        # use sha? sha.new(phrase).hexdigest()

        # get a session id
        q = """SELECT nextval('sessions_id_seq')"""
        c.execute(q, {})
        (session_id,) = c.fetchone()

        #add session id to database
        q = """
        INSERT INTO sessions (id, user_id, key, hostip, authtype, master)
        VALUES (%(session_id)i, %(user_id)i, %(key)s, %(hostip)s, %(authtype)i, %(master)s)
        """
        c.execute(q, locals())
        context.cnx.commit()

        #return session info
        return {'session-id' : session_id, 'session-key' : key}
github koji-project / koji / plugins / hub / rpm2maven.py View on Github external
def maven_import(cbtype, *args, **kws):
    global config
    if not context.opts.get('EnableMaven', False):
        return
    if kws.get('type') != 'rpm':
        return
    buildinfo = kws['build']
    rpminfo = kws['rpm']
    filepath = kws['filepath']

    if not config:
        config = six.moves.configparser.SafeConfigParser()
        config.read(CONFIG_FILE)
    name_patterns = config.get('patterns', 'rpm_names').split()
    for pattern in name_patterns:
        if fnmatch.fnmatch(rpminfo['name'], pattern):
            break
    else:
        return
github henrysher / fedora-infra-ansible / roles / koji_hub / templates / fedmsg-koji-plugin.py View on Github external
def send_messages(cbtype, *args, **kws):
    messages = getattr(context, 'fedmsg_plugin_messages', [])

    for message in messages:
        try:
            msg = fedora_messaging.api.Message(
                topic="buildsys.{}".format(message['topic']),
                body=message['msg']
            )
            fedora_messaging.api.publish(msg)
        except fedora_messaging.exceptions.PublishReturned as e:
            log.warning(
                "Fedora Messaging broker rejected message %s: %s", msg.id, e
            )
        except fedora_messaging.exceptions.ConnectionException as e:
            log.warning("Error sending message %s: %s", msg.id, e)
        except Exception:
            log.exception("Un-expected error sending fedora-messaging message")
github koji-project / koji / hub / kojixmlrpc.py View on Github external
def format(self, record):
        record.method = getattr(context, 'method', None)
        if hasattr(context, 'environ'):
            record.remoteaddr = "%s:%s" % (
                context.environ.get('REMOTE_ADDR', '?'),
                context.environ.get('REMOTE_PORT', '?'))
        else:
            record.remoteaddr = "?:?"
        if hasattr(context, 'session'):
            record.user_id = context.session.user_id
            record.session_id = context.session.id
            record.callnum = context.session.callnum
            record.user_name = context.session.user_data.get('name')
        else:
            record.user_id = None
            record.session_id = None
            record.callnum = None
            record.user_name = None
        return logging.Formatter.format(self, record)
github koji-project / koji / plugins / hub / protonmsg.py View on Github external
def queue_msg(address, props, data):
    msgs = getattr(context, 'protonmsg_msgs', None)
    if msgs is None:
        msgs = []
        context.protonmsg_msgs = msgs
    body = json.dumps(data, default=json_serialize)
    msgs.append((address, props, body))
github henrysher / fedora-infra-ansible / roles / koji_hub / templates / fedmsg-koji-plugin.py View on Github external
def scrub(obj):
        if isinstance(obj, list):
            return [scrub(item) for item in obj]
        if isinstance(obj, dict):
            return dict([
                (k, scrub(v))
                for k, v in obj.items()
                if k not in problem_fields
            ])
        return obj

    body = scrub(body)

    # Queue the message for later.
    # It will only get sent after postCommit is called.
    messages = getattr(context, 'fedmsg_plugin_messages', [])
    messages.append(dict(topic=topic, msg=body))
    context.fedmsg_plugin_messages = messages
github koji-project / koji / koji / auth.py View on Github external
def get_remote_ip(self, override=None):
        if not context.opts['CheckClientIP']:
            return '-'
        elif override is not None:
            return override
        else:
            hostip = context.environ['REMOTE_ADDR']
            #XXX - REMOTE_ADDR not promised by wsgi spec
            if hostip == '127.0.0.1':
                hostip = socket.gethostbyname(socket.gethostname())
            return hostip
github koji-project / koji / plugins / hub / rpm2maven.py View on Github external
maven_archives.append({'maven_info': maven_info,
                               'files': [os.path.join(dirpath, f) for f in filenames]})

    if not maven_archives:
        return

    # We don't know which pom is the top-level pom, so we don't know what Maven
    # metadata to associate with the build.  So we make something up.
    maven_build = {'group_id': buildinfo['name'], 'artifact_id': rpminfo['name'],
                   'version': '%(version)s-%(release)s' % buildinfo}
    context.handlers.call('host.createMavenBuild', buildinfo, maven_build)

    for entry in maven_archives:
        maven_info = entry['maven_info']
        for filepath in entry['files']:
            if not context.handlers.call('getArchiveType', filename=filepath):
                # unsupported archive type, skip it
                continue
            context.handlers.call('host.importArchive', filepath, buildinfo, 'maven', maven_info)