2016-09-05 22:44:19 -04:00
|
|
|
package registry
|
|
|
|
|
2018-12-29 12:09:10 -05:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
2019-06-10 12:57:48 -04:00
|
|
|
"strings"
|
2018-12-29 12:09:10 -05:00
|
|
|
)
|
|
|
|
|
2019-06-10 12:57:48 -04:00
|
|
|
// Pingable checks pingable
|
|
|
|
func (r *Registry) Pingable() bool {
|
|
|
|
// Currently *.gcr.io/v2 can't be ping if users have each projects auth
|
|
|
|
return !strings.HasSuffix(r.URL, "gcr.io")
|
|
|
|
}
|
|
|
|
|
2016-09-05 22:44:19 -04:00
|
|
|
// Ping tries to contact a registry URL to make sure it is up and accessible.
|
2018-12-29 12:09:10 -05:00
|
|
|
func (r *Registry) Ping(ctx context.Context) error {
|
2016-09-05 22:44:19 -04:00
|
|
|
url := r.url("/v2/")
|
|
|
|
r.Logf("registry.ping url=%s", url)
|
2018-12-29 12:09:10 -05:00
|
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
resp, err := r.Client.Do(req.WithContext(ctx))
|
2016-09-05 22:44:19 -04:00
|
|
|
if resp != nil {
|
|
|
|
defer resp.Body.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|