2017-02-15 20:52:07 +00:00
|
|
|
#!/usr/bin/env python
|
2017-02-15 21:31:22 +00:00
|
|
|
"""
|
|
|
|
|
Script to encode/decode the IDs that galaxy exposes to users and admins.
|
|
|
|
|
"""
|
2026-01-19 22:33:34 +00:00
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
import argparse
|
2017-08-15 18:02:44 +01:00
|
|
|
import logging
|
2017-02-15 20:52:07 +00:00
|
|
|
import os
|
|
|
|
|
import sys
|
2017-08-15 18:02:44 +01:00
|
|
|
|
2017-02-15 20:52:07 +00:00
|
|
|
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "lib")))
|
|
|
|
|
|
2019-03-18 11:51:02 -04:00
|
|
|
from galaxy.security.idencoding import IdEncodingHelper
|
2018-08-20 18:34:09 +01:00
|
|
|
from galaxy.util import unicodify
|
2018-03-23 09:41:05 -04:00
|
|
|
from galaxy.util.script import (
|
|
|
|
|
app_properties_from_args,
|
|
|
|
|
populate_config_args,
|
2022-02-02 15:26:21 -05:00
|
|
|
)
|
2017-02-15 20:52:07 +00:00
|
|
|
|
2017-08-15 18:02:44 +01:00
|
|
|
logging.basicConfig()
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
parser = argparse.ArgumentParser()
|
2023-12-14 13:07:37 -05:00
|
|
|
parser.add_argument("action", metavar="ACTION", type=str, default=None, choices=("decode", "encode"))
|
|
|
|
|
parser.add_argument("value", metavar="VALUE", nargs="+", type=str, default=None, help="value to encode or decode")
|
2018-03-23 09:41:05 -04:00
|
|
|
populate_config_args(parser)
|
|
|
|
|
args = parser.parse_args()
|
2017-02-15 20:52:07 +00:00
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
app_properties = app_properties_from_args(args)
|
2017-02-15 20:52:07 +00:00
|
|
|
|
|
|
|
|
# We need the ID secret for configuring the security helper to decrypt
|
|
|
|
|
# galaxysession cookies.
|
|
|
|
|
if "id_secret" not in app_properties:
|
2018-03-23 09:41:05 -04:00
|
|
|
log.warning('No ID_SECRET specified. Please set the "id_secret" in your galaxy.yml.')
|
2017-02-15 20:52:07 +00:00
|
|
|
|
|
|
|
|
id_secret = app_properties.get("id_secret", "dangerous_default")
|
|
|
|
|
|
2019-03-18 11:51:02 -04:00
|
|
|
security_helper = IdEncodingHelper(id_secret=id_secret)
|
2017-02-15 20:52:07 +00:00
|
|
|
# And get access to the models
|
|
|
|
|
# Login manager to manage current_user functionality
|
|
|
|
|
|
2018-03-23 09:41:05 -04:00
|
|
|
if args.action == "decode":
|
2023-12-14 13:07:37 -05:00
|
|
|
for value in args.value:
|
|
|
|
|
sys.stdout.write(security_helper.decode_guid(value.lstrip("F")))
|
|
|
|
|
sys.stdout.write("\n")
|
2018-03-23 09:41:05 -04:00
|
|
|
elif args.action == "encode":
|
2023-12-14 13:07:37 -05:00
|
|
|
for value in args.value:
|
|
|
|
|
sys.stdout.write(unicodify(security_helper.encode_guid(value)))
|
|
|
|
|
sys.stdout.write("\n")
|