package artifactregistry import ( "context" "fmt" gcpgar "cloud.google.com/go/artifactregistry/apiv1" "cloud.google.com/go/artifactregistry/apiv1/artifactregistrypb" ) type ArtifactRegistry struct { garClient *gcpgar.Client } func NewArtifactRegistry(ctx context.Context) (*ArtifactRegistry, error) { client, err := gcpgar.NewClient(ctx) if err != nil { return nil, err } ar := &ArtifactRegistry{ garClient: client, } return ar, nil } func (ar *ArtifactRegistry) ListTags(location, project, repository, pkg string) (*gcpgar.TagIterator, error) { parentString := fmt.Sprintf( "projects/%s/locations/%s/repositories/%s/packages/%s", project, location, repository, pkg, ) getTagsReq := &artifactregistrypb.ListTagsRequest{ Parent: parentString, PageSize: 1000, } ctx := context.Background() return ar.garClient.ListTags(ctx, getTagsReq), nil } func (ar *ArtifactRegistry) GetTag(location, project, repository, pkg, tag string) (*artifactregistrypb.Tag, error) { parentString := fmt.Sprintf( "projects/%s/locations/%s/repositories/%s/packages/%s/tags/%s", project, location, repository, pkg, tag, ) getTagReq := &artifactregistrypb.GetTagRequest{ Name: parentString, } ctx := context.Background() return ar.garClient.GetTag(ctx, getTagReq) } func (ar *ArtifactRegistry) GetVersion(location, project, repository, pkg, version string) (*artifactregistrypb.Version, error) { parentString := fmt.Sprintf( "projects/%s/locations/%s/repositories/%s/packages/%s/versions/%s", project, location, repository, pkg, version, ) getVersionReq := &artifactregistrypb.GetVersionRequest{ Name: parentString, View: artifactregistrypb.VersionView_FULL, } ctx := context.Background() return ar.garClient.GetVersion(ctx, getVersionReq) } func (ar *ArtifactRegistry) Close() error { return ar.garClient.Close() }