Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

backend/repository: assume no v2 on unexpected status #214

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/internal/backend/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,26 @@ func (rb *RepositoryBackend) BuildACI(layerIDs []string, dockerURL *types.Parsed
}
}

// checkRegistryStatus determines registry API version compatibility according to spec:
// https://docs.docker.com/registry/spec/api/#/api-version-check
func checkRegistryStatus(statusCode int, hdr http.Header, version registryVersion) (bool, error) {
switch statusCode {
case http.StatusOK, http.StatusUnauthorized:
ok := true
if version == registryV2 {
// v2 API requires this check
// According to v2 spec, registries SHOULD set this header value
// and clients MAY fallback to v1 if missing, as done here.
ok = hdr.Get("Docker-Distribution-API-Version") == "registry/2.0"
}
return ok, nil
case http.StatusNotFound:
return false, nil
}

return false, fmt.Errorf("unexpected http code: %d", statusCode)
return false, nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a compilation failure, since there is nothing returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local build+test seems fine (go 1.6.3), but I see over-zealous checkers may get confused. I'll switch to a false-return at the bottom.

}

func (rb *RepositoryBackend) supportsRegistry(indexURL string, version registryVersion) (schema string, ok bool, err error) {
var URLPath string
switch version {
case registryV1:
// the v1 API defines this URL to check if the registry's status
URLPath = "v1/_ping"
case registryV2:
URLPath = "v2"
Expand Down