fs: stop writing config for on the fly and environment variable remotes into the config file
When a backend saved config, for example a refreshed OAuth token, for a remote which wasn't in the config file, a section with just that value was created in the config file for environment variable remotes and the config file was rewritten for on the fly remotes. Config is now only saved if the remote is in the config file.
This commit is contained in:
1 parent
d597972297
commit
6a0f081380
2 files changed
+27
No files matched your search
@@ -83,7 +83,15 @@ func (r *regInfoValues) Get(key string) (value string, ok bool) {
|
||||
type setConfigFile string
|
||||
|
||||
// Set a config item into the config file
|
||||
//
|
||||
// The item is only saved if the remote is defined in the config file,
|
||||
// so remotes defined on the fly or with environment variables aren't
|
||||
// written to it.
|
||||
func (section setConfigFile) Set(key, value string) {
|
||||
if !ConfigFileHasSection(string(section)) {
|
||||
Debugf(nil, "Not saving config %q as section %q is not in the config file", key, section)
|
||||
return
|
||||
}
|
||||
Debugf(nil, "Saving config %q in section %q of the config file", key, section)
|
||||
err := ConfigFileSet(string(section), key, value)
|
||||
if err != nil {
|
||||
|
||||
@@ -91,3 +91,22 @@ func TestOptionEnvVarsRedactsPassword(t *testing.T) {
|
||||
assert.Equal(t, "obscured_pass", value)
|
||||
assert.NotContains(t, buf.String(), "obscured_pass")
|
||||
}
|
||||
|
||||
// TestSetConfigFileOnlyExistingSection checks that config is only
|
||||
// saved to sections which exist in the config file.
|
||||
func TestSetConfigFileOnlyExistingSection(t *testing.T) {
|
||||
oldHasSection, oldSet := ConfigFileHasSection, ConfigFileSet
|
||||
t.Cleanup(func() { ConfigFileHasSection, ConfigFileSet = oldHasSection, oldSet })
|
||||
ConfigFileHasSection = func(section string) bool { return section == "remote" }
|
||||
saved := map[string]string{}
|
||||
ConfigFileSet = func(section, key, value string) error {
|
||||
saved[section+"."+key] = value
|
||||
return nil
|
||||
}
|
||||
|
||||
setConfigFile("remote").Set("key", "value")
|
||||
setConfigFile(":backend").Set("key", "value")
|
||||
setConfigFile("envremote").Set("key", "value")
|
||||
|
||||
assert.Equal(t, map[string]string{"remote.key": "value"}, saved)
|
||||
}
|
||||
Reference in new issue
Block a user