forked from elixir-oslo/proto
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ProTo: Forgot to add the Security module some commits ago
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |