Loading lib/galaxy/model/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ from galaxy.security.validate_user_input import validate_password_str from galaxy.util import ( directory_hash_id, enum_values, hex_to_lowercase_alphanum, listify, ready_name_for_url, unicodify, Loading lib/galaxy/model/migrations/alembic/versions_gxy/8a19186a6ee7_add_columns_to_interactivetool_entry_point.py 0 → 100644 +41 −0 Original line number Diff line number Diff line """add label, requires_path_in_url and requires_path_in_header_named columns to interactivetool_entry_point Revision ID: 8a19186a6ee7 Revises: ddbdbc40bdc1 Create Date: 2023-11-15 12:53:32.888292 """ from sqlalchemy import ( Boolean, Column, Text, ) from galaxy.model.migrations.util import ( add_column, drop_column, ) # revision identifiers, used by Alembic. revision = "8a19186a6ee7" down_revision = "ddbdbc40bdc1" branch_labels = None depends_on = None # database object names used in this revision table_name = "interactivetool_entry_point" label_column_name = "label" requires_path_in_url_colname = "requires_path_in_url" requires_path_in_header_named_colname = "requires_path_in_header_named" def upgrade(): add_column(table_name, Column(label_column_name, Text())) add_column(table_name, Column(requires_path_in_url_colname, Boolean(), default=False)) add_column(table_name, Column(requires_path_in_header_named_colname, Text())) def downgrade(): drop_column(table_name, requires_path_in_header_named_colname) drop_column(table_name, requires_path_in_url_colname) drop_column(table_name, label_column_name) lib/galaxy/security/idencoding.py +17 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ from Crypto.Random import get_random_bytes import galaxy.exceptions from galaxy.util import ( hex_to_lowercase_alphanum, lowercase_alphanum_to_hex, smart_str, unicodify, ) Loading Loading @@ -146,3 +148,18 @@ def _last_bits(secret): if len(last_bits) > MAXIMUM_ID_SECRET_LENGTH: last_bits = last_bits[-MAXIMUM_ID_SECRET_LENGTH:] return last_bits class IdAsLowercaseAlphanumEncodingHelper: """ Helper class to encode IDs as lowercase alphanumeric strings, and vice versa """ def __init__(self, security: IdEncodingHelper): self.security = security def encode_id(self, id: int) -> str: return hex_to_lowercase_alphanum(self.security.encode_id(id)) def decode_id(self, id: str) -> int: return self.security.decode_id(lowercase_alphanum_to_hex(id).rjust(16, "0")) lib/galaxy/util/__init__.py +22 −2 Original line number Diff line number Diff line Loading @@ -538,7 +538,7 @@ def pretty_print_time_interval(time=False, precise=False, utc=False): now = datetime.utcnow() else: now = datetime.now() if type(time) is int: if isinstance(time, (int, float)): diff = now - datetime.fromtimestamp(time) elif isinstance(time, datetime): diff = now - time Loading Loading @@ -979,7 +979,7 @@ def parse_resource_parameters(resource_param_file): resource_definitions_root = resource_definitions.getroot() for parameter_elem in resource_definitions_root.findall("param"): name = parameter_elem.get("name") resource_parameters[name] = parameter_elem resource_parameters[name] = etree.tostring(parameter_elem) return resource_parameters Loading Loading @@ -1882,3 +1882,23 @@ def enum_values(enum_class): Values are in member definition order. """ return [value.value for value in enum_class.__members__.values()] def hex_to_lowercase_alphanum(hex_string: str) -> str: """ Convert a hexadecimal string encoding into a lowercase 36-base alphanumeric string using the characters a-z and 0-9 """ import numpy as np return np.base_repr(int(hex_string, 16), 36).lower() def lowercase_alphanum_to_hex(lowercase_alphanum: str) -> str: """ Convert a lowercase 36-base alphanumeric string encoding using the characters a-z and 0-9 to a hexadecimal string """ import numpy as np return np.base_repr(int(lowercase_alphanum, 36), 16).lower() Loading
lib/galaxy/model/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ from galaxy.security.validate_user_input import validate_password_str from galaxy.util import ( directory_hash_id, enum_values, hex_to_lowercase_alphanum, listify, ready_name_for_url, unicodify, Loading
lib/galaxy/model/migrations/alembic/versions_gxy/8a19186a6ee7_add_columns_to_interactivetool_entry_point.py 0 → 100644 +41 −0 Original line number Diff line number Diff line """add label, requires_path_in_url and requires_path_in_header_named columns to interactivetool_entry_point Revision ID: 8a19186a6ee7 Revises: ddbdbc40bdc1 Create Date: 2023-11-15 12:53:32.888292 """ from sqlalchemy import ( Boolean, Column, Text, ) from galaxy.model.migrations.util import ( add_column, drop_column, ) # revision identifiers, used by Alembic. revision = "8a19186a6ee7" down_revision = "ddbdbc40bdc1" branch_labels = None depends_on = None # database object names used in this revision table_name = "interactivetool_entry_point" label_column_name = "label" requires_path_in_url_colname = "requires_path_in_url" requires_path_in_header_named_colname = "requires_path_in_header_named" def upgrade(): add_column(table_name, Column(label_column_name, Text())) add_column(table_name, Column(requires_path_in_url_colname, Boolean(), default=False)) add_column(table_name, Column(requires_path_in_header_named_colname, Text())) def downgrade(): drop_column(table_name, requires_path_in_header_named_colname) drop_column(table_name, requires_path_in_url_colname) drop_column(table_name, label_column_name)
lib/galaxy/security/idencoding.py +17 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ from Crypto.Random import get_random_bytes import galaxy.exceptions from galaxy.util import ( hex_to_lowercase_alphanum, lowercase_alphanum_to_hex, smart_str, unicodify, ) Loading Loading @@ -146,3 +148,18 @@ def _last_bits(secret): if len(last_bits) > MAXIMUM_ID_SECRET_LENGTH: last_bits = last_bits[-MAXIMUM_ID_SECRET_LENGTH:] return last_bits class IdAsLowercaseAlphanumEncodingHelper: """ Helper class to encode IDs as lowercase alphanumeric strings, and vice versa """ def __init__(self, security: IdEncodingHelper): self.security = security def encode_id(self, id: int) -> str: return hex_to_lowercase_alphanum(self.security.encode_id(id)) def decode_id(self, id: str) -> int: return self.security.decode_id(lowercase_alphanum_to_hex(id).rjust(16, "0"))
lib/galaxy/util/__init__.py +22 −2 Original line number Diff line number Diff line Loading @@ -538,7 +538,7 @@ def pretty_print_time_interval(time=False, precise=False, utc=False): now = datetime.utcnow() else: now = datetime.now() if type(time) is int: if isinstance(time, (int, float)): diff = now - datetime.fromtimestamp(time) elif isinstance(time, datetime): diff = now - time Loading Loading @@ -979,7 +979,7 @@ def parse_resource_parameters(resource_param_file): resource_definitions_root = resource_definitions.getroot() for parameter_elem in resource_definitions_root.findall("param"): name = parameter_elem.get("name") resource_parameters[name] = parameter_elem resource_parameters[name] = etree.tostring(parameter_elem) return resource_parameters Loading Loading @@ -1882,3 +1882,23 @@ def enum_values(enum_class): Values are in member definition order. """ return [value.value for value in enum_class.__members__.values()] def hex_to_lowercase_alphanum(hex_string: str) -> str: """ Convert a hexadecimal string encoding into a lowercase 36-base alphanumeric string using the characters a-z and 0-9 """ import numpy as np return np.base_repr(int(hex_string, 16), 36).lower() def lowercase_alphanum_to_hex(lowercase_alphanum: str) -> str: """ Convert a lowercase 36-base alphanumeric string encoding using the characters a-z and 0-9 to a hexadecimal string """ import numpy as np return np.base_repr(int(lowercase_alphanum, 36), 16).lower()