Skip to content

Commit 83c2c9c

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

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

internal/handlers/rubygems_server.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package handlers
33
import (
44
"net/http"
55
"strings"
6-
"sync"
76

87
"github.com/elazarl/goproxy"
98

@@ -15,9 +14,8 @@ import (
1514

1615
// RubyGemsServerHandler handles requests to rubygems servers, adding auth.
1716
type RubyGemsServerHandler struct {
18-
credentials []rubyGemsServerCredentials
19-
oidcCredentials map[string]*oidc.OIDCCredential
20-
mutex sync.RWMutex
17+
credentials []rubyGemsServerCredentials
18+
oidcRegistry *oidc.OIDCRegistry
2119
}
2220

2321
type rubyGemsServerCredentials struct {
@@ -29,8 +27,8 @@ type rubyGemsServerCredentials struct {
2927
// NewRubyGemsServerHandler returns a new RubyGemsServerHandler.
3028
func NewRubyGemsServerHandler(creds config.Credentials) *RubyGemsServerHandler {
3129
handler := RubyGemsServerHandler{
32-
credentials: []rubyGemsServerCredentials{},
33-
oidcCredentials: make(map[string]*oidc.OIDCCredential),
30+
credentials: []rubyGemsServerCredentials{},
31+
oidcRegistry: oidc.NewOIDCRegistry(),
3432
}
3533

3634
for _, cred := range creds {
@@ -41,16 +39,11 @@ func NewRubyGemsServerHandler(creds config.Credentials) *RubyGemsServerHandler {
4139
host := cred.Host()
4240
url := cred.GetString("url")
4341

44-
oidcCredential, _ := oidc.CreateOIDCCredential(cred)
45-
if oidcCredential != nil {
46-
hostURL := url
47-
if hostURL == "" {
48-
hostURL = host
49-
}
50-
if hostURL != "" {
51-
handler.oidcCredentials[hostURL] = oidcCredential
52-
logging.RequestLogf(nil, "registered %s OIDC credentials for rubygems server: %s", oidcCredential.Provider(), hostURL)
53-
}
42+
if oidcCred, _, ok := handler.oidcRegistry.Register(cred, []string{"url"}, "rubygems server"); ok {
43+
continue
44+
} else if oidcCred != nil {
45+
// OIDC-configured but registration failed (e.g. no URL/host) — skip
46+
// static credential processing to match original behavior.
5447
continue
5548
}
5649

@@ -72,7 +65,7 @@ func (h *RubyGemsServerHandler) HandleRequest(req *http.Request, ctx *goproxy.Pr
7265
}
7366

7467
// Try OIDC credentials first
75-
if oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) {
68+
if h.oidcRegistry.TryAuth(req, ctx) {
7669
return req, nil
7770
}
7871

0 commit comments

Comments
 (0)