mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-20 14:41:28 +01:00
Merge pull request #67 from Benniu/master
Fix bug: Failed to get repository tags
This commit is contained in:
commit
b6a2f5eb9e
@ -21,7 +21,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"github.com/vmware/harbor/utils/log"
|
"github.com/vmware/harbor/utils/log"
|
||||||
)
|
)
|
||||||
@ -62,22 +62,13 @@ func RegistryAPIGet(url, username string) ([]byte, error) {
|
|||||||
} else if response.StatusCode == http.StatusUnauthorized {
|
} else if response.StatusCode == http.StatusUnauthorized {
|
||||||
authenticate := response.Header.Get("WWW-Authenticate")
|
authenticate := response.Header.Get("WWW-Authenticate")
|
||||||
log.Debugf("authenticate header: %s", authenticate)
|
log.Debugf("authenticate header: %s", authenticate)
|
||||||
str := strings.Split(authenticate, " ")[1]
|
|
||||||
var service string
|
var service string
|
||||||
var scope string
|
var scope string
|
||||||
strs := strings.Split(str, ",")
|
re := regexp.MustCompile(`service=\"(.*?)\".*scope=\"(.*?)\"`)
|
||||||
for _, s := range strs {
|
res := re.FindStringSubmatch(authenticate)
|
||||||
if strings.Contains(s, "service") {
|
if len(res) > 2 {
|
||||||
service = s
|
service = res[1]
|
||||||
} else if strings.Contains(s, "scope") {
|
scope = res[2]
|
||||||
scope = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if arr := strings.Split(service, "\""); len(arr) > 1 {
|
|
||||||
service = arr[1]
|
|
||||||
}
|
|
||||||
if arr := strings.Split(scope, "\""); len(arr) > 1 {
|
|
||||||
scope = arr[1]
|
|
||||||
}
|
}
|
||||||
token, err := GenTokenForUI(username, service, scope)
|
token, err := GenTokenForUI(username, service, scope)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user