未验证 提交 89b98030 编写于 作者: C colynn.liu 提交者: GitHub

Merge pull request #140 from sampsonye/feat-registry-errmsg-upgrade

优化Registry连接失败时的提示信息
......@@ -14,10 +14,18 @@ func TryLoginRegistry(basicUrl, username, password string, insecure bool) error
} else {
schema = "https"
}
url := fmt.Sprintf("%s://%s/v2/", schema, strings.TrimRight(basicUrl, "/"))
resp, err := http.Get(url)
if err != nil || resp.StatusCode != 401 {
return errors.New("error basicUrl")
hostUrl := fmt.Sprintf("%s://%s", schema, strings.TrimRight(basicUrl, "/"))
resp, err := http.Get(hostUrl)
if err != nil {
return errors.New(fmt.Sprintf("%s访问异常:%s", hostUrl, err.Error()))
}
url := fmt.Sprintf("%s/v2/", hostUrl)
resp, err = http.Get(url)
if err != nil {
return errors.New(fmt.Sprintf("%s访问异常:%s", url, err.Error()))
}
if resp.StatusCode != 401 {
return errors.New(fmt.Sprintf("%s不支持V2版本访问", url))
}
//get Auth Info
auth := resp.Header.Get("Www-Authenticate")
......@@ -43,17 +51,17 @@ func TryLoginRegistry(basicUrl, username, password string, insecure bool) error
authFullUrl = authBaseUrl
}
req, err := http.NewRequest("GET", authFullUrl, nil)
req.SetBasicAuth(username, password)
if err != nil {
return errors.New("incorrect username or password")
return errors.New("账号或密码不正确")
}
req.SetBasicAuth(username, password)
client := http.Client{}
resp, err = client.Do(req)
if err != nil {
return err
}
if resp.StatusCode != 200 {
return errors.New("incorrect username or password")
return errors.New("账号或密码不正确")
}
//body, err := ioutil.ReadAll(resp.Body)
//fmt.Println(string(body))
......
......@@ -336,7 +336,7 @@ func (pm *SettingManager) VerifyIntegrateSetting(request *IntegrateSettingReq) V
if err := TryLoginRegistry(registryConf.URL, registryConf.User, registryConf.Password, !registryConf.IsHttps); err != nil {
resp.Error = err
} else {
resp.Msg = "Connected to Registry"
resp.Msg = "连接成功"
}
}
case JenkinsType:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册