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

fs: Use connection string config as highest priority config #4996

Nick Craig-Woode25ac4dcf077
diff --git a/fs/config/authorize.go b/fs/config/authorize.go
index 0ef0b926a..dbdcccefa 100644
--- a/fs/config/authorize.go
+++ b/fs/config/authorize.go
@@ -42,7 +42,7 @@ func Authorize(ctx context.Context, args []string, noAutoBrowser bool) error {
Data.SetValue(name, ConfigClientSecret, args[2])
}
- m := fs.ConfigMap(f, name)
+ m := fs.ConfigMap(f, name, nil)
f.Config(ctx, name, m)
return nil
}
diff --git a/fs/config/ui.go b/fs/config/ui.go
index 595b99492..bbbd75a08 100644
--- a/fs/config/ui.go
+++ b/fs/config/ui.go
@@ -274,7 +274,7 @@ func RemoteConfig(ctx context.Context, name string) {
fmt.Printf("Remote config\n")
f := mustFindByName(name)
if f.Config != nil {
- m := fs.ConfigMap(f, name)
+ m := fs.ConfigMap(f, name, nil)
f.Config(ctx, name, m)
}
}
diff --git a/fs/fs.go b/fs/fs.go
index 18f5e27be..92425c416 100644
--- a/fs/fs.go
+++ b/fs/fs.go
@@ -1205,23 +1205,22 @@ func MustFind(name string) *RegInfo {
// ParseRemote deconstructs a path into configName, fsPath, looking up
// the fsName in the config file (returning NotFoundInConfigFile if not found)
-func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err error) {
+func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, connectionStringConfig configmap.Simple, err error) {
parsed, err := fspath.Parse(path)
if err != nil {
- return nil, "", "", err
+ return nil, "", "", nil, err
}
configName, fsPath = parsed.Name, parsed.Path
- // FIXME do something with parsed.Config
var fsName string
var ok bool
if configName != "" {
if strings.HasPrefix(configName, ":") {
fsName = configName[1:]
} else {
- m := ConfigMap(nil, configName)
+ m := ConfigMap(nil, configName, parsed.Config)
fsName, ok = m.Get("type")
if !ok {
- return nil, "", "", ErrorNotFoundInConfigFile
+ return nil, "", "", nil, ErrorNotFoundInConfigFile
}
}
} else {
@@ -1229,7 +1228,7 @@ func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err e
configName = "local"
}
fsInfo, err = Find(fsName)
- return fsInfo, configName, fsPath, err
+ return fsInfo, configName, fsPath, parsed.Config, err
}
// A configmap.Getter to read from the environment RCLONE_CONFIG_backend_option_name
@@ -1304,16 +1303,22 @@ func (section getConfigFile) Get(key string) (value string, ok bool) {
}
// ConfigMap creates a configmap.Map from the *RegInfo and the
-// configName passed in.
+// configName passed in. If connectionStringConfig has any entries (it may be nil),
+// then it will be added to the lookup with the highest priority.
//
// If fsInfo is nil then the returned configmap.Map should only be
// used for reading non backend specific parameters, such as "type".
-func ConfigMap(fsInfo *RegInfo, configName string) (config *configmap.Map) {
+func ConfigMap(fsInfo *RegInfo, configName string, connectionStringConfig configmap.Simple) (config *configmap.Map) {
// Create the config
config = configmap.New()
// Read the config, more specific to least specific
+ // Config from connection string
+ if len(connectionStringConfig) > 0 {
+ config.AddGetter(connectionStringConfig)
+ }
+
// flag values
if fsInfo != nil {
config.AddGetter(&regInfoValues{fsInfo, false})
@@ -1348,11 +1353,11 @@ func ConfigMap(fsInfo *RegInfo, configName string) (config *configmap.Map) {
// found then NotFoundInConfigFile will be returned.
func ConfigFs(path string) (fsInfo *RegInfo, configName, fsPath string, config *configmap.Map, err error) {
// Parse the remote path
- fsInfo, configName, fsPath, err = ParseRemote(path)
+ fsInfo, configName, fsPath, connectionStringConfig, err := ParseRemote(path)
if err != nil {
return
}
- config = ConfigMap(fsInfo, configName)
+ config = ConfigMap(fsInfo, configName, connectionStringConfig)
return
}