Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.6 KiB
Python
Raw Permalink Normal View History

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
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")))
from galaxy.security.idencoding import IdEncodingHelper
from galaxy.util import unicodify
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__)
parser = argparse.ArgumentParser()
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")
populate_config_args(parser)
args = parser.parse_args()
2017-02-15 20:52:07 +00: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:
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")
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
if args.action == "decode":
for value in args.value:
sys.stdout.write(security_helper.decode_guid(value.lstrip("F")))
sys.stdout.write("\n")
elif args.action == "encode":
for value in args.value:
sys.stdout.write(unicodify(security_helper.encode_guid(value)))
sys.stdout.write("\n")