mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
fs: Use connection string config as highest priority config #4996
This commit is contained in:
parent
28f6efe955
commit
e25ac4dcf0
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
25
fs/fs.go
25
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(®InfoValues{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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user