main: include credentials and credentials_helper when merging CLI configs

This commit is contained in:
Martin Atkins 2017-10-19 16:41:03 -07:00
parent 35a058fb3d
commit fe7ef7ae5d
2 changed files with 51 additions and 0 deletions

View File

@ -147,5 +147,28 @@ func (c1 *Config) Merge(c2 *Config) *Config {
result.PluginCacheDir = c2.PluginCacheDir result.PluginCacheDir = c2.PluginCacheDir
} }
if (len(c1.Credentials) + len(c2.Credentials)) > 0 {
result.Credentials = make(map[string]map[string]interface{})
for host, creds := range c1.Credentials {
result.Credentials[host] = creds
}
for host, creds := range c2.Credentials {
// We just clobber an entry from the other file right now. Will
// improve on this later using the more-robust merging behavior
// built in to HCL2.
result.Credentials[host] = creds
}
}
if (len(c1.CredentialsHelpers) + len(c2.CredentialsHelpers)) > 0 {
result.CredentialsHelpers = make(map[string]*ConfigCredentialsHelper)
for name, helper := range c1.CredentialsHelpers {
result.CredentialsHelpers[name] = helper
}
for name, helper := range c2.CredentialsHelpers {
result.CredentialsHelpers[name] = helper
}
}
return &result return &result
} }

View File

@ -92,6 +92,14 @@ func TestConfig_Merge(t *testing.T) {
"local": "local", "local": "local",
"remote": "bad", "remote": "bad",
}, },
Credentials: map[string]map[string]interface{}{
"foo": {
"bar": "baz",
},
},
CredentialsHelpers: map[string]*ConfigCredentialsHelper{
"buz": {},
},
} }
c2 := &Config{ c2 := &Config{
@ -102,6 +110,14 @@ func TestConfig_Merge(t *testing.T) {
Provisioners: map[string]string{ Provisioners: map[string]string{
"remote": "remote", "remote": "remote",
}, },
Credentials: map[string]map[string]interface{}{
"fee": {
"bur": "bez",
},
},
CredentialsHelpers: map[string]*ConfigCredentialsHelper{
"biz": {},
},
} }
expected := &Config{ expected := &Config{
@ -114,6 +130,18 @@ func TestConfig_Merge(t *testing.T) {
"local": "local", "local": "local",
"remote": "remote", "remote": "remote",
}, },
Credentials: map[string]map[string]interface{}{
"foo": {
"bar": "baz",
},
"fee": {
"bur": "bez",
},
},
CredentialsHelpers: map[string]*ConfigCredentialsHelper{
"buz": {},
"biz": {},
},
} }
actual := c1.Merge(c2) actual := c1.Merge(c2)