mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
528497f7c4
I want to be able to use this class in galaxy.model and it doesn't have any dependnecies on "web" stuff so I'd like to move it out of galaxy.model and into galaxy.security. galaxy.model shouldn't have dependencies on galaxy.web (and doesn't after the recent 976f5ad367), so this pre-emptively ensures it doesn't require these dependencies for https://github.com/galaxyproject/galaxy/pull/7367.
This has the benefit of also eliminating any galaxy.web dependencies from the generic test base file (test/base/testcase.py) which has long been a goal of mine as well.
There are places we legimately use ID encoding and decoding for security (i.e. job files API) but for the most part it doesn't provide security for API endpoints and this causes confusion repeatedly, so I've started the process of renaming the contained class SecurityHelper to something I feel makes it clearer this is just about encoding and decoding IDs.
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
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.security.idencoding import IdEncodingHelper
|
|
from galaxy.util import unicodify
|
|
from galaxy.util.script import app_properties_from_args, populate_config_args
|
|
|
|
logging.basicConfig()
|
|
log = logging.getLogger(__name__)
|
|
|
|
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()
|
|
|
|
app_properties = app_properties_from_args(args)
|
|
|
|
# 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.yml.')
|
|
|
|
id_secret = app_properties.get('id_secret', 'dangerous_default')
|
|
|
|
security_helper = IdEncodingHelper(id_secret=id_secret)
|
|
# And get access to the models
|
|
# Login manager to manage current_user functionality
|
|
|
|
if args.action == 'decode':
|
|
sys.stdout.write(security_helper.decode_guid(args.value.lstrip('F')))
|
|
elif args.action == 'encode':
|
|
sys.stdout.write(unicodify(security_helper.encode_guid(args.value)))
|
|
else:
|
|
sys.stdout.write("Unknown argument")
|
|
sys.stdout.write('\n')
|