Skip to content

Commit dc41365

Browse files
committed
internal/registry: remove NewStaticCredentialStore
It was only used in a single place; inline it there. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent dad2e67 commit dc41365

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

cli/registry/client/endpoint.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
"net"
55
"net/http"
6+
"net/url"
67
"time"
78

89
"github.com/distribution/reference"
@@ -97,7 +98,7 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API
9798
if len(actions) == 0 {
9899
actions = []string{"pull"}
99100
}
100-
creds := registry.NewStaticCredentialStore(&authConfig)
101+
creds := &staticCredentialStore{authConfig: &authConfig}
101102
tokenHandler := auth.NewTokenHandler(authTransport, creds, repoName, actions...)
102103
basicHandler := auth.NewBasicHandler(creds)
103104
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))
@@ -117,3 +118,23 @@ func (th *existingTokenHandler) AuthorizeRequest(req *http.Request, _ map[string
117118
func (*existingTokenHandler) Scheme() string {
118119
return "bearer"
119120
}
121+
122+
type staticCredentialStore struct {
123+
authConfig *registrytypes.AuthConfig
124+
}
125+
126+
func (scs staticCredentialStore) Basic(*url.URL) (string, string) {
127+
if scs.authConfig == nil {
128+
return "", ""
129+
}
130+
return scs.authConfig.Username, scs.authConfig.Password
131+
}
132+
133+
func (scs staticCredentialStore) RefreshToken(*url.URL, string) string {
134+
if scs.authConfig == nil {
135+
return ""
136+
}
137+
return scs.authConfig.IdentityToken
138+
}
139+
140+
func (staticCredentialStore) SetRefreshToken(*url.URL, string, string) {}

internal/registry/auth.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,6 @@ func (lcs loginCredentialStore) SetRefreshToken(u *url.URL, service, token strin
3434
lcs.authConfig.IdentityToken = token
3535
}
3636

37-
type staticCredentialStore struct {
38-
auth *registry.AuthConfig
39-
}
40-
41-
// NewStaticCredentialStore returns a credential store
42-
// which always returns the same credential values.
43-
func NewStaticCredentialStore(ac *registry.AuthConfig) auth.CredentialStore {
44-
return staticCredentialStore{
45-
auth: ac,
46-
}
47-
}
48-
49-
func (scs staticCredentialStore) Basic(*url.URL) (string, string) {
50-
if scs.auth == nil {
51-
return "", ""
52-
}
53-
return scs.auth.Username, scs.auth.Password
54-
}
55-
56-
func (scs staticCredentialStore) RefreshToken(*url.URL, string) string {
57-
if scs.auth == nil {
58-
return ""
59-
}
60-
return scs.auth.IdentityToken
61-
}
62-
63-
func (staticCredentialStore) SetRefreshToken(*url.URL, string, string) {
64-
}
65-
6637
// loginV2 tries to login to the v2 registry server. The given registry
6738
// endpoint will be pinged to get authorization challenges. These challenges
6839
// will be used to authenticate against the registry to validate credentials.

0 commit comments

Comments
 (0)