Skip to content

Commit ea3dec9

Browse files
authored
Parse app config strictly by default (#3629)
1 parent 1da768a commit ea3dec9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

private/pkg/app/appext/appext.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ func BuilderWithLoggerProvider(loggerProvider LoggerProvider) BuilderOption {
161161
// If the file does not exist, this is a no-op.
162162
// The value should be a pointer to unmarshal into.
163163
func ReadConfig(container NameContainer, value interface{}) error {
164+
configFilePath := filepath.Join(container.ConfigDirPath(), configFileName)
165+
data, err := os.ReadFile(configFilePath)
166+
if !errors.Is(err, os.ErrNotExist) {
167+
if err != nil {
168+
return fmt.Errorf("could not read %s configuration file at %s: %w", container.AppName(), configFilePath, err)
169+
}
170+
if err := encoding.UnmarshalYAMLStrict(data, value); err != nil {
171+
return fmt.Errorf("invalid %s configuration file: %w", container.AppName(), err)
172+
}
173+
}
174+
return nil
175+
}
176+
177+
// ReadConfigNonStrict reads the configuration from the YAML configuration file config.yaml
178+
// in the configuration directory, ignoring any unknown properties.
179+
//
180+
// If the file does not exist, this is a no-op.
181+
// The value should be a pointer to unmarshal into.
182+
func ReadConfigNonStrict(container NameContainer, value interface{}) error {
164183
configFilePath := filepath.Join(container.ConfigDirPath(), configFileName)
165184
data, err := os.ReadFile(configFilePath)
166185
if !errors.Is(err, os.ErrNotExist) {

0 commit comments

Comments
 (0)