From ee01275d25fe5b703625ea5684bfcf9b348a8d96 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 20 Apr 2023 11:38:10 +0300 Subject: [PATCH] [#125] node: Remove redundant `env` from `config/internal` Signed-off-by: Anton Nikiforov --- cmd/frostfs-node/config/calls_test.go | 6 ++++-- cmd/frostfs-node/config/config.go | 16 ++++++++++---- cmd/frostfs-node/config/internal/env.go | 22 -------------------- cmd/frostfs-node/config/internal/env_test.go | 15 ------------- 4 files changed, 16 insertions(+), 43 deletions(-) delete mode 100644 cmd/frostfs-node/config/internal/env.go delete mode 100644 cmd/frostfs-node/config/internal/env_test.go diff --git a/cmd/frostfs-node/config/calls_test.go b/cmd/frostfs-node/config/calls_test.go index 37ffd2e88..9b283c8f6 100644 --- a/cmd/frostfs-node/config/calls_test.go +++ b/cmd/frostfs-node/config/calls_test.go @@ -2,10 +2,10 @@ package config_test import ( "os" + "strings" "testing" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config" - "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/internal" configtest "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/test" "github.com/stretchr/testify/require" ) @@ -35,7 +35,9 @@ func TestConfigEnv(t *testing.T) { value = "some value" ) - err := os.Setenv(internal.Env(section, name), value) + envName := strings.ToUpper( + strings.Join([]string{config.EnvPrefix, section, name}, config.EnvSeparator)) + err := os.Setenv(envName, value) require.NoError(t, err) c := configtest.EmptyConfig() diff --git a/cmd/frostfs-node/config/config.go b/cmd/frostfs-node/config/config.go index 12c92306b..dba3d12e7 100644 --- a/cmd/frostfs-node/config/config.go +++ b/cmd/frostfs-node/config/config.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/internal" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config" "github.com/spf13/viper" ) @@ -24,7 +23,16 @@ type Config struct { path []string } -const separator = "." +const ( + separator = "." + + // EnvPrefix is a prefix of ENV variables related + // to storage node configuration. + EnvPrefix = "FROSTFS" + + // EnvSeparator is a section separator in ENV variables. + EnvSeparator = "_" +) // Prm groups required parameters of the Config. type Prm struct{} @@ -37,9 +45,9 @@ type Prm struct{} func New(_ Prm, opts ...Option) *Config { v := viper.New() - v.SetEnvPrefix(internal.EnvPrefix) + v.SetEnvPrefix(EnvPrefix) v.AutomaticEnv() - v.SetEnvKeyReplacer(strings.NewReplacer(separator, internal.EnvSeparator)) + v.SetEnvKeyReplacer(strings.NewReplacer(separator, EnvSeparator)) o := defaultOpts() for i := range opts { diff --git a/cmd/frostfs-node/config/internal/env.go b/cmd/frostfs-node/config/internal/env.go deleted file mode 100644 index 6bf260ac1..000000000 --- a/cmd/frostfs-node/config/internal/env.go +++ /dev/null @@ -1,22 +0,0 @@ -package internal - -import ( - "strings" -) - -// EnvPrefix is a prefix of ENV variables related -// to storage node configuration. -const EnvPrefix = "FROSTFS" - -// EnvSeparator is a section separator in ENV variables. -const EnvSeparator = "_" - -// Env returns ENV variable key for a particular config parameter. -func Env(path ...string) string { - return strings.ToUpper( - strings.Join( - append([]string{EnvPrefix}, path...), - EnvSeparator, - ), - ) -} diff --git a/cmd/frostfs-node/config/internal/env_test.go b/cmd/frostfs-node/config/internal/env_test.go deleted file mode 100644 index 3d1af0715..000000000 --- a/cmd/frostfs-node/config/internal/env_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package internal_test - -import ( - "testing" - - "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/internal" - "github.com/stretchr/testify/require" -) - -func TestEnv(t *testing.T) { - require.Equal(t, - "FROSTFS_SECTION_PARAMETER", - internal.Env("section", "parameter"), - ) -}