Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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}
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
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")
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)
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))
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
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
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)