diff --git a/group_vars/all.yaml b/group_vars/all.yaml index 7f20b9c..5f036ef 100644 --- a/group_vars/all.yaml +++ b/group_vars/all.yaml @@ -85,3 +85,10 @@ gxy_io_rewrites: - /smorg-slack - /smorgasbordslack - /smorgasbord-slack + + # GTN Short URLs + - src: "/t/(.*)" + dest: "https://training.galaxyproject.org/training-material/short/\\1" + tests: + - /t/ansible-galaxy + - /t/galaxy-intro-101 diff --git a/templates/lambda_function.py.j2 b/templates/lambda_function.py.j2 index 4beda32..f9eb532 100644 --- a/templates/lambda_function.py.j2 +++ b/templates/lambda_function.py.j2 @@ -3,7 +3,7 @@ import re DEFAULT_LOCATION = "https://galaxyproject.org/" LOCATION_MAP = { {% for item in gxy_io_rewrites %} - "{{ item.src.rstrip('/') }}/?$": "{{ item.dest }}", + r"{{ item.src.rstrip('/') }}/?$": r"{{ item.dest }}", {% endfor %} } @@ -18,8 +18,11 @@ def lambda_handler(event, context): if uri is not None: for src, dest in LOCATION_MAP.items(): - if re.match(src, uri): + m = re.match(src, uri) + if m: location = dest + if len(m.groups()): + location = re.sub(src, dest, uri) break if location is None: