Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Swift storageUrl overloading fixes #167

Xavier Lucasc2e8f06bfaf2
diff --git a/docs/content/swift.md b/docs/content/swift.md
index ecbce831c..3b7d21ed6 100644
--- a/docs/content/swift.md
+++ b/docs/content/swift.md
@@ -56,6 +56,8 @@ Choose a number from below, or type in your own value
auth> 1
Tenant name - optional
tenant>
+Storage URL - optional
+storage_url>
Remote config
--------------------
[remote]
@@ -63,6 +65,7 @@ user = user_name
key = password_or_api_key
auth = https://auth.api.rackspacecloud.com/v1.0
tenant =
+storage_url =
--------------------
y) Yes this is OK
e) Edit this remote
diff --git a/swift/auth.go b/swift/auth.go
new file mode 100644
index 000000000..1eecdbce6
--- /dev/null
+++ b/swift/auth.go
@@ -0,0 +1,30 @@
+package swift
+
+import "github.com/ncw/swift"
+
+// auth is an authenticator for swift
+type auth struct {
+ swift.Authenticator
+ storageURL string
+}
+
+// newAuth creates a swift authenticator wrapper to override the
+// StorageUrl method.
+func newAuth(Authenticator swift.Authenticator, storageURL string) *auth {
+ return &auth{
+ Authenticator: Authenticator,
+ storageURL: storageURL,
+ }
+}
+
+// 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)
+}
+
+// Check the interfaces are satisfied
+var _ swift.Authenticator = (*auth)(nil)
diff --git a/swift/swift.go b/swift/swift.go
index 3c6dbbaf3..89d803a83 100644
--- a/swift/swift.go
+++ b/swift/swift.go
@@ -66,6 +66,9 @@ func init() {
}, {
Name: "region",
Help: "Region name - optional",
+ }, {
+ Name: "storage_url",
+ Help: "Storage URL - optional",
},
},
})
@@ -176,6 +179,12 @@ func NewFsWithConnection(name, root string, c *swift.Connection) (fs.Fs, error)
segmentsContainer: container + "_segments",
root: directory,
}
+ // StorageURL overloading
+ storageURL := fs.ConfigFile.MustValue(name, "storage_url")
+ if storageURL != "" {
+ f.c.StorageUrl = storageURL
+ f.c.Auth = newAuth(f.c.Auth, storageURL)
+ }
if f.root != "" {
f.root += "/"
// Check to see if the object exists - ignoring directory markers