Skip to content

Commit 6d6175b

Browse files
committed
Refactor Credentials method to use findCredentials to eliminate duplicated parsing logic
1 parent 0631ebd commit 6d6175b

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

pkg/registry/auth.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,15 @@ func (a *AuthProvider) Register(server *grpc.Server) {
6060
}
6161

6262
func (a *AuthProvider) Credentials(ctx context.Context, req *auth.CredentialsRequest) (*auth.CredentialsResponse, error) {
63-
for _, c := range a.credentials {
64-
if c.Host == req.Host {
65-
decodedAuth, err := base64.StdEncoding.DecodeString(c.Token)
66-
if err != nil {
67-
return nil, err
68-
}
69-
70-
usernamePassword := strings.SplitN(string(decodedAuth), ":", 2)
71-
if len(usernamePassword) != 2 {
72-
return nil, fmt.Errorf("invalid auth string")
73-
}
74-
75-
return &auth.CredentialsResponse{
76-
Username: usernamePassword[0],
77-
Secret: usernamePassword[1],
78-
}, nil
79-
}
63+
creds, err := a.findCredentials(req.Host)
64+
if err != nil {
65+
return nil, err
66+
}
67+
if creds != nil {
68+
return &auth.CredentialsResponse{
69+
Username: creds.Username,
70+
Secret: creds.Password,
71+
}, nil
8072
}
8173

8274
return a.inner.Credentials(ctx, req)

0 commit comments

Comments
 (0)