@@ -43,37 +43,6 @@ func (r *Registry) RegistryStr() string {
43
43
return strings .Split (r .URL , "/" )[0 ]
44
44
}
45
45
46
- // initAuthenticator returns an authn.Authenticator used by the docker golang library
47
- // to authenticate with a docker registry
48
- //
49
- // We generate the authn.Authenticator once, otherwise the resolver will try to resolve
50
- // the gcloud credentials before each api call. We check for the presence of an environment
51
- // variable GCR_JSON_KEY_PATH. If present, we use it, otherwise, we default to the default
52
- // keychain mechanism.
53
- func (r * Registry ) initAuthenticator () error {
54
- gcrJSONKeyPath := os .Getenv (EnvGcrJSONKeyPath )
55
- if gcrJSONKeyPath != "" {
56
- key , err := os .ReadFile (gcrJSONKeyPath ) //nolint:gosec
57
- if err != nil {
58
- return fmt .Errorf ("failed to resolve authenticator using gcr json key at %s: %w" , gcrJSONKeyPath , err )
59
- }
60
- r .authenticator = & authn.Basic {
61
- Username : "_json_key" ,
62
- Password : string (key ),
63
- }
64
-
65
- return nil
66
- }
67
-
68
- var err error
69
- r .authenticator , err = authn .DefaultKeychain .Resolve (r )
70
- if err != nil {
71
- return fmt .Errorf ("failed to resolve authenticator using default keychain: %w" , err )
72
- }
73
-
74
- return nil
75
- }
76
-
77
46
// Head is a wrapper to the remote.Head method.
78
47
func (r * Registry ) Head (imageRef string ) (* v1.Descriptor , error ) {
79
48
ref , err := name .ParseReference (imageRef )
@@ -152,3 +121,34 @@ func (r *Registry) Retag(existingRef, toCreateRef string) error {
152
121
153
122
return nil
154
123
}
124
+
125
+ // initAuthenticator returns an authn.Authenticator used by the docker golang library
126
+ // to authenticate with a docker registry
127
+ //
128
+ // We generate the authn.Authenticator once, otherwise the resolver will try to resolve
129
+ // the gcloud credentials before each api call. We check for the presence of an environment
130
+ // variable GCR_JSON_KEY_PATH. If present, we use it, otherwise, we default to the default
131
+ // keychain mechanism.
132
+ func (r * Registry ) initAuthenticator () error {
133
+ gcrJSONKeyPath := os .Getenv (EnvGcrJSONKeyPath )
134
+ if gcrJSONKeyPath != "" {
135
+ key , err := os .ReadFile (gcrJSONKeyPath ) //nolint:gosec
136
+ if err != nil {
137
+ return fmt .Errorf ("failed to resolve authenticator using gcr json key at %s: %w" , gcrJSONKeyPath , err )
138
+ }
139
+ r .authenticator = & authn.Basic {
140
+ Username : "_json_key" ,
141
+ Password : string (key ),
142
+ }
143
+
144
+ return nil
145
+ }
146
+
147
+ var err error
148
+ r .authenticator , err = authn .DefaultKeychain .Resolve (r )
149
+ if err != nil {
150
+ return fmt .Errorf ("failed to resolve authenticator using default keychain: %w" , err )
151
+ }
152
+
153
+ return nil
154
+ }
0 commit comments