mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Improve the pre-push repository lookup for permisisons
This commit is contained in:
parent
161526d99d
commit
6ccd473127
1 changed files with 17 additions and 2 deletions
19
registry.go
19
registry.go
|
@ -334,13 +334,28 @@ func (graph *Graph) pushTag(remote, revision, tag string, authConfig *auth.AuthC
|
||||||
func (graph *Graph) LookupRemoteRepository(remote string, authConfig *auth.AuthConfig) bool {
|
func (graph *Graph) LookupRemoteRepository(remote string, authConfig *auth.AuthConfig) bool {
|
||||||
rt := &http.Transport{Proxy: http.ProxyFromEnvironment}
|
rt := &http.Transport{Proxy: http.ProxyFromEnvironment}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", REGISTRY_ENDPOINT+"/users/"+remote, nil)
|
var repositoryTarget string
|
||||||
|
// If we are asking for 'root' repository, lookup on the Library's registry
|
||||||
|
if strings.Index(remote, "/") == -1 {
|
||||||
|
repositoryTarget = REGISTRY_ENDPOINT + "/library/" + remote + "/lookup"
|
||||||
|
} else {
|
||||||
|
repositoryTarget = REGISTRY_ENDPOINT + "/users/" + remote + "/lookup"
|
||||||
|
}
|
||||||
|
Debugf("Checking for permissions on: %s", repositoryTarget)
|
||||||
|
req, err := http.NewRequest("PUT", repositoryTarget, strings.NewReader("\"\""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Debugf("%s\n", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
|
req.Header.Add("Content-type", "application/json")
|
||||||
res, err := rt.RoundTrip(req)
|
res, err := rt.RoundTrip(req)
|
||||||
if err != nil || res.StatusCode != 200 {
|
if err != nil || res.StatusCode != 404 {
|
||||||
|
errBody, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
errBody = []byte(err.Error())
|
||||||
|
}
|
||||||
|
Debugf("Lookup status code: %d (body: %s)", res.StatusCode, errBody)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue