@@ -2,7 +2,6 @@ package handlers
22
33import (
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.
1615type HelmRegistryHandler struct {
17- credentials []helmRegistryCredentials
18- oidcCredentials map [string ]* oidc.OIDCCredential
19- mutex sync.RWMutex
16+ credentials []helmRegistryCredentials
17+ oidcRegistry * oidc.OIDCRegistry
2018}
2119
2220type helmRegistryCredentials struct {
@@ -28,8 +26,8 @@ type helmRegistryCredentials struct {
2826// NewHelmRegistryHandler returns a new HelmRegistryHandler.
2927func 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