forked from TrueCloudLab/frostfs-node
[#125] node: Remove redundant env
from config/internal
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
9d01029733
commit
ee01275d25
4 changed files with 16 additions and 43 deletions
|
@ -2,10 +2,10 @@ package config_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
"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"
|
configtest "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -35,7 +35,9 @@ func TestConfigEnv(t *testing.T) {
|
||||||
value = "some value"
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
c := configtest.EmptyConfig()
|
c := configtest.EmptyConfig()
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/internal"
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/config"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -24,7 +23,16 @@ type Config struct {
|
||||||
path []string
|
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.
|
// Prm groups required parameters of the Config.
|
||||||
type Prm struct{}
|
type Prm struct{}
|
||||||
|
@ -37,9 +45,9 @@ type Prm struct{}
|
||||||
func New(_ Prm, opts ...Option) *Config {
|
func New(_ Prm, opts ...Option) *Config {
|
||||||
v := viper.New()
|
v := viper.New()
|
||||||
|
|
||||||
v.SetEnvPrefix(internal.EnvPrefix)
|
v.SetEnvPrefix(EnvPrefix)
|
||||||
v.AutomaticEnv()
|
v.AutomaticEnv()
|
||||||
v.SetEnvKeyReplacer(strings.NewReplacer(separator, internal.EnvSeparator))
|
v.SetEnvKeyReplacer(strings.NewReplacer(separator, EnvSeparator))
|
||||||
|
|
||||||
o := defaultOpts()
|
o := defaultOpts()
|
||||||
for i := range opts {
|
for i := range opts {
|
||||||
|
|
|
@ -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,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -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"),
|
|
||||||
)
|
|
||||||
}
|
|
Loading…
Reference in a new issue