Swift storageUrl overloading fixes #167
This commit is contained in:
parent
08a8f7174a
commit
c2e8f06bfa
3 changed files with 42 additions and 0 deletions
|
@ -56,6 +56,8 @@ Choose a number from below, or type in your own value
|
||||||
auth> 1
|
auth> 1
|
||||||
Tenant name - optional
|
Tenant name - optional
|
||||||
tenant>
|
tenant>
|
||||||
|
Storage URL - optional
|
||||||
|
storage_url>
|
||||||
Remote config
|
Remote config
|
||||||
--------------------
|
--------------------
|
||||||
[remote]
|
[remote]
|
||||||
|
@ -63,6 +65,7 @@ user = user_name
|
||||||
key = password_or_api_key
|
key = password_or_api_key
|
||||||
auth = https://auth.api.rackspacecloud.com/v1.0
|
auth = https://auth.api.rackspacecloud.com/v1.0
|
||||||
tenant =
|
tenant =
|
||||||
|
storage_url =
|
||||||
--------------------
|
--------------------
|
||||||
y) Yes this is OK
|
y) Yes this is OK
|
||||||
e) Edit this remote
|
e) Edit this remote
|
||||||
|
|
30
swift/auth.go
Normal file
30
swift/auth.go
Normal file
|
@ -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)
|
|
@ -66,6 +66,9 @@ func init() {
|
||||||
}, {
|
}, {
|
||||||
Name: "region",
|
Name: "region",
|
||||||
Help: "Region name - optional",
|
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",
|
segmentsContainer: container + "_segments",
|
||||||
root: directory,
|
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 != "" {
|
if f.root != "" {
|
||||||
f.root += "/"
|
f.root += "/"
|
||||||
// Check to see if the object exists - ignoring directory markers
|
// Check to see if the object exists - ignoring directory markers
|
||||||
|
|
Loading…
Reference in a new issue