From da77e426b66a60ef0f90fec0422fdd45cad63e87 Mon Sep 17 00:00:00 2001 From: Marina Biryukova Date: Fri, 24 Jan 2025 12:21:24 +0300 Subject: [PATCH] [#541] Fix setting of tls.enabled flag Signed-off-by: Marina Biryukova --- cmd/s3-gw/app_settings.go | 6 +++++- cmd/s3-gw/app_settings_test.go | 9 +++++++++ docs/configuration.md | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/s3-gw/app_settings.go b/cmd/s3-gw/app_settings.go index 8ef38089..a3c225e9 100644 --- a/cmd/s3-gw/app_settings.go +++ b/cmd/s3-gw/app_settings.go @@ -931,13 +931,17 @@ func newViper(flags *pflag.FlagSet) (*viper.Viper, error) { v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) v.AllowEmptyEnv(true) + if err := bindFlags(v, flags); err != nil { + return nil, err + } + setDefaults(v, flags) if v.IsSet(cfgServer+".0."+cfgTLSKeyFile) && v.IsSet(cfgServer+".0."+cfgTLSCertFile) { v.Set(cfgServer+".0."+cfgTLSEnabled, true) } - return v, bindFlags(v, flags) + return v, nil } func newSettings() *appCfg { diff --git a/cmd/s3-gw/app_settings_test.go b/cmd/s3-gw/app_settings_test.go index f00b8e8c..03128b99 100644 --- a/cmd/s3-gw/app_settings_test.go +++ b/cmd/s3-gw/app_settings_test.go @@ -48,3 +48,12 @@ resolve_order: require.Equal(t, []string{resolver.DNSResolver}, cfg.config().GetStringSlice(cfgResolveOrder)) require.Equal(t, 10, cfg.config().GetInt(cfgMaxClientsCount)) } + +func TestSetTLSEnabled(t *testing.T) { + cfg := newSettings() + + require.NoError(t, cfg.flags.Parse([]string{"--" + cfgTLSCertFile, "tls.crt", "--" + cfgTLSKeyFile, "tls.key"})) + require.NoError(t, cfg.reload()) + + require.True(t, cfg.config().GetBool(cfgServer+".0."+cfgTLSEnabled)) +} diff --git a/docs/configuration.md b/docs/configuration.md index d4417b23..aa0db197 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -64,6 +64,8 @@ $ frostfs-s3-gw --listen_address 192.168.130.130:443 \ Using these flag you can configure only one address. To set multiple addresses use yaml config. +**Note:** It's not recommended to configure addresses via flags and yaml config at the same time. + ### RPC endpoint and resolving of bucket names To set RPC endpoint specify a value of parameter `-r` or `--rpc_endpoint`. The parameter is **required if** another