From 595fea757d9c0278e6c0e2f5f2fca5938fa13d5d Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 18 Mar 2019 10:36:54 +0000 Subject: [PATCH] vendor: update github.com/ncw/swift to bring in Expires changes --- go.mod | 2 +- go.sum | 2 ++ vendor/github.com/ncw/swift/.travis.yml | 10 +++++----- vendor/github.com/ncw/swift/README.md | 1 + vendor/github.com/ncw/swift/auth.go | 15 +++++++++++++++ vendor/github.com/ncw/swift/auth_v3.go | 16 +++++++++++++--- vendor/github.com/ncw/swift/meta.go | 4 ++-- vendor/github.com/ncw/swift/swift.go | 16 +++++++++++++++- vendor/modules.txt | 2 +- 9 files changed, 55 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 21354b01e..f2334c005 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/kr/fs v0.1.0 // indirect github.com/mattn/go-runewidth v0.0.4 github.com/ncw/go-acd v0.0.0-20171120105400-887eb06ab6a2 - github.com/ncw/swift v1.0.44 + github.com/ncw/swift v1.0.46 github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d github.com/okzk/sdnotify v0.0.0-20180710141335-d9becc38acbd github.com/patrickmn/go-cache v2.1.0+incompatible diff --git a/go.sum b/go.sum index 63c59d11c..6052331e5 100644 --- a/go.sum +++ b/go.sum @@ -109,6 +109,8 @@ github.com/ncw/go-acd v0.0.0-20171120105400-887eb06ab6a2 h1:VlXvEx6JbFp7F9iz92zX github.com/ncw/go-acd v0.0.0-20171120105400-887eb06ab6a2/go.mod h1:MLIrzg7gp/kzVBxRE1olT7CWYMCklcUWU+ekoxOD9x0= github.com/ncw/swift v1.0.44 h1:EKvOTvUxElbpDWqxsyVaVGvc2IfuOqQnRmjnR2AGhQ4= github.com/ncw/swift v1.0.44/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= +github.com/ncw/swift v1.0.46 h1:ewnoFKEI9f2LT+gqmeeiJ1SCzOBDTcK3JF1XziR85QQ= +github.com/ncw/swift v1.0.46/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= diff --git a/vendor/github.com/ncw/swift/.travis.yml b/vendor/github.com/ncw/swift/.travis.yml index d064e46fe..e0a61643b 100644 --- a/vendor/github.com/ncw/swift/.travis.yml +++ b/vendor/github.com/ncw/swift/.travis.yml @@ -2,7 +2,6 @@ language: go sudo: false go: - - 1.1.x - 1.2.x - 1.3.x - 1.4.x @@ -13,18 +12,19 @@ go: - 1.9.x - 1.10.x - 1.11.x + - 1.12.x - master matrix: include: - - go: 1.11.x + - go: 1.12.x env: TEST_REAL_SERVER=rackspace - - go: 1.11.x + - go: 1.12.x env: TEST_REAL_SERVER=memset allow_failures: - - go: 1.11.x + - go: 1.12.x env: TEST_REAL_SERVER=rackspace - - go: 1.11.x + - go: 1.12.x env: TEST_REAL_SERVER=memset install: go test -i ./... script: diff --git a/vendor/github.com/ncw/swift/README.md b/vendor/github.com/ncw/swift/README.md index f08c5b6f4..0a09293d8 100644 --- a/vendor/github.com/ncw/swift/README.md +++ b/vendor/github.com/ncw/swift/README.md @@ -153,3 +153,4 @@ Contributors - Omar Ali - Andreas Andersen - kayrus +- CodeLingo Bot diff --git a/vendor/github.com/ncw/swift/auth.go b/vendor/github.com/ncw/swift/auth.go index 316dc7fe0..25654f429 100644 --- a/vendor/github.com/ncw/swift/auth.go +++ b/vendor/github.com/ncw/swift/auth.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "strings" + "time" ) // Auth defines the operations needed to authenticate with swift @@ -25,6 +26,11 @@ type Authenticator interface { CdnUrl() string } +// Expireser is an optional interface to read the expiration time of the token +type Expireser interface { + Expires() time.Time +} + type CustomEndpointAuthenticator interface { StorageUrlForEndpoint(endpointType EndpointType) string } @@ -240,6 +246,15 @@ func (auth *v2Auth) Token() string { return auth.Auth.Access.Token.Id } +// v2 Authentication - read expires +func (auth *v2Auth) Expires() time.Time { + t, err := time.Parse(time.RFC3339, auth.Auth.Access.Token.Expires) + if err != nil { + return time.Time{} // return Zero if not parsed + } + return t +} + // v2 Authentication - read cdn url func (auth *v2Auth) CdnUrl() string { return auth.endpointUrl("rax:object-cdn", EndpointTypePublic) diff --git a/vendor/github.com/ncw/swift/auth_v3.go b/vendor/github.com/ncw/swift/auth_v3.go index e8666ebed..1e34ad814 100644 --- a/vendor/github.com/ncw/swift/auth_v3.go +++ b/vendor/github.com/ncw/swift/auth_v3.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strings" + "time" ) const ( @@ -76,9 +77,10 @@ type v3AuthApplicationCredential struct { // V3 Authentication response type v3AuthResponse struct { Token struct { - Expires_At, Issued_At string - Methods []string - Roles []struct { + ExpiresAt string `json:"expires_at"` + IssuedAt string `json:"issued_at"` + Methods []string + Roles []struct { Id, Name string Links struct { Self string @@ -285,6 +287,14 @@ func (auth *v3Auth) Token() string { return auth.Headers.Get("X-Subject-Token") } +func (auth *v3Auth) Expires() time.Time { + t, err := time.Parse(time.RFC3339, auth.Auth.Token.ExpiresAt) + if err != nil { + return time.Time{} // return Zero if not parsed + } + return t +} + func (auth *v3Auth) CdnUrl() string { return "" } diff --git a/vendor/github.com/ncw/swift/meta.go b/vendor/github.com/ncw/swift/meta.go index e52d68608..7e149e139 100644 --- a/vendor/github.com/ncw/swift/meta.go +++ b/vendor/github.com/ncw/swift/meta.go @@ -151,7 +151,7 @@ func TimeToFloatString(t time.Time) string { return nsToFloatString(t.UnixNano()) } -// Read a modification time (mtime) from a Metadata object +// GetModTime reads a modification time (mtime) from a Metadata object // // This is a defacto standard (used in the official python-swiftclient // amongst others) for storing the modification time (as read using @@ -163,7 +163,7 @@ func (m Metadata) GetModTime() (t time.Time, err error) { return FloatStringToTime(m["mtime"]) } -// Write an modification time (mtime) to a Metadata object +// SetModTime writes an modification time (mtime) to a Metadata object // // This is a defacto standard (used in the official python-swiftclient // amongst others) for storing the modification time (as read using diff --git a/vendor/github.com/ncw/swift/swift.go b/vendor/github.com/ncw/swift/swift.go index b81f9e5b9..f197dddea 100644 --- a/vendor/github.com/ncw/swift/swift.go +++ b/vendor/github.com/ncw/swift/swift.go @@ -122,6 +122,7 @@ type Connection struct { // These are filled in after Authenticate is called as are the defaults for above StorageUrl string AuthToken string + Expires time.Time // time the token expires, may be Zero if unknown client *http.Client Auth Authenticator `json:"-" xml:"-"` // the current authenticator authLock sync.Mutex // lock when R/W StorageUrl, AuthToken, Auth @@ -519,6 +520,12 @@ again: c.StorageUrl = c.Auth.StorageUrl(c.Internal) } c.AuthToken = c.Auth.Token() + if do, ok := c.Auth.(Expireser); ok { + c.Expires = do.Expires() + } else { + c.Expires = time.Time{} + } + if !c.authenticated() { err = newError(0, "Response didn't have storage url and auth token") return @@ -580,7 +587,14 @@ func (c *Connection) Authenticated() bool { // // Call with authLock held func (c *Connection) authenticated() bool { - return c.StorageUrl != "" && c.AuthToken != "" + if c.StorageUrl == "" || c.AuthToken == "" { + return false + } + if c.Expires.IsZero() { + return true + } + timeUntilExpiry := c.Expires.Sub(time.Now()) + return timeUntilExpiry >= 60*time.Second } // SwiftInfo contains the JSON object returned by Swift when the /info diff --git a/vendor/modules.txt b/vendor/modules.txt index 636e0a4a8..65f3ce802 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -108,7 +108,7 @@ github.com/kr/fs github.com/mattn/go-runewidth # github.com/ncw/go-acd v0.0.0-20171120105400-887eb06ab6a2 github.com/ncw/go-acd -# github.com/ncw/swift v1.0.44 +# github.com/ncw/swift v1.0.46 github.com/ncw/swift # github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d github.com/nsf/termbox-go