/
quay.go
50 lines (41 loc) · 1.18 KB
/
quay.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2021 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package internal
import (
"net/http"
"strings"
"github.com/juju/errors"
"github.com/juju/juju/docker"
)
type quayContainerRegistry struct {
*baseClient
}
func newQuayContainerRegistry(repoDetails docker.ImageRepoDetails, transport http.RoundTripper) (RegistryInternal, error) {
c, err := newBase(repoDetails, transport, normalizeRepoDetailsCommon)
if err != nil {
return nil, err
}
return &quayContainerRegistry{c}, nil
}
func (c *quayContainerRegistry) String() string {
return "quay.io"
}
// Match checks if the repository details matches current provider format.
func (c *quayContainerRegistry) Match() bool {
return strings.Contains(c.repoDetails.ServerAddress, "quay.io")
}
// Ping pings the quay endpoint.
func (c quayContainerRegistry) Ping() error {
if !c.repoDetails.IsPrivate() {
// quay.io root path requires authentication.
// So skip ping for public repositories.
return nil
}
url := c.url("/")
logger.Debugf("quay container registry ping %q", url)
resp, err := c.client.Get(url)
if resp != nil {
defer resp.Body.Close()
}
return errors.Trace(unwrapNetError(err))
}