swift: fix refresh of authentication token

Before this fix we were doing the token refresh but ignoring the new
tokens.

This bug was introduced in v1.39 by 4c0e2f9b3b

Fixes #2018
Fixes #2031
This commit is contained in:
Nick Craig-Wood 2018-02-15 19:18:11 +00:00
parent 9a34fd984c
commit b1945d0094

View File

@ -221,6 +221,7 @@ func swiftConnection(name string) (*swift.Connection, error) {
return nil, errors.Wrap(err, "failed to read environment variables") return nil, errors.Wrap(err, "failed to read environment variables")
} }
} }
StorageUrl, AuthToken := c.StorageUrl, c.AuthToken
if !c.Authenticated() { if !c.Authenticated() {
if c.UserName == "" && c.UserId == "" { if c.UserName == "" && c.UserId == "" {
return nil, errors.New("user name or user id not found for authentication (and no storage_url+auth_token is provided)") return nil, errors.New("user name or user id not found for authentication (and no storage_url+auth_token is provided)")
@ -231,15 +232,16 @@ func swiftConnection(name string) (*swift.Connection, error) {
if c.AuthUrl == "" { if c.AuthUrl == "" {
return nil, errors.New("auth not found") return nil, errors.New("auth not found")
} }
err := c.Authenticate() err := c.Authenticate() // fills in c.StorageUrl and c.AuthToken
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
// Make sure we re-auth with the AuthToken and StorageUrl // Make sure we re-auth with the AuthToken and StorageUrl
// provided by wrapping the existing auth // provided by wrapping the existing auth, so we can just
if c.StorageUrl != "" || c.AuthToken != "" { // override one or the other or both.
c.Auth = newAuth(c.Auth, c.StorageUrl, c.AuthToken) if StorageUrl != "" || AuthToken != "" {
c.Auth = newAuth(c.Auth, StorageUrl, AuthToken)
} }
return c, nil return c, nil
} }