@@ -3,7 +3,6 @@ package handlers
33import (
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.
1716type RubyGemsServerHandler struct {
18- credentials []rubyGemsServerCredentials
19- oidcCredentials map [string ]* oidc.OIDCCredential
20- mutex sync.RWMutex
17+ credentials []rubyGemsServerCredentials
18+ oidcRegistry * oidc.OIDCRegistry
2119}
2220
2321type rubyGemsServerCredentials struct {
@@ -29,8 +27,8 @@ type rubyGemsServerCredentials struct {
2927// NewRubyGemsServerHandler returns a new RubyGemsServerHandler.
3028func 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,8 @@ 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+ // OIDC credentials are not used as static credentials.
43+ if oidcCred , _ , _ := handler .oidcRegistry .Register (cred , []string {"url" }, "rubygems server" ); oidcCred != nil {
5444 continue
5545 }
5646
@@ -72,7 +62,7 @@ func (h *RubyGemsServerHandler) HandleRequest(req *http.Request, ctx *goproxy.Pr
7262 }
7363
7464 // Try OIDC credentials first
75- if oidc . TryAuthOIDCRequestWithPrefix ( & h . mutex , h . oidcCredentials , req , ctx ) {
65+ if h . oidcRegistry . TryAuth ( req , ctx ) {
7666 return req , nil
7767 }
7868
0 commit comments