github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/docker/registry/internal/acr.go (about) 1 // Copyright 2021 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package internal 5 6 import ( 7 "fmt" 8 "net/http" 9 "strings" 10 11 "github.com/juju/errors" 12 13 "github.com/juju/juju/docker" 14 "github.com/juju/juju/tools" 15 ) 16 17 type azureContainerRegistry struct { 18 *baseClient 19 } 20 21 func newAzureContainerRegistry(repoDetails docker.ImageRepoDetails, transport http.RoundTripper) (RegistryInternal, error) { 22 c, err := newBase(repoDetails, transport, normalizeRepoDetailsAzure) 23 if err != nil { 24 return nil, errors.Trace(err) 25 } 26 return &azureContainerRegistry{c}, nil 27 } 28 29 func normalizeRepoDetailsAzure(repoDetails *docker.ImageRepoDetails) error { 30 if repoDetails.ServerAddress == "" { 31 repoDetails.ServerAddress = repoDetails.Repository 32 } 33 return nil 34 } 35 36 func (c *azureContainerRegistry) String() string { 37 return "azurecr.io" 38 } 39 40 // Match checks if the repository details matches current provider format. 41 func (c *azureContainerRegistry) Match() bool { 42 return strings.Contains(c.repoDetails.ServerAddress, "azurecr.io") 43 } 44 45 func (c *azureContainerRegistry) WrapTransport(...TransportWrapper) error { 46 if c.repoDetails.BasicAuthConfig.Empty() { 47 return errors.NewNotValid(nil, fmt.Sprintf(`username and password are required for registry %q`, c.repoDetails.Repository)) 48 } 49 return c.baseClient.WrapTransport() 50 } 51 52 // Tags fetches tags for an OCI image. 53 func (c azureContainerRegistry) Tags(imageName string) (versions tools.Versions, err error) { 54 // acr puts the namespace under subdomain. 55 url := c.url("/%s/tags/list", imageName) 56 var response tagsResponseV2 57 return c.fetchTags(url, &response) 58 } 59 60 // GetArchitecture returns the archtecture of the image for the specified tag. 61 func (c azureContainerRegistry) GetArchitecture(imageName, tag string) (string, error) { 62 return getArchitecture(imageName, tag, c) 63 } 64 65 // GetManifests returns the manifests of the image for the specified tag. 66 func (c azureContainerRegistry) GetManifests(imageName, tag string) (*ManifestsResult, error) { 67 url := c.url("/%s/manifests/%s", imageName, tag) 68 return c.GetManifestsCommon(url) 69 } 70 71 // GetBlobs gets the archtecture of the image for the specified tag via blobs API. 72 func (c azureContainerRegistry) GetBlobs(imageName, digest string) (*BlobsResponse, error) { 73 url := c.url("/%s/blobs/%s", imageName, digest) 74 return c.GetBlobsCommon(url) 75 }