verify secret

Signed-off-by: zhuxiaoyang <sunzhu@yunify.com>
This commit is contained in:
zhuxiaoyang
2020-02-10 21:52:48 +08:00
parent 291af6707e
commit 3698af5e8e
2 changed files with 20 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import (
"time"
)
// TODO: deprecated, use github.com/docker/docker/api/types.AuthConfig instead
type AuthInfo struct {
Username string `json:"username" description:"username"`
Password string `json:"password" description:"password"`

View File

@@ -28,6 +28,8 @@ import (
"k8s.io/klog"
log "k8s.io/klog"
"kubesphere.io/kubesphere/pkg/informers"
"net/http"
"strings"
)
const (
@@ -68,6 +70,23 @@ func RegistryVerify(authInfo AuthInfo) error {
ServerAddress: authInfo.ServerHost,
}
// Sometimes request DockerHub V2 API will timeout in China. Skipped.
if authInfo.ServerHost != DefaultDockerHub {
var checkAPIVersionUrl string
if strings.Contains(authInfo.ServerHost, "://") {
checkAPIVersionUrl = authInfo.ServerHost + "/v2/"
} else {
// default use HTTPS protocol
checkAPIVersionUrl = "https://" + authInfo.ServerHost + "/v2/"
}
_, err := http.Get(checkAPIVersionUrl)
if err != nil {
return err
}
}
// TODO: deprecated, use native Docker Registry v2 authentication.
resp, err := cli.RegistryLogin(ctx, config)
cli.Close()