main: include credentials and credentials_helper when merging CLI configs
This commit is contained in:
parent
35a058fb3d
commit
fe7ef7ae5d
23
config.go
23
config.go
|
@ -147,5 +147,28 @@ func (c1 *Config) Merge(c2 *Config) *Config {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -92,6 +92,14 @@ func TestConfig_Merge(t *testing.T) {
|
|||
"local": "local",
|
||||
"remote": "bad",
|
||||
},
|
||||
Credentials: map[string]map[string]interface{}{
|
||||
"foo": {
|
||||
"bar": "baz",
|
||||
},
|
||||
},
|
||||
CredentialsHelpers: map[string]*ConfigCredentialsHelper{
|
||||
"buz": {},
|
||||
},
|
||||
}
|
||||
|
||||
c2 := &Config{
|
||||
|
@ -102,6 +110,14 @@ func TestConfig_Merge(t *testing.T) {
|
|||
Provisioners: map[string]string{
|
||||
"remote": "remote",
|
||||
},
|
||||
Credentials: map[string]map[string]interface{}{
|
||||
"fee": {
|
||||
"bur": "bez",
|
||||
},
|
||||
},
|
||||
CredentialsHelpers: map[string]*ConfigCredentialsHelper{
|
||||
"biz": {},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &Config{
|
||||
|
@ -114,6 +130,18 @@ func TestConfig_Merge(t *testing.T) {
|
|||
"local": "local",
|
||||
"remote": "remote",
|
||||
},
|
||||
Credentials: map[string]map[string]interface{}{
|
||||
"foo": {
|
||||
"bar": "baz",
|
||||
},
|
||||
"fee": {
|
||||
"bur": "bez",
|
||||
},
|
||||
},
|
||||
CredentialsHelpers: map[string]*ConfigCredentialsHelper{
|
||||
"buz": {},
|
||||
"biz": {},
|
||||
},
|
||||
}
|
||||
|
||||
actual := c1.Merge(c2)
|
||||
|
|
Loading…
Reference in New Issue