@@ -2,7 +2,6 @@ package handlers
22
33import (
44 "net/http"
5- "sync"
65
76 "github.com/elazarl/goproxy"
87 "github.com/sirupsen/logrus"
@@ -35,9 +34,8 @@ import (
3534// credentials locally in this example:
3635// https://jfrog.com/help/r/artifactory-how-to-integrate-artifactory-with-cargo-using-sparse-indexing/client-configuration
3736type CargoRegistryHandler struct {
38- credentials []cargoRepositoryCredentials
39- oidcCredentials map [string ]* oidc.OIDCCredential
40- mutex sync.RWMutex
37+ credentials []cargoRepositoryCredentials
38+ oidcRegistry * oidc.OIDCRegistry
4139}
4240
4341type cargoRepositoryCredentials struct {
@@ -47,8 +45,8 @@ type cargoRepositoryCredentials struct {
4745
4846func NewCargoRegistryHandler (credentials config.Credentials ) * CargoRegistryHandler {
4947 handler := CargoRegistryHandler {
50- credentials : []cargoRepositoryCredentials {},
51- oidcCredentials : make ( map [ string ] * oidc.OIDCCredential ),
48+ credentials : []cargoRepositoryCredentials {},
49+ oidcRegistry : oidc .NewOIDCRegistry ( ),
5250 }
5351
5452 for _ , credential := range credentials {
@@ -58,12 +56,7 @@ func NewCargoRegistryHandler(credentials config.Credentials) *CargoRegistryHandl
5856
5957 url := credential .GetString ("url" )
6058
61- oidcCredential , _ := oidc .CreateOIDCCredential (credential )
62- if oidcCredential != nil {
63- if url != "" {
64- handler .oidcCredentials [url ] = oidcCredential
65- logging .RequestLogf (nil , "registered %s OIDC credentials for cargo registry: %s" , oidcCredential .Provider (), url )
66- }
59+ if _ , _ , ok := handler .oidcRegistry .Register (credential , []string {"url" }, "cargo registry" ); ok {
6760 continue
6861 }
6962
@@ -90,7 +83,7 @@ func (h *CargoRegistryHandler) HandleRequest(req *http.Request, ctx *goproxy.Pro
9083 }
9184
9285 // Try OIDC credentials first
93- if oidc . TryAuthOIDCRequestWithPrefix ( & h . mutex , h . oidcCredentials , req , ctx ) {
86+ if h . oidcRegistry . TryAuth ( req , ctx ) {
9487 return req , nil
9588 }
9689
0 commit comments