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)
| 117 | // information needed to operate on a notary repository. |
| 118 | // It creates an HTTP transport providing authentication support. |
| 119 | func 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 |
no test coverage detected
searching dependent graphs…