vendor: update github.com/ncw/swift to bring in Expires changes

s3-about
Nick Craig-Wood 2019-03-18 10:36:54 +00:00
parent bb80586473
commit 595fea757d
9 changed files with 55 additions and 13 deletions

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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:

View File

@ -153,3 +153,4 @@ Contributors
- Omar Ali <omarali@users.noreply.github.com>
- Andreas Andersen <andreas@softwaredesign.se>
- kayrus <kay.diam@gmail.com>
- CodeLingo Bot <bot@codelingo.io>

15
vendor/github.com/ncw/swift/auth.go generated vendored
View File

@ -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)

View File

@ -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 ""
}

View File

@ -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

16
vendor/github.com/ncw/swift/swift.go generated vendored
View File

@ -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

2
vendor/modules.txt vendored
View File

@ -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