From 0b053c4a979011075023fbad10a90c48231d5e0b Mon Sep 17 00:00:00 2001 From: Saquib Mian Date: Tue, 11 Feb 2025 11:53:31 -0500 Subject: [PATCH 1/2] Parse app config strictly In #3376 we switched `UnmarshalYAMLStrict` to `UnmarshalYAMLNonStrict`. I'm not entirely sure if this was intentional, but we want this to be strict by default. Happy to discuss if the CLI needs non-strict anywhere and if so if we can make this configurable. --- private/pkg/app/appext/appext.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/pkg/app/appext/appext.go b/private/pkg/app/appext/appext.go index 88e70574c4..05eddb0894 100644 --- a/private/pkg/app/appext/appext.go +++ b/private/pkg/app/appext/appext.go @@ -167,7 +167,7 @@ func ReadConfig(container NameContainer, value interface{}) error { if err != nil { return fmt.Errorf("could not read %s configuration file at %s: %w", container.AppName(), configFilePath, err) } - if err := encoding.UnmarshalYAMLNonStrict(data, value); err != nil { + if err := encoding.UnmarshalYAMLStrict(data, value); err != nil { return fmt.Errorf("invalid %s configuration file: %w", container.AppName(), err) } } From 7b33c228f52735ba4efc1b2e91529756b861a7f5 Mon Sep 17 00:00:00 2001 From: Saquib Mian Date: Wed, 12 Feb 2025 11:15:27 -0500 Subject: [PATCH 2/2] Add `ReadConfigNonStrict` as well --- private/pkg/app/appext/appext.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/private/pkg/app/appext/appext.go b/private/pkg/app/appext/appext.go index 05eddb0894..bfb35c59c8 100644 --- a/private/pkg/app/appext/appext.go +++ b/private/pkg/app/appext/appext.go @@ -174,6 +174,25 @@ func ReadConfig(container NameContainer, value interface{}) error { return nil } +// ReadConfigNonStrict reads the configuration from the YAML configuration file config.yaml +// in the configuration directory, ignoring any unknown properties. +// +// If the file does not exist, this is a no-op. +// The value should be a pointer to unmarshal into. +func ReadConfigNonStrict(container NameContainer, value interface{}) error { + configFilePath := filepath.Join(container.ConfigDirPath(), configFileName) + data, err := os.ReadFile(configFilePath) + if !errors.Is(err, os.ErrNotExist) { + if err != nil { + return fmt.Errorf("could not read %s configuration file at %s: %w", container.AppName(), configFilePath, err) + } + if err := encoding.UnmarshalYAMLNonStrict(data, value); err != nil { + return fmt.Errorf("invalid %s configuration file: %w", container.AppName(), err) + } + } + return nil +} + // ReadSecret returns the contents of the file at path // filepath.Join(container.ConfigDirPath(), secretRelDirPath, name). func ReadSecret(container NameContainer, name string) (string, error) {