Skip to content

Commit 74c2bcc

Browse files
committed
Migrate helm handler to OIDCRegistry
Replace manual OIDC credential map and mutex with the shared OIDCRegistry type. Helm already used the raw registry value as the key, so this is a pure structural refactor with no behavior change.
1 parent b63c337 commit 74c2bcc

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

internal/handlers/helm_registry.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package handlers
22

33
import (
44
"net/http"
5-
"sync"
65

76
"github.com/elazarl/goproxy"
87

@@ -14,9 +13,8 @@ import (
1413

1514
// HelmRegistryHandler handles requests to helm registries, adding auth.
1615
type HelmRegistryHandler struct {
17-
credentials []helmRegistryCredentials
18-
oidcCredentials map[string]*oidc.OIDCCredential
19-
mutex sync.RWMutex
16+
credentials []helmRegistryCredentials
17+
oidcRegistry *oidc.OIDCRegistry
2018
}
2119

2220
type helmRegistryCredentials struct {
@@ -28,8 +26,8 @@ type helmRegistryCredentials struct {
2826
// NewHelmRegistryHandler returns a new HelmRegistryHandler.
2927
func NewHelmRegistryHandler(creds config.Credentials) *HelmRegistryHandler {
3028
handler := HelmRegistryHandler{
31-
credentials: []helmRegistryCredentials{},
32-
oidcCredentials: make(map[string]*oidc.OIDCCredential),
29+
credentials: []helmRegistryCredentials{},
30+
oidcRegistry: oidc.NewOIDCRegistry(),
3331
}
3432

3533
for _, cred := range creds {
@@ -42,12 +40,7 @@ func NewHelmRegistryHandler(creds config.Credentials) *HelmRegistryHandler {
4240
registry = cred.Host()
4341
}
4442

45-
oidcCredential, _ := oidc.CreateOIDCCredential(cred)
46-
if oidcCredential != nil {
47-
if registry != "" {
48-
handler.oidcCredentials[registry] = oidcCredential
49-
logging.RequestLogf(nil, "registered %s OIDC credentials for helm registry: %s", oidcCredential.Provider(), registry)
50-
}
43+
if _, _, ok := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); ok {
5144
continue
5245
}
5346

@@ -69,7 +62,7 @@ func (h *HelmRegistryHandler) HandleRequest(req *http.Request, ctx *goproxy.Prox
6962
}
7063

7164
// Try OIDC credentials first
72-
if oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) {
65+
if h.oidcRegistry.TryAuth(req, ctx) {
7366
return req, nil
7467
}
7568

0 commit comments

Comments
 (0)