From 340e6b807b1a72260b504151748bb0b3fa21d43f Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 14 Dec 2023 16:21:09 +0300 Subject: [PATCH] [#266] Update params that being reloaded in one place Signed-off-by: Denis Kirillov --- cmd/s3-gw/app.go | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index ca4200f0..8ae511a8 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -196,11 +196,8 @@ func newAppSettings(log *Logger, v *viper.Viper, key *keys.PrivateKey) *appSetti settings := &appSettings{ logLevel: log.lvl, maxClient: newMaxClients(v), - defaultXMLNS: v.GetBool(cfgKludgeUseDefaultXMLNS), defaultMaxAge: fetchDefaultMaxAge(v, log.logger), notificatorEnabled: v.GetBool(cfgEnableNATS), - defaultNamespaces: fetchDefaultNamespaces(log.logger, v), - namespaceHeader: v.GetString(cfgResolveNamespaceHeader), } settings.resolveZoneList = v.GetStringSlice(cfgResolveBucketAllow) @@ -209,17 +206,24 @@ func newAppSettings(log *Logger, v *viper.Viper, key *keys.PrivateKey) *appSetti settings.resolveZoneList = v.GetStringSlice(cfgResolveBucketDeny) } - settings.setBypassContentEncodingInChunks(v.GetBool(cfgKludgeBypassContentEncodingCheckInChunks)) - settings.setClientCut(v.GetBool(cfgClientCut)) - settings.initPlacementPolicy(log.logger, v) - settings.setBufferMaxSizeForPut(v.GetUint64(cfgBufferMaxSizeForPut)) - settings.setMD5Enabled(v.GetBool(cfgMD5Enabled)) - settings.setAuthorizedControlAPIKeys(append(fetchAuthorizedKeys(log.logger, v), key.PublicKey())) - settings.setPolicyDenyByDefault(v.GetBool(cfgPolicyDenyByDefault)) + settings.update(v, log.logger, key) return settings } +func (s *appSettings) update(v *viper.Viper, log *zap.Logger, key *keys.PrivateKey) { + s.setNamespaceHeader(v.GetString(cfgResolveNamespaceHeader)) // should be updated before placement policies + s.initPlacementPolicy(log, v) + s.useDefaultXMLNamespace(v.GetBool(cfgKludgeUseDefaultXMLNS)) + s.setBypassContentEncodingInChunks(v.GetBool(cfgKludgeBypassContentEncodingCheckInChunks)) + s.setClientCut(v.GetBool(cfgClientCut)) + s.setBufferMaxSizeForPut(v.GetUint64(cfgBufferMaxSizeForPut)) + s.setMD5Enabled(v.GetBool(cfgMD5Enabled)) + s.setDefaultNamespaces(fetchDefaultNamespaces(log, v)) + s.setAuthorizedControlAPIKeys(append(fetchAuthorizedKeys(log, v), key.PublicKey())) + s.setPolicyDenyByDefault(v.GetBool(cfgPolicyDenyByDefault)) +} + func (s *appSettings) BypassContentEncodingInChunks() bool { s.mu.RLock() defer s.mu.RUnlock() @@ -801,17 +805,7 @@ func (a *App) updateSettings() { a.settings.logLevel.SetLevel(lvl) } - a.settings.setNamespaceHeader(a.cfg.GetString(cfgResolveNamespaceHeader)) // should be updated before placement policies - a.settings.initPlacementPolicy(a.log, a.cfg) - - a.settings.useDefaultXMLNamespace(a.cfg.GetBool(cfgKludgeUseDefaultXMLNS)) - a.settings.setBypassContentEncodingInChunks(a.cfg.GetBool(cfgKludgeBypassContentEncodingCheckInChunks)) - a.settings.setClientCut(a.cfg.GetBool(cfgClientCut)) - a.settings.setBufferMaxSizeForPut(a.cfg.GetUint64(cfgBufferMaxSizeForPut)) - a.settings.setMD5Enabled(a.cfg.GetBool(cfgMD5Enabled)) - a.settings.setDefaultNamespaces(a.cfg.GetStringSlice(cfgKludgeDefaultNamespaces)) - a.settings.setAuthorizedControlAPIKeys(append(fetchAuthorizedKeys(a.log, a.cfg), a.key.PublicKey())) - a.settings.setPolicyDenyByDefault(a.cfg.GetBool(cfgPolicyDenyByDefault)) + a.settings.update(a.cfg, a.log, a.key) } func (a *App) startServices() {