@@ -52,7 +52,7 @@ func Login(ctx context.Context, store Store, reg *remote.Registry, cred auth.Cre
52
52
if err := regClone .Ping (ctx ); err != nil {
53
53
return fmt .Errorf ("failed to validate the credential for %s: %w" , regClone .Reference .Registry , err )
54
54
}
55
- hostname := mapStoreRegistryName (regClone .Reference .Registry )
55
+ hostname := ServerAddressFromRegistry (regClone .Reference .Registry )
56
56
if err := store .Put (ctx , hostname , cred ); err != nil {
57
57
return fmt .Errorf ("failed to store the credential for %s: %w" , hostname , err )
58
58
}
@@ -61,7 +61,7 @@ func Login(ctx context.Context, store Store, reg *remote.Registry, cred auth.Cre
61
61
62
62
// Logout provides the logout functionality given the registry name.
63
63
func Logout (ctx context.Context , store Store , registryName string ) error {
64
- registryName = mapStoreRegistryName (registryName )
64
+ registryName = ServerAddressFromRegistry (registryName )
65
65
if err := store .Delete (ctx , registryName ); err != nil {
66
66
return fmt .Errorf ("failed to delete the credential for %s: %w" , registryName , err )
67
67
}
@@ -71,28 +71,30 @@ func Logout(ctx context.Context, store Store, registryName string) error {
71
71
// Credential returns a Credential() function that can be used by auth.Client.
72
72
func Credential (store Store ) func (context.Context , string ) (auth.Credential , error ) {
73
73
return func (ctx context.Context , reg string ) (auth.Credential , error ) {
74
- reg = mapAuthenticationRegistryName (reg )
74
+ reg = ServerAddressFromHostname (reg )
75
75
if reg == "" {
76
76
return auth .EmptyCredential , nil
77
77
}
78
78
return store .Get (ctx , reg )
79
79
}
80
80
}
81
81
82
- func mapStoreRegistryName (registry string ) string {
83
- // The Docker CLI expects that the 'docker.io' credential
84
- // will be added under the key "https://index.docker.io/v1/"
85
- // See: https://github.com/moby/moby/blob/v24.0.0-beta.2/registry/config.go#L25-L48
82
+ // ServerAddressFromRegistry maps a registry to a server address, which is used as
83
+ // a key for credentials store. The Docker CLI expects that the credentials of
84
+ // the registry 'docker.io' will be added under the key "https://index.docker.io/v1/".
85
+ // See: https://github.com/moby/moby/blob/v24.0.2/registry/config.go#L25-L48
86
+ func ServerAddressFromRegistry (registry string ) string {
86
87
if registry == "docker.io" {
87
88
return "https://index.docker.io/v1/"
88
89
}
89
90
return registry
90
91
}
91
92
92
- func mapAuthenticationRegistryName (hostname string ) string {
93
- // It is expected that the traffic targetting "registry-1.docker.io"
94
- // will be redirected to "https://index.docker.io/v1/"
95
- // See: https://github.com/moby/moby/blob/v24.0.0-beta.2/registry/config.go#L25-L48
93
+ // ServerAddressFromHostname maps a hostname to a server address, which is used as
94
+ // a key for credentials store. It is expected that the traffic targetting the
95
+ // host "registry-1.docker.io" will be redirected to "https://index.docker.io/v1/".
96
+ // See: https://github.com/moby/moby/blob/v24.0.2/registry/config.go#L25-L48
97
+ func ServerAddressFromHostname (hostname string ) string {
96
98
if hostname == "registry-1.docker.io" {
97
99
return "https://index.docker.io/v1/"
98
100
}
0 commit comments