github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/docker/registry/internal/gitlab.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 gitlabContainerRegistry struct { 16 *baseClient 17 } 18 19 func newGitlabContainerRegistry(repoDetails docker.ImageRepoDetails, transport http.RoundTripper) (RegistryInternal, error) { 20 c, err := newBase(repoDetails, transport, normalizeRepoDetailsCommon) 21 if err != nil { 22 return nil, errors.Trace(err) 23 } 24 return &gitlabContainerRegistry{c}, nil 25 } 26 27 func (c *gitlabContainerRegistry) String() string { 28 return "registry.gitlab.com" 29 } 30 31 // Match checks if the repository details matches current provider format. 32 func (c *gitlabContainerRegistry) Match() bool { 33 return strings.Contains(c.repoDetails.ServerAddress, "registry.gitlab.com") 34 } 35 36 func (c *gitlabContainerRegistry) WrapTransport(...TransportWrapper) error { 37 return c.baseClient.WrapTransport() 38 } 39 40 // Ping pings the gitlab endpoint. 41 func (c gitlabContainerRegistry) Ping() error { 42 if !c.repoDetails.IsPrivate() { 43 // The root gitlab endpoint requires credentials. 44 // Anonymous login does not work. 45 return nil 46 } 47 return c.baseClient.Ping() 48 }