Skip to content

Commit dbd24e2

Browse files
author
Jelle Dijkstra
committed
URL aliases in download middlewares
1 parent 577a911 commit dbd24e2

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

internal/controller/middleware.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ func (r *AtomReconciler) mutateDownloadLinkMiddleware(atom *pdoknlv3.Atom, prefi
9393
return err
9494
}
9595

96-
baseURL := atom.Spec.Service.BaseURL
96+
ingressRouteURLs := atom.Spec.IngressRouteURLs
97+
if len(ingressRouteURLs) == 0 {
98+
ingressRouteURLs = smoothoperatormodel.IngressRouteURLs{{URL: atom.Spec.Service.BaseURL}}
99+
}
97100

98101
middleware.Spec = traefikiov1alpha1.MiddlewareSpec{
99102
ReplacePathRegex: &dynamic.ReplacePathRegex{
100-
Regex: getDownloadLinkRegex(baseURL, files),
103+
Regex: getDownloadLinkRegex(ingressRouteURLs, files),
101104
Replacement: "/" + prefix + "/$1",
102105
},
103106
}
@@ -108,8 +111,18 @@ func (r *AtomReconciler) mutateDownloadLinkMiddleware(atom *pdoknlv3.Atom, prefi
108111
return ctrl.SetControllerReference(atom, middleware, r.Scheme)
109112
}
110113

111-
func getDownloadLinkRegex(url smoothoperatormodel.URL, files []string) string {
112-
return "^" + url.JoinPath("downloads", "("+strings.Join(files, "|")+")").Path
114+
func getDownloadLinkRegex(ingressRouteURLs smoothoperatormodel.IngressRouteURLs, files []string) string {
115+
if len(ingressRouteURLs) == 1 {
116+
return "^" + ingressRouteURLs[0].URL.JoinPath("downloads", "("+strings.Join(files, "|")+")").Path
117+
}
118+
119+
paths := []string{}
120+
for _, ingressRouteURL := range ingressRouteURLs {
121+
paths = append(paths, ingressRouteURL.URL.Path)
122+
}
123+
124+
return "^(" + strings.Join(paths, "|") + ")/downloads/" + "(" + strings.Join(files, "|") + ")"
125+
113126
}
114127

115128
func getDownloadLinkGroups(links []pdoknlv3.DownloadLink) map[string]struct {

internal/controller/test_data/maximum-atom/expected-output/middleware-downloads-0.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ metadata:
1515
controller: true
1616
spec:
1717
replacePathRegex:
18-
regex: ^/path/downloads/(index.json|file-1.ext)
18+
regex: ^(/path|/path/other)/downloads/(index.json|file-1.ext)
1919
replacement: /container/prefix-1/$1

internal/controller/test_data/maximum-atom/expected-output/middleware-downloads-1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ metadata:
1515
controller: true
1616
spec:
1717
replacePathRegex:
18-
regex: ^/path/downloads/(file-2.ext)
18+
regex: ^(/path|/path/other)/downloads/(file-2.ext)
1919
replacement: /container/prefix-2/$1

internal/controller/test_data/maximum-atom/expected-output/middleware-downloads-2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ metadata:
1515
controller: true
1616
spec:
1717
replacePathRegex:
18-
regex: ^/path/downloads/(file-3.ext|file-4.ext)
18+
regex: ^(/path|/path/other)/downloads/(file-3.ext|file-4.ext)
1919
replacement: /container/prefix-3/$1

0 commit comments

Comments
 (0)