Skip to content

Commit

Permalink
ProTo: Forgot to add the Security module some commits ago
Browse files Browse the repository at this point in the history
  • Loading branch information
morj-uio authored and sveinugu committed Nov 24, 2016
1 parent 7a4350b commit 55a156a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/proto/config/Security.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# NB: imported by Galaxy (managers.hdas). Should not import other ProTo modules.
# This module will only be loaded once, during startup of Galaxy, and not dynamically by ProTo tools.
# This means changes in the module will not take effect until Galaxy is restarted.

import os
from ConfigParser import SafeConfigParser

GALAXY_BASE_DIR = os.path.abspath(os.path.dirname(__file__) + '/../../../.')


def getUniverseConfigParser():
config = SafeConfigParser({'here': GALAXY_BASE_DIR})
configRelFn = os.environ.get('GALAXY_CONFIG_FILE')
if not configRelFn:
configRelFn = 'config/galaxy.ini'
configFn = GALAXY_BASE_DIR + '/' + configRelFn
if os.path.exists(configFn):
config.read(configFn)
else:
raise Exception('No Galaxy config file found at path: ' + configFn)
return config


config = getUniverseConfigParser()


def getFromConfig(config, key, default, section='app:main'):
try:
return config.get(section, key)
except:
return default


def galaxyGetSecurityHelper(config):
from galaxy.web.security import SecurityHelper

id_secret = getFromConfig(config, 'proto_id_secret',
'USING THE DEFAULT IS ALSO NOT SECURE!',
section='galaxy_proto')
return SecurityHelper(id_secret=id_secret)


try:
GALAXY_SECURITY_HELPER_OBJ = galaxyGetSecurityHelper(config)
except:
GALAXY_SECURITY_HELPER_OBJ = None


def galaxySecureEncodeId(plainId):
return GALAXY_SECURITY_HELPER_OBJ.encode_id(plainId)


def galaxySecureDecodeId(encodedId):
return GALAXY_SECURITY_HELPER_OBJ.decode_id(str(encodedId))

0 comments on commit 55a156a

Please sign in to comment.