github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/backend/hubic/auth.go (about) 1 package hubic 2 3 import ( 4 "net/http" 5 "time" 6 7 "github.com/ncw/rclone/fs" 8 "github.com/ncw/swift" 9 ) 10 11 // auth is an authenticator for swift 12 type auth struct { 13 f *Fs 14 } 15 16 // newAuth creates a swift authenticator 17 func newAuth(f *Fs) *auth { 18 return &auth{ 19 f: f, 20 } 21 } 22 23 // Request constructs a http.Request for authentication 24 // 25 // returns nil for not needed 26 func (a *auth) Request(*swift.Connection) (r *http.Request, err error) { 27 const retries = 10 28 for try := 1; try <= retries; try++ { 29 err = a.f.getCredentials() 30 if err == nil { 31 break 32 } 33 time.Sleep(100 * time.Millisecond) 34 fs.Debugf(a.f, "retrying auth request %d/%d: %v", try, retries, err) 35 } 36 return nil, err 37 } 38 39 // Response parses the result of an http request 40 func (a *auth) Response(resp *http.Response) error { 41 return nil 42 } 43 44 // The public storage URL - set Internal to true to read 45 // internal/service net URL 46 func (a *auth) StorageUrl(Internal bool) string { // nolint 47 return a.f.credentials.Endpoint 48 } 49 50 // The access token 51 func (a *auth) Token() string { 52 return a.f.credentials.Token 53 } 54 55 // The CDN url if available 56 func (a *auth) CdnUrl() string { // nolint 57 return "" 58 } 59 60 // Check the interfaces are satisfied 61 var _ swift.Authenticator = (*auth)(nil)