Skip to content

--Config-file is loaded as a path, not a direct file when calling Viper - leading to implicit (undocumented) file prioritization of config files in the same path #2573

@Chickenhen

Description

@Chickenhen

When providing the --config-file switch to Cloud-SQL-Proxy; users can provide TOML, JSON, YAML extensions.
Expectation is specific file is chosen when provided on the command line.

When loading the file via VIPER; the extension is removed from the lookup; and only the filename used.

If users have multiple files with same name; but different extension in same directory - the file loaded will be based on internal viper prioritization; not the file listed by the user

cloud-sql-proxy/cmd/root.go

Lines 690 to 692 in 88a85ce

// argument must be the name of config file without extension
v.SetConfigName(noExt)
v.AddConfigPath(filepath.Dir(c.conf.Filepath))

precedence is defined by order of declaration

https://github.com/spf13/viper/blob/528f7416c4b56a4948673984b190bf8713f0c3c4/viper.go#L268

Options to resolve either

  • change documentation to indicate the file load preference
  • load exact file specified by user and error if not available - v.SetConfigFile(c.conf.Filepath)
  • raise a warning \ exception if multiple files within the path specified by user could be loaded

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions