mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 00:43:49 +01:00
swift: work around token expiry on CEPH
This implements the Expiry interface so token expiry works properly This change makes sure that this change from the swift library works correctly with rclone's custom authenticator. > Renew the token 60s before the expiry time > > The v2 and v3 auth schemes both return the expiry time of the token, > so instead of waiting for a 401 error, renew the token 60s before this > time. > > This makes transfers more efficient and also works around a bug in > CEPH which returns 403 instead of 401 when the token expires. > > http://tracker.ceph.com/issues/22223
This commit is contained in:
parent
595fea757d
commit
6e70d88f54
@ -2,6 +2,7 @@ package swift
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/ncw/swift"
|
||||
)
|
||||
@ -65,6 +66,14 @@ func (a *auth) Token() string {
|
||||
return a.parentAuth.Token()
|
||||
}
|
||||
|
||||
// Expires returns the time the token expires if known or Zero if not.
|
||||
func (a *auth) Expires() (t time.Time) {
|
||||
if do, ok := a.parentAuth.(swift.Expireser); ok {
|
||||
t = do.Expires()
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// The CDN url if available
|
||||
func (a *auth) CdnUrl() string { // nolint
|
||||
if a.parentAuth == nil {
|
||||
@ -74,4 +83,7 @@ func (a *auth) CdnUrl() string { // nolint
|
||||
}
|
||||
|
||||
// Check the interfaces are satisfied
|
||||
var _ swift.Authenticator = (*auth)(nil)
|
||||
var (
|
||||
_ swift.Authenticator = (*auth)(nil)
|
||||
_ swift.Expireser = (*auth)(nil)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user