swift: Allow authentication with storage url and auth key
Adding the option to load the storage url and the auth key from the environment when you have an alternate authorization, external to rclone, and you need to use it (e.g. because it's not yet supported by the swift go library) Allowing to get alternate authentication from config file, and using proper way (c.Authenticated()) to know if it's authenticated. Updated docs as well
This commit is contained in:
parent
25b073c767
commit
f12512dd13
2 changed files with 92 additions and 62 deletions
|
@ -96,6 +96,9 @@ func init() {
|
|||
}, {
|
||||
Name: "storage_url",
|
||||
Help: "Storage URL - optional (OS_STORAGE_URL)",
|
||||
}, {
|
||||
Name: "auth_token",
|
||||
Help: "Auth Token from alternate authentication - optional (OS_AUTH_TOKEN)",
|
||||
}, {
|
||||
Name: "auth_version",
|
||||
Help: "AuthVersion - optional - set to (1,2,3) if your auth URL has no version (ST_AUTH_VERSION)",
|
||||
|
@ -197,7 +200,10 @@ func swiftConnection(name string) (*swift.Connection, error) {
|
|||
TenantId: fs.ConfigFileGet(name, "tenant_id"),
|
||||
TenantDomain: fs.ConfigFileGet(name, "tenant_domain"),
|
||||
Region: fs.ConfigFileGet(name, "region"),
|
||||
// StorageUrl is set below
|
||||
// I get the StorageUrl already here, in case the user wants to set it manually
|
||||
// (e.g. when using alternate authentication)
|
||||
StorageUrl: fs.ConfigFileGet(name, "storage_url"),
|
||||
AuthToken: fs.ConfigFileGet(name, "auth_token"),
|
||||
AuthVersion: fs.ConfigFileGetInt(name, "auth_version", 0),
|
||||
EndpointType: swift.EndpointType(fs.ConfigFileGet(name, "endpoint_type", "public")),
|
||||
ConnectTimeout: 10 * fs.Config.ConnectTimeout, // Use the timeouts in the transport
|
||||
|
@ -210,18 +216,20 @@ func swiftConnection(name string) (*swift.Connection, error) {
|
|||
return nil, errors.Wrap(err, "failed to read environment variables")
|
||||
}
|
||||
}
|
||||
if c.UserName == "" && c.UserId == "" {
|
||||
return nil, errors.New("user name or user id not found")
|
||||
}
|
||||
if c.ApiKey == "" {
|
||||
return nil, errors.New("key not found")
|
||||
}
|
||||
if c.AuthUrl == "" {
|
||||
return nil, errors.New("auth not found")
|
||||
}
|
||||
err := c.Authenticate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if !c.Authenticated() {
|
||||
if c.UserName == "" && c.UserId == "" {
|
||||
return nil, errors.New("user name or user id not found for authentication (and no storage_url+auth_token is provided)")
|
||||
}
|
||||
if c.ApiKey == "" {
|
||||
return nil, errors.New("key not found")
|
||||
}
|
||||
if c.AuthUrl == "" {
|
||||
return nil, errors.New("auth not found")
|
||||
}
|
||||
err := c.Authenticate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue