Skip to content

Commit 41a4d7c

Browse files
committed
Migrate goproxy handler to OIDCRegistry
Replace manual OIDC credential map and mutex with the shared OIDCRegistry type. Goproxy already used url-with-host-fallback as the key, so this is a pure structural refactor with no behavior change.
1 parent 5328230 commit 41a4d7c

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

internal/handlers/goproxy_server_handler.go

Lines changed: 6 additions & 17 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

@@ -13,9 +12,8 @@ import (
1312
)
1413

1514
type GoProxyServerHandler struct {
16-
credentials []goProxyServerCredentials
17-
oidcCredentials map[string]*oidc.OIDCCredential
18-
mutex sync.RWMutex
15+
credentials []goProxyServerCredentials
16+
oidcRegistry *oidc.OIDCRegistry
1917
}
2018

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

3533
for _, cred := range creds {
@@ -40,16 +38,7 @@ func NewGoProxyServerHandler(creds config.Credentials) *GoProxyServerHandler {
4038
url := cred.GetString("url")
4139
host := cred.GetString("host")
4240

43-
oidcCredential, _ := oidc.CreateOIDCCredential(cred)
44-
if oidcCredential != nil {
45-
urlOrHost := url
46-
if urlOrHost == "" {
47-
urlOrHost = host
48-
}
49-
if urlOrHost != "" {
50-
handler.oidcCredentials[urlOrHost] = oidcCredential
51-
logging.RequestLogf(nil, "registered %s OIDC credentials for goproxy server: %s", oidcCredential.Provider(), urlOrHost)
52-
}
41+
if _, _, ok := handler.oidcRegistry.Register(cred, []string{"url"}, "goproxy server"); ok {
5342
continue
5443
}
5544

@@ -76,7 +65,7 @@ func (h *GoProxyServerHandler) HandleRequest(req *http.Request, ctx *goproxy.Pro
7665
}
7766

7867
// Try OIDC credentials first
79-
if oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) {
68+
if h.oidcRegistry.TryAuth(req, ctx) {
8069
return req, nil
8170
}
8271

0 commit comments

Comments
 (0)