refinement per review

This commit is contained in:
Tan Jiang 2017-02-27 12:52:14 +08:00
parent 776c34a0ae
commit 81502e1e59
2 changed files with 7 additions and 5 deletions

View File

@ -105,7 +105,8 @@ func (e endpointParser) parse(s string) (*image, error) {
//Workaround, need to use endpoint Parser to handle both cases.
if strings.ContainsRune(repo[0], '.') {
if repo[0] != e.endpoint {
return nil, fmt.Errorf("Mismatch endpoint from string: %s, expected endpoint: %s", s, e.endpoint)
log.Warningf("Mismatch endpoint from string: %s, expected endpoint: %s, fallback to basic parser", s, e.endpoint)
return parseImg(s)
}
return parseImg(repo[1])
}
@ -209,12 +210,12 @@ func (g generalCreator) Create(r *http.Request) (*tokenJSON, error) {
log.Debugf("scopes: %v", scopes)
for _, v := range g.validators {
user, err = v.validate(r)
if user != nil {
break
}
if err != nil {
return nil, err
}
if user != nil {
break
}
}
if user == nil {
if len(scopes) == 0 {
@ -227,6 +228,7 @@ func (g generalCreator) Create(r *http.Request) (*tokenJSON, error) {
f, ok := g.filterMap[a.Type]
if !ok {
log.Warningf("No filter found for access type: %s, skip.", a.Type)
continue
}
err = f.filter(*user, a)
if err != nil {

View File

@ -169,8 +169,8 @@ func TestEndpointParser(t *testing.T) {
}
testList := []parserTestRec{parserTestRec{"10.117.4.142:5000/library/ubuntu:14.04", image{"library", "ubuntu", "14.04"}, false},
parserTestRec{"myimage:14.04", image{}, true},
parserTestRec{"10.117.4.142:80/library/myimage:14.04", image{}, true},
//Test the temp workaround
parserTestRec{"10.117.4.142:80/library/myimage:14.04", image{"10.117.4.142:80", "library/myimage", "14.04"}, false},
parserTestRec{"library/myimage:14.04", image{"library", "myimage", "14.04"}, false},
parserTestRec{"10.117.4.142:5000/myimage:14.04", image{}, true},
parserTestRec{"10.117.4.142:5000/org/team/img", image{"org", "team/img", ""}, false},