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