Skip to content

Commit 9dfeb71

Browse files
committed
Migrate pub handler to OIDCRegistry
Replace manual OIDC credential map and mutex with the shared OIDCRegistry type. Pub already used the full URL as the OIDC key, so this is a pure structural refactor with no behavior change. OIDC registration is guarded with url != "" to preserve the original URL-scoped behavior.
1 parent 5328230 commit 9dfeb71

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

internal/handlers/pub_repository.go

Lines changed: 12 additions & 12 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"
@@ -17,9 +16,8 @@ import (
1716
// the v2 spec.
1817
// https://github.com/dart-lang/pub/blob/db003f2ec3a0751337a1c8d4ff22d4863a28afe6/doc/repository-spec-v2.md
1918
type PubRepositoryHandler struct {
20-
credentials []pubRepositoryCredentials
21-
oidcCredentials map[string]*oidc.OIDCCredential
22-
mutex sync.RWMutex
19+
credentials []pubRepositoryCredentials
20+
oidcRegistry *oidc.OIDCRegistry
2321
}
2422

2523
type pubRepositoryCredentials struct {
@@ -29,8 +27,8 @@ type pubRepositoryCredentials struct {
2927

3028
func NewPubRepositoryHandler(credentials config.Credentials) *PubRepositoryHandler {
3129
handler := PubRepositoryHandler{
32-
credentials: []pubRepositoryCredentials{},
33-
oidcCredentials: make(map[string]*oidc.OIDCCredential),
30+
credentials: []pubRepositoryCredentials{},
31+
oidcRegistry: oidc.NewOIDCRegistry(),
3432
}
3533

3634
for _, credential := range credentials {
@@ -40,12 +38,14 @@ func NewPubRepositoryHandler(credentials config.Credentials) *PubRepositoryHandl
4038

4139
url := credential.GetString("url")
4240

43-
oidcCredential, _ := oidc.CreateOIDCCredential(credential)
44-
if oidcCredential != nil {
45-
if url != "" {
46-
handler.oidcCredentials[url] = oidcCredential
47-
logging.RequestLogf(nil, "registered %s OIDC credentials for pub repository: %s", oidcCredential.Provider(), url)
41+
// Pub credentials must remain URL-scoped. Do not allow OIDC
42+
// registration to fall back to host-only matching when url is empty.
43+
if url != "" {
44+
if _, _, ok := handler.oidcRegistry.Register(credential, []string{"url"}, "pub repository"); ok {
45+
continue
4846
}
47+
} else if oidcCred, _ := oidc.CreateOIDCCredential(credential); oidcCred != nil {
48+
// OIDC-configured but no URL — skip entirely (matches original behavior).
4949
continue
5050
}
5151

@@ -72,7 +72,7 @@ func (h *PubRepositoryHandler) HandleRequest(req *http.Request, ctx *goproxy.Pro
7272
}
7373

7474
// Try OIDC credentials first
75-
if oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) {
75+
if h.oidcRegistry.TryAuth(req, ctx) {
7676
return req, nil
7777
}
7878

0 commit comments

Comments
 (0)