summary refs log tree commit diff
path: root/synapse/rest/client/_base.py
diff options
context:
space:
mode:
authorreivilibre <oliverw@matrix.org>2023-03-23 12:11:14 +0000
committerGitHub <noreply@github.com>2023-03-23 12:11:14 +0000
commit98fd558382226b347d78e5f6e6782c6e74c25e69 (patch)
treeec4c7ef0999d40dd47e0c29ac645901b86efd7c5 /synapse/rest/client/_base.py
parentUse immutabledict instead of frozendict (#15113) (diff)
downloadsynapse-98fd558382226b347d78e5f6e6782c6e74c25e69.tar.xz
Add a primitive helper script for listing worker endpoints. (#15243)
Co-authored-by: Patrick Cloke <patrickc@matrix.org>
Diffstat (limited to 'synapse/rest/client/_base.py')
-rw-r--r--synapse/rest/client/_base.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/synapse/rest/client/_base.py b/synapse/rest/client/_base.py
index b4cb90cb76..5c1c19e1f3 100644
--- a/synapse/rest/client/_base.py
+++ b/synapse/rest/client/_base.py
@@ -43,19 +43,22 @@ def client_patterns(
     Returns:
         An iterable of patterns.
     """
-    patterns = []
+    versions = []
 
-    if unstable:
-        unstable_prefix = CLIENT_API_PREFIX + "/unstable"
-        patterns.append(re.compile("^" + unstable_prefix + path_regex))
     if v1:
-        v1_prefix = CLIENT_API_PREFIX + "/api/v1"
-        patterns.append(re.compile("^" + v1_prefix + path_regex))
-    for release in releases:
-        new_prefix = CLIENT_API_PREFIX + f"/{release}"
-        patterns.append(re.compile("^" + new_prefix + path_regex))
+        versions.append("api/v1")
+    versions.extend(releases)
+    if unstable:
+        versions.append("unstable")
+
+    if len(versions) == 1:
+        versions_str = versions[0]
+    elif len(versions) > 1:
+        versions_str = "(" + "|".join(versions) + ")"
+    else:
+        raise RuntimeError("Must have at least one version for a URL")
 
-    return patterns
+    return [re.compile("^" + CLIENT_API_PREFIX + "/" + versions_str + path_regex)]
 
 
 def set_timeline_upper_limit(filter_json: JsonDict, filter_timeline_limit: int) -> None: