mirror of
https://github.com/rclone/rclone
synced 2025-07-29 02:10:46 +02:00
.circleci
backend
alias
all
amazonclouddrive
azureblob
b2
box
cache
crypt
drive
dropbox
ftp
googlecloudstorage
http
hubic
local
onedrive
pcloud
qingstor
s3
sftp
swift
auth.go
swift.go
swift_internal_test.go
swift_test.go
webdav
yandex
bin
cmd
docs
fs
fstest
graphics
lib
vendor
vfs
.appveyor.yml
.gitignore
.pkgr.yml
.travis.yml
CONTRIBUTING.md
COPYING
Gopkg.lock
Gopkg.toml
ISSUE_TEMPLATE.md
MAINTAINERS.md
MANUAL.html
MANUAL.md
MANUAL.txt
Makefile
README.md
RELEASE.md
notes.txt
rclone.1
rclone.go
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package swift
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/ncw/swift"
|
|
)
|
|
|
|
// auth is an authenticator for swift. It overrides the StorageUrl
|
|
// and AuthToken with fixed values.
|
|
type auth struct {
|
|
parentAuth swift.Authenticator
|
|
storageURL string
|
|
authToken string
|
|
}
|
|
|
|
// newAuth creates a swift authenticator wrapper to override the
|
|
// StorageUrl and AuthToken values.
|
|
//
|
|
// Note that parentAuth can be nil
|
|
func newAuth(parentAuth swift.Authenticator, storageURL string, authToken string) *auth {
|
|
return &auth{
|
|
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
|
|
}
|
|
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
|
|
var _ swift.Authenticator = (*auth)(nil)
|