MCPcopy Create free account
hub / github.com/docker/cli / GetNotaryRepository

Function GetNotaryRepository

cmd/docker-trust/internal/trust/trust.go:119–201  ·  view source on GitHub ↗

GetNotaryRepository returns a NotaryRepository which stores all the information needed to operate on a notary repository. It creates an HTTP transport providing authentication support.

(in io.Reader, out io.Writer, userAgent string, repoInfo *RepositoryInfo, authConfig *registrytypes.AuthConfig, actions ...string)

Source from the content-addressed store, hash-verified

117// information needed to operate on a notary repository.
118// It creates an HTTP transport providing authentication support.
119func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo *RepositoryInfo, authConfig *registrytypes.AuthConfig, actions ...string) (client.Repository, error) {
120 server, err := Server(repoInfo.Index.Name)
121 if err != nil {
122 return nil, err
123 }
124 if server == NotaryServer {
125 _, _ = fmt.Fprint(os.Stderr, dctDeprecation)
126 }
127
128 cfg := tlsconfig.ClientDefault()
129 cfg.InsecureSkipVerify = !repoInfo.Index.Secure
130
131 // Get certificate base directory
132 certDir, err := certificateDirectory(server)
133 if err != nil {
134 return nil, err
135 }
136 logrus.Debugf("reading certificate directory: %s", certDir)
137
138 if err := registry.ReadCertsDirectory(cfg, certDir); err != nil {
139 return nil, err
140 }
141
142 base := &http.Transport{
143 Proxy: http.ProxyFromEnvironment,
144 Dial: (&net.Dialer{
145 Timeout: 30 * time.Second,
146 KeepAlive: 30 * time.Second,
147 }).Dial,
148 TLSHandshakeTimeout: 10 * time.Second,
149 TLSClientConfig: cfg,
150 DisableKeepAlives: true,
151 }
152
153 // Skip configuration headers since request is not going to Docker daemon
154 modifiers := registry.Headers(userAgent, http.Header{})
155 authTransport := transport.NewTransport(base, modifiers...)
156 pingClient := &http.Client{
157 Transport: authTransport,
158 Timeout: 5 * time.Second,
159 }
160 endpointStr := server + "/v2/"
161 req, err := http.NewRequest(http.MethodGet, endpointStr, nil)
162 if err != nil {
163 return nil, err
164 }
165
166 challengeManager := challenge.NewSimpleManager()
167
168 resp, err := pingClient.Do(req)
169 if err != nil {
170 // Ignore error on ping to operate in offline mode
171 logrus.Debugf("Error pinging notary server %q: %s", endpointStr, err)
172 } else {
173 defer resp.Body.Close()
174
175 // Add response to the challenge manager to parse out
176 // authentication header and register authentication method

Callers 1

PushTrustedReferenceFunction · 0.85

Calls 6

ServerFunction · 0.85
certificateDirectoryFunction · 0.85
GetTrustDirectoryFunction · 0.85
GetPassphraseRetrieverFunction · 0.85
CloseMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…