@@ -18,6 +18,7 @@ import (
1818type GCPRemoteRepository struct {
1919 repositoryURL string
2020 registry * artifactregistry.Client
21+ authToken authn.Authenticator
2122}
2223
2324var gcpAuthConfig = authn.Basic {
@@ -31,7 +32,12 @@ func NewGCPRemoteRepository(ctx context.Context, repositoryURL string) (*GCPRemo
3132 return nil , fmt .Errorf ("error creating artifact registry client: %w" , err )
3233 }
3334
34- return & GCPRemoteRepository {repositoryURL : repositoryURL , registry : registry }, nil
35+ authToken , err := getAuthToken (ctx )
36+ if err != nil {
37+ return nil , fmt .Errorf ("error getting auth token: %w" , err )
38+ }
39+
40+ return & GCPRemoteRepository {repositoryURL : repositoryURL , registry : registry , authToken : authToken }, nil
3541}
3642
3743func (g * GCPRemoteRepository ) GetImage (ctx context.Context , tag string , platform containerregistry.Platform ) (containerregistry.Image , error ) {
@@ -45,20 +51,15 @@ func (g *GCPRemoteRepository) GetImage(ctx context.Context, tag string, platform
4551 return nil , fmt .Errorf ("invalid image reference: %w" , err )
4652 }
4753
48- authToken , err := g .getAuthToken (ctx )
49- if err != nil {
50- return nil , fmt .Errorf ("error getting auth token: %w" , err )
51- }
52-
53- img , err := remote .Image (ref , remote .WithAuth (authToken ), remote .WithPlatform (platform ))
54+ img , err := remote .Image (ref , remote .WithAuth (g .authToken ), remote .WithPlatform (platform ))
5455 if err != nil {
5556 return nil , fmt .Errorf ("error pulling image: %w" , err )
5657 }
5758
5859 return img , nil
5960}
6061
61- func ( g * GCPRemoteRepository ) getAuthToken (_ context.Context ) (authn.Authenticator , error ) {
62+ func getAuthToken (_ context.Context ) (authn.Authenticator , error ) {
6263 authCfg := consts .DockerAuthConfig
6364 if authCfg == "" {
6465 return & gcpAuthConfig , nil
@@ -83,3 +84,7 @@ func (g *GCPRemoteRepository) getAuthToken(_ context.Context) (authn.Authenticat
8384 Password : cfg .Password ,
8485 }, nil
8586}
87+
88+ func (g * GCPRemoteRepository ) Close () error {
89+ return g .registry .Close ()
90+ }
0 commit comments