PingV2Registry attempts to ping a v2 registry and on success return a challenge manager for the supported authentication types. If a response is received but cannot be interpreted, a PingResponseError will be returned.
(endpoint *url.URL, authTransport http.RoundTripper)
| 102 | // challenge manager for the supported authentication types. |
| 103 | // If a response is received but cannot be interpreted, a PingResponseError will be returned. |
| 104 | func PingV2Registry(endpoint *url.URL, authTransport http.RoundTripper) (challenge.Manager, error) { |
| 105 | endpointStr := strings.TrimRight(endpoint.String(), "/") + "/v2/" |
| 106 | req, err := http.NewRequest(http.MethodGet, endpointStr, http.NoBody) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | pingClient := &http.Client{ |
| 111 | Transport: authTransport, |
| 112 | Timeout: 15 * time.Second, |
| 113 | } |
| 114 | resp, err := pingClient.Do(req) |
| 115 | if err != nil { |
| 116 | return nil, err |
| 117 | } |
| 118 | defer resp.Body.Close() |
| 119 | |
| 120 | challengeManager := challenge.NewSimpleManager() |
| 121 | if err := challengeManager.AddResponse(resp); err != nil { |
| 122 | return nil, err |
| 123 | } |
| 124 | |
| 125 | return challengeManager, nil |
| 126 | } |
no test coverage detected
searching dependent graphs…