mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-19 02:21:32 +08:00
Unification of Galaxy configuration parsing for scripts/*
This commit is contained in:
@@ -2,32 +2,36 @@
|
||||
"""
|
||||
Script to encode/decode the IDs that galaxy exposes to users and admins.
|
||||
"""
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'lib')))
|
||||
|
||||
from galaxy.model import mapping
|
||||
from galaxy.model.orm.scripts import get_config
|
||||
from galaxy.util.properties import load_app_properties
|
||||
from galaxy.util.script import app_properties_from_args, populate_config_args
|
||||
from galaxy.web.security import SecurityHelper
|
||||
|
||||
logging.basicConfig()
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Get config file and load up SA session
|
||||
config = get_config(sys.argv)
|
||||
model = mapping.init('/tmp/', config['db_url'])
|
||||
sa_session = model.context.current
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('action', metavar='ACTION', type=str,
|
||||
default=None,
|
||||
help='decode|encode')
|
||||
parser.add_argument('value', metavar='VALUE', type=str,
|
||||
default=None,
|
||||
help='value to encode or decode')
|
||||
populate_config_args(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
# With the config file we can load the full app properties
|
||||
app_properties = load_app_properties(ini_file=config['config_file'])
|
||||
app_properties = app_properties_from_args(args)
|
||||
helper = SecurityHelper(id_secret=app_properties.get('id_secret'))
|
||||
|
||||
# We need the ID secret for configuring the security helper to decrypt
|
||||
# galaxysession cookies.
|
||||
if "id_secret" not in app_properties:
|
||||
log.warning('No ID_SECRET specified. Please set the "id_secret" in your galaxy.ini.')
|
||||
log.warning('No ID_SECRET specified. Please set the "id_secret" in your galaxy.yml.')
|
||||
|
||||
id_secret = app_properties.get('id_secret', 'dangerous_default')
|
||||
|
||||
@@ -35,17 +39,10 @@ security_helper = SecurityHelper(id_secret=id_secret)
|
||||
# And get access to the models
|
||||
# Login manager to manage current_user functionality
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
sys.stdout.write("python %s (encode|decode) value\n" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
action = sys.argv[1]
|
||||
value = sys.argv[2]
|
||||
|
||||
if action == 'decode':
|
||||
sys.stdout.write(security_helper.decode_guid(value.lstrip('F')))
|
||||
elif action == 'encode':
|
||||
sys.stdout.write(security_helper.encode_guid(value))
|
||||
if args.action == 'decode':
|
||||
sys.stdout.write(security_helper.decode_guid(args.value.lstrip('F')))
|
||||
elif args.action == 'encode':
|
||||
sys.stdout.write(security_helper.encode_guid(args.value))
|
||||
else:
|
||||
sys.stdout.write("Unknown argument")
|
||||
sys.stdout.write('\n')
|
||||
|
||||
Reference in New Issue
Block a user