mirror of
https://github.com/genuinetools/reg.git
synced 2024-05-20 12:08:33 -04:00
auth service fix for token
Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
parent
bd56ba0eff
commit
0dbc9338a6
|
@ -2,6 +2,7 @@ package registry
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -117,17 +118,22 @@ func isTokenDemand(resp *http.Response) (*authService, error) {
|
|||
func (r *Registry) Token(url string) (string, error) {
|
||||
r.Logf("registry.token url=%s", url)
|
||||
|
||||
resp, err := r.Client.Get(url)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
a, err := isTokenDemand(resp)
|
||||
if err != nil || a == nil {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if a == nil {
|
||||
r.Logf("registry.token authService=nil")
|
||||
return "", nil
|
||||
}
|
||||
|
||||
authReq, err := a.Request(r.Username, r.Password)
|
||||
resp, err = r.Client.Do(authReq)
|
||||
if err != nil {
|
||||
|
@ -136,7 +142,7 @@ func (r *Registry) Token(url string) (string, error) {
|
|||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return "", err
|
||||
return "", fmt.Errorf("Getting token failed with StatusCode != StatusOK but %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
var authToken authToken
|
||||
|
@ -144,5 +150,9 @@ func (r *Registry) Token(url string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
if authToken.Token == "" {
|
||||
return "", errors.New("Auth token cannot be empty.")
|
||||
}
|
||||
|
||||
return authToken.Token, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue