mirror of
https://github.com/rclone/rclone.git
synced 2025-08-09 13:55:15 +02:00
swift: fix crash on bad authentication - fixes #1919
This also fixes Hubic not re-authenticating for long transfers.
This commit is contained in:
@ -1,29 +1,76 @@
|
||||
package swift
|
||||
|
||||
import "github.com/ncw/swift"
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
// auth is an authenticator for swift
|
||||
"github.com/ncw/swift"
|
||||
)
|
||||
|
||||
// auth is an authenticator for swift. It overrides the StorageUrl
|
||||
// and AuthToken with fixed values.
|
||||
type auth struct {
|
||||
swift.Authenticator
|
||||
parentAuth swift.Authenticator
|
||||
storageURL string
|
||||
authToken string
|
||||
}
|
||||
|
||||
// newAuth creates a swift authenticator wrapper to override the
|
||||
// StorageUrl method.
|
||||
func newAuth(Authenticator swift.Authenticator, storageURL string) *auth {
|
||||
// StorageUrl and AuthToken values.
|
||||
//
|
||||
// Note that parentAuth can be nil
|
||||
func newAuth(parentAuth swift.Authenticator, storageURL string, authToken string) *auth {
|
||||
return &auth{
|
||||
Authenticator: Authenticator,
|
||||
storageURL: storageURL,
|
||||
parentAuth: parentAuth,
|
||||
storageURL: storageURL,
|
||||
authToken: authToken,
|
||||
}
|
||||
}
|
||||
|
||||
// Request creates an http.Request for the auth - return nil if not needed
|
||||
func (a *auth) Request(c *swift.Connection) (*http.Request, error) {
|
||||
if a.parentAuth == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return a.parentAuth.Request(c)
|
||||
}
|
||||
|
||||
// Response parses the http.Response
|
||||
func (a *auth) Response(resp *http.Response) error {
|
||||
if a.parentAuth == nil {
|
||||
return nil
|
||||
}
|
||||
return a.parentAuth.Response(resp)
|
||||
}
|
||||
|
||||
// The public storage URL - set Internal to true to read
|
||||
// internal/service net URL
|
||||
func (a *auth) StorageUrl(Internal bool) string {
|
||||
if a.storageURL != "" {
|
||||
return a.storageURL
|
||||
}
|
||||
return a.Authenticator.StorageUrl(Internal)
|
||||
if a.parentAuth == nil {
|
||||
return ""
|
||||
}
|
||||
return a.parentAuth.StorageUrl(Internal)
|
||||
}
|
||||
|
||||
// The access token
|
||||
func (a *auth) Token() string {
|
||||
if a.authToken != "" {
|
||||
return a.authToken
|
||||
}
|
||||
if a.parentAuth == nil {
|
||||
return ""
|
||||
}
|
||||
return a.parentAuth.Token()
|
||||
}
|
||||
|
||||
// The CDN url if available
|
||||
func (a *auth) CdnUrl() string {
|
||||
if a.parentAuth == nil {
|
||||
return ""
|
||||
}
|
||||
return a.parentAuth.CdnUrl()
|
||||
}
|
||||
|
||||
// Check the interfaces are satisfied
|
||||
|
Reference in New Issue
Block a user