1
0
mirror of https://github.com/rclone/rclone.git synced 2025-06-14 22:15:26 +02:00
Files
.github
backend
alias
all
amazonclouddrive
azureblob
b2
box
cache
chunker
combine
compress
crypt
drive
dropbox
fichier
filefabric
ftp
googlecloudstorage
googlephotos
hasher
hdfs
hidrive
http
internetarchive
jottacloud
koofr
local
mailru
mega
memory
netstorage
onedrive
opendrive
oracleobjectstorage
pcloud
premiumizeme
putio
qingstor
s3
seafile
sftp
sharefile
sia
smb
storj
sugarsync
swift
auth.go
swift.go
swift_internal_test.go
swift_test.go
union
uptobox
webdav
yandex
zoho
bin
cmd
cmdtest
contrib
docs
fs
fstest
graphics
lib
librclone
vfs
.gitattributes
.gitignore
.golangci.yml
CONTRIBUTING.md
COPYING
Dockerfile
MAINTAINERS.md
MANUAL.html
MANUAL.md
MANUAL.txt
Makefile
README.md
RELEASE.md
VERSION
go.mod
go.sum
notes.txt
rclone.1
rclone.go
rclone/backend/swift/auth.go

91 lines
1.9 KiB
Go
Raw Normal View History

package swift
import (
"context"
"net/http"
"time"
"github.com/ncw/swift/v2"
)
// 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(ctx context.Context, c *swift.Connection) (*http.Request, error) {
if a.parentAuth == nil {
return nil, nil
}
return a.parentAuth.Request(ctx, c)
}
// Response parses the http.Response
func (a *auth) Response(ctx context.Context, resp *http.Response) error {
if a.parentAuth == nil {
return nil
}
return a.parentAuth.Response(ctx, resp)
}
// The public storage URL - set Internal to true to read
// internal/service net URL
2018-05-05 11:49:03 +01:00
func (a *auth) StorageUrl(Internal bool) string { // nolint
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()
}
// 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
2018-05-05 11:49:03 +01:00
func (a *auth) CdnUrl() string { // nolint
if a.parentAuth == nil {
return ""
}
return a.parentAuth.CdnUrl()
}
// Check the interfaces are satisfied
var (
_ swift.Authenticator = (*auth)(nil)
_ swift.Expireser = (*auth)(nil)
)