Merge pull request #3686 from hashicorp/skip-unknown
Skips files with unknown extensions when not forcing a format.
This commit is contained in:
commit
8550c07967
|
@ -231,6 +231,17 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
|
||||||
src.Format = FormatFrom(src.Name)
|
src.Format = FormatFrom(src.Name)
|
||||||
if configFormat != "" {
|
if configFormat != "" {
|
||||||
src.Format = configFormat
|
src.Format = configFormat
|
||||||
|
} else {
|
||||||
|
// If they haven't forced things to a specific format,
|
||||||
|
// then skip anything we don't understand, which is the
|
||||||
|
// behavior before we added the -config-format option.
|
||||||
|
switch src.Format {
|
||||||
|
case "json", "hcl":
|
||||||
|
// OK
|
||||||
|
default:
|
||||||
|
// SKIP
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if src.Format == "" {
|
if src.Format == "" {
|
||||||
return RuntimeConfig{}, fmt.Errorf(`config: Missing or invalid file extension for %q. Please use ".json" or ".hcl".`, src.Name)
|
return RuntimeConfig{}, fmt.Errorf(`config: Missing or invalid file extension for %q. Please use ".json" or ".hcl".`, src.Name)
|
||||||
|
|
|
@ -361,6 +361,21 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
|
||||||
rt.DataDir = dataDir
|
rt.DataDir = dataDir
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "-config-format disabled, skip unknown files",
|
||||||
|
args: []string{
|
||||||
|
`-data-dir=` + dataDir,
|
||||||
|
`-config-dir`, filepath.Join(dataDir, "conf"),
|
||||||
|
},
|
||||||
|
patch: func(rt *RuntimeConfig) {
|
||||||
|
rt.Datacenter = "a"
|
||||||
|
rt.DataDir = dataDir
|
||||||
|
},
|
||||||
|
pre: func() {
|
||||||
|
writeFile(filepath.Join(dataDir, "conf", "valid.json"), []byte(`{"datacenter":"a"}`))
|
||||||
|
writeFile(filepath.Join(dataDir, "conf", "invalid.skip"), []byte(`NOPE`))
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "-config-format=json",
|
desc: "-config-format=json",
|
||||||
args: []string{
|
args: []string{
|
||||||
|
|
Loading…
Reference in New Issue