github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/docker/registry/internal/quay.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  	"net/http"
     8  	"strings"
     9  
    10  	"github.com/juju/errors"
    11  
    12  	"github.com/juju/juju/docker"
    13  )
    14  
    15  type quayContainerRegistry struct {
    16  	*baseClient
    17  }
    18  
    19  func newQuayContainerRegistry(repoDetails docker.ImageRepoDetails, transport http.RoundTripper) (RegistryInternal, error) {
    20  	c, err := newBase(repoDetails, transport, normalizeRepoDetailsCommon)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  	return &quayContainerRegistry{c}, nil
    25  }
    26  
    27  func (c *quayContainerRegistry) String() string {
    28  	return "quay.io"
    29  }
    30  
    31  // Match checks if the repository details matches current provider format.
    32  func (c *quayContainerRegistry) Match() bool {
    33  	return strings.Contains(c.repoDetails.ServerAddress, "quay.io")
    34  }
    35  
    36  // Ping pings the quay endpoint.
    37  func (c quayContainerRegistry) Ping() error {
    38  	if !c.repoDetails.IsPrivate() {
    39  		// quay.io root path requires authentication.
    40  		// So skip ping for public repositories.
    41  		return nil
    42  	}
    43  	url := c.url("/")
    44  	logger.Debugf("quay container registry ping %q", url)
    45  	resp, err := c.client.Get(url)
    46  	if resp != nil {
    47  		defer resp.Body.Close()
    48  	}
    49  	return errors.Trace(unwrapNetError(err))
    50  }