Skip to content

Commit

Permalink
Allow captures and replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Feb 1, 2023
1 parent 93f37a0 commit 659006a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions group_vars/all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions templates/lambda_function.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
}

Expand All @@ -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:
Expand Down

0 comments on commit 659006a

Please sign in to comment.