Skip to content

Commit dfef832

Browse files
committed
Migrate cargo handler to OIDCRegistry
Replace manual OIDC credential map and mutex with the shared OIDCRegistry type. Cargo already used full URL keys, so this is a pure structural refactor with no behavior change.
1 parent 5328230 commit dfef832

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

internal/handlers/cargo_registry.go

Lines changed: 10 additions & 13 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
"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
3736
type CargoRegistryHandler struct {
38-
credentials []cargoRepositoryCredentials
39-
oidcCredentials map[string]*oidc.OIDCCredential
40-
mutex sync.RWMutex
37+
credentials []cargoRepositoryCredentials
38+
oidcRegistry *oidc.OIDCRegistry
4139
}
4240

4341
type cargoRepositoryCredentials struct {
@@ -47,8 +45,8 @@ type cargoRepositoryCredentials struct {
4745

4846
func 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,13 +56,12 @@ 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)
59+
// Cargo registry credentials must remain URL-scoped. Do not allow OIDC
60+
// registration to fall back to host-only matching when url is empty.
61+
if url != "" {
62+
if _, _, ok := handler.oidcRegistry.Register(credential, []string{"url"}, "cargo registry"); ok {
63+
continue
6664
}
67-
continue
6865
}
6966

7067
cargoCred := cargoRepositoryCredentials{
@@ -90,7 +87,7 @@ func (h *CargoRegistryHandler) HandleRequest(req *http.Request, ctx *goproxy.Pro
9087
}
9188

9289
// Try OIDC credentials first
93-
if oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) {
90+
if h.oidcRegistry.TryAuth(req, ctx) {
9491
return req, nil
9592
}
9693

0 commit comments

Comments
 (0)