From 6c5f9b2764784f7c3e4c99175fb1105ce1769486 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 1 Dec 2023 15:42:50 +0300 Subject: [PATCH] [#266] Fix namespace config initialization Don't use nil Namespaces map in case when file isn't provided or invalid Signed-off-by: Denis Kirillov --- cmd/s3-gw/app_settings.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/s3-gw/app_settings.go b/cmd/s3-gw/app_settings.go index fe473764..5d36f945 100644 --- a/cmd/s3-gw/app_settings.go +++ b/cmd/s3-gw/app_settings.go @@ -487,7 +487,7 @@ func fetchNamespacesConfig(l *zap.Logger, v *viper.Viper) NamespacesConfig { nsConfig, err := readNamespacesConfig(v.GetString(cfgNamespacesConfig)) if err != nil { - l.Warn(logs.FailedToParseNamespacesConfig) + l.Warn(logs.FailedToParseNamespacesConfig, zap.Error(err)) } defaultNamespacesNames := fetchDefaultNamespaces(l, v) @@ -521,18 +521,21 @@ func fetchNamespacesConfig(l *zap.Logger, v *viper.Viper) NamespacesConfig { } func readNamespacesConfig(filepath string) (NamespacesConfig, error) { + nsConfig := NamespacesConfig{ + Namespaces: make(Namespaces), + } + if filepath == "" { - return NamespacesConfig{}, nil + return nsConfig, nil } data, err := os.ReadFile(filepath) if err != nil { - return NamespacesConfig{}, fmt.Errorf("failed to read namespace config '%s': %w", filepath, err) + return nsConfig, fmt.Errorf("failed to read namespace config '%s': %w", filepath, err) } - var nsConfig NamespacesConfig if err = json.Unmarshal(data, &nsConfig); err != nil { - return NamespacesConfig{}, fmt.Errorf("failed to parse namespace config: %w", err) + return nsConfig, fmt.Errorf("failed to parse namespace config: %w", err) } return nsConfig, nil