From 2dbf8296c035593d918317a5d82f80ee54afdd54 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 9 Jan 2025 11:32:54 +0100 Subject: [PATCH] fix(ocm): fix wildcards in ocm domains Signed-off-by: jkoberg --- changelog/unreleased/fix-wildcards.md | 5 +++++ pkg/ocm/provider/authorizer/json/json.go | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 changelog/unreleased/fix-wildcards.md diff --git a/changelog/unreleased/fix-wildcards.md b/changelog/unreleased/fix-wildcards.md new file mode 100644 index 0000000000..8371a2f7a5 --- /dev/null +++ b/changelog/unreleased/fix-wildcards.md @@ -0,0 +1,5 @@ +Bugfix: Fix ocm wildcards + +ocm wildcards were not working properly. We now overwrite the wildcard values with the actual domain. + +https://github.com/cs3org/reva/pull/5033 diff --git a/pkg/ocm/provider/authorizer/json/json.go b/pkg/ocm/provider/authorizer/json/json.go index c56b951c0e..025d036985 100644 --- a/pkg/ocm/provider/authorizer/json/json.go +++ b/pkg/ocm/provider/authorizer/json/json.go @@ -114,9 +114,22 @@ func (a *authorizer) GetInfoByDomain(_ context.Context, domain string) (*ocmprov return nil, err } for _, p := range a.providers { + // we can exit early if this an exact match if strings.Contains(p.Domain, normalizedDomain) { return p, nil } + + // check if the domain matches a regex + if ok, err := regexp.MatchString(p.Domain, normalizedDomain); ok && err == nil { + // overwrite wildcards with the actual domain + for i, s := range p.Services { + s.Endpoint.Path = strings.ReplaceAll(s.Endpoint.Path, p.Domain, normalizedDomain) + s.Host = strings.ReplaceAll(s.Host, p.Domain, normalizedDomain) + p.Services[i] = s + } + p.Domain = normalizedDomain + return p, nil + } } return nil, errtypes.NotFound(domain) }