config: fix in memory config not saving on the fly backend config

Before this fix, saving a :backend config gave the error

    Can't save config "token" = "XXX" for on the fly backend ":backend"

Even when using the in-memory config `--config ""`

This fixes the problem by
- always using the in memory config if it is configured
- moving the check for a :backend config save to the file config backend

It also removes the contents of the config items being saved from the
log which saves confidential tokens being logged.

Fixes #5451
This commit is contained in:
Nick Craig-Wood 2021-07-13 17:41:28 +01:00
parent da36ce08e4
commit 770b3496a1
3 changed files with 11 additions and 11 deletions

View File

@ -332,6 +332,10 @@ func SetConfigPath(path string) (err error) {
// SetData sets new config file storage
func SetData(newData Storage) {
// If no config file, use in-memory config (which is the default)
if configPath == "" {
return
}
data = newData
dataLoaded = false
}
@ -371,10 +375,6 @@ var ErrorConfigFileNotFound = errors.New("config file not found")
// SaveConfig calling function which saves configuration file.
// if SaveConfig returns error trying again after sleep.
func SaveConfig() {
if configPath == "" {
fs.Debugf(nil, "Skipping save for memory-only config")
return
}
ctx := context.Background()
ci := fs.GetConfig(ctx)
var err error

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"github.com/Unknwon/goconfig"
@ -224,6 +225,10 @@ func (s *Storage) GetValue(section string, key string) (value string, found bool
// SetValue sets the value under key in section
func (s *Storage) SetValue(section string, key string, value string) {
s.check()
if strings.HasPrefix(section, ":") {
fs.Logf(nil, "Can't save config %q for on the fly backend %q", key, section)
return
}
s.gc.SetValue(section, key, value)
}

View File

@ -4,7 +4,6 @@ package fs
import (
"os"
"strings"
"github.com/rclone/rclone/fs/config/configmap"
)
@ -70,14 +69,10 @@ type setConfigFile string
// Set a config item into the config file
func (section setConfigFile) Set(key, value string) {
if strings.HasPrefix(string(section), ":") {
Logf(nil, "Can't save config %q = %q for on the fly backend %q", key, value, section)
return
}
Debugf(nil, "Saving config %q = %q in section %q of the config file", key, value, section)
Debugf(nil, "Saving config %q in section %q of the config file", key, section)
err := ConfigFileSet(string(section), key, value)
if err != nil {
Errorf(nil, "Failed saving config %q = %q in section %q of the config file: %v", key, value, section, err)
Errorf(nil, "Failed saving config %q in section %q of the config file: %v", key, section, err)
}
}