From 099ceeae501f1e20abfa2adb147d707a2b22817b Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 21 May 2021 20:40:43 +0300 Subject: [PATCH] [#493] node/config: Implement ENV variable key constructor Add `internal.Env` function which converts path to config value to ENV variable key. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config/internal/env.go | 14 ++++++++++++++ cmd/neofs-node/config/internal/env_test.go | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 cmd/neofs-node/config/internal/env_test.go diff --git a/cmd/neofs-node/config/internal/env.go b/cmd/neofs-node/config/internal/env.go index e5174254..43cd8d44 100644 --- a/cmd/neofs-node/config/internal/env.go +++ b/cmd/neofs-node/config/internal/env.go @@ -1,8 +1,22 @@ package internal +import ( + "strings" +) + // EnvPrefix is a prefix of ENV variables related // to storage node configuration. const EnvPrefix = "neofs" // EnvSeparator is a section separator in ENV variables. const EnvSeparator = "_" + +// Env returns ENV variable key for particular config parameter. +func Env(path ...string) string { + return strings.ToUpper( + strings.Join( + append([]string{EnvPrefix}, path...), + EnvSeparator, + ), + ) +} diff --git a/cmd/neofs-node/config/internal/env_test.go b/cmd/neofs-node/config/internal/env_test.go new file mode 100644 index 00000000..a599ad45 --- /dev/null +++ b/cmd/neofs-node/config/internal/env_test.go @@ -0,0 +1,15 @@ +package internal_test + +import ( + "testing" + + "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/internal" + "github.com/stretchr/testify/require" +) + +func TestEnv(t *testing.T) { + require.Equal(t, + "NEOFS_SECTION_PARAMETER", + internal.Env("section", "parameter"), + ) +}