Skip to content

Commit 10e5ccb

Browse files
Remove unnecessary function (#3723)
1 parent af372a6 commit 10e5ccb

File tree

3 files changed

+23
-30
lines changed

3 files changed

+23
-30
lines changed

config/config.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func getConsensusConfig(v *viper.Viper) snowball.Parameters {
106106

107107
func getLoggingConfig(v *viper.Viper) (logging.Config, error) {
108108
loggingConfig := logging.Config{}
109-
loggingConfig.Directory = GetExpandedArg(v, LogsDirKey)
109+
loggingConfig.Directory = getExpandedArg(v, LogsDirKey)
110110
var err error
111111
loggingConfig.LogLevel, err = logging.ToLevel(v.GetString(LogLevelKey))
112112
if err != nil {
@@ -144,7 +144,7 @@ func getHTTPConfig(v *viper.Viper) (node.HTTPConfig, error) {
144144
return node.HTTPConfig{}, fmt.Errorf("unable to decode base64 content: %w", err)
145145
}
146146
case v.IsSet(HTTPSKeyFileKey):
147-
httpsKeyFilepath := GetExpandedArg(v, HTTPSKeyFileKey)
147+
httpsKeyFilepath := getExpandedArg(v, HTTPSKeyFileKey)
148148
httpsKey, err = os.ReadFile(filepath.Clean(httpsKeyFilepath))
149149
if err != nil {
150150
return node.HTTPConfig{}, err
@@ -159,7 +159,7 @@ func getHTTPConfig(v *viper.Viper) (node.HTTPConfig, error) {
159159
return node.HTTPConfig{}, fmt.Errorf("unable to decode base64 content: %w", err)
160160
}
161161
case v.IsSet(HTTPSCertFileKey):
162-
httpsCertFilepath := GetExpandedArg(v, HTTPSCertFileKey)
162+
httpsCertFilepath := getExpandedArg(v, HTTPSCertFileKey)
163163
httpsCert, err = os.ReadFile(filepath.Clean(httpsCertFilepath))
164164
if err != nil {
165165
return node.HTTPConfig{}, err
@@ -558,7 +558,7 @@ func getIPConfig(v *viper.Viper) (node.IPConfig, error) {
558558

559559
func getProfilerConfig(v *viper.Viper) (profiler.Config, error) {
560560
config := profiler.Config{
561-
Dir: GetExpandedArg(v, ProfileDirKey),
561+
Dir: getExpandedArg(v, ProfileDirKey),
562562
Enabled: v.GetBool(ProfileContinuousEnabledKey),
563563
Freq: v.GetDuration(ProfileContinuousFreqKey),
564564
MaxNumFiles: v.GetInt(ProfileContinuousMaxFilesKey),
@@ -592,8 +592,8 @@ func getStakingTLSCertFromFlag(v *viper.Viper) (tls.Certificate, error) {
592592

593593
func getStakingTLSCertFromFile(v *viper.Viper) (tls.Certificate, error) {
594594
// Parse the staking key/cert paths and expand environment variables
595-
stakingKeyPath := GetExpandedArg(v, StakingTLSKeyPathKey)
596-
stakingCertPath := GetExpandedArg(v, StakingCertPathKey)
595+
stakingKeyPath := getExpandedArg(v, StakingTLSKeyPathKey)
596+
stakingCertPath := getExpandedArg(v, StakingCertPathKey)
597597

598598
// If staking key/cert locations are specified but not found, error
599599
if v.IsSet(StakingTLSKeyPathKey) || v.IsSet(StakingCertPathKey) {
@@ -661,7 +661,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) {
661661
return key, nil
662662
}
663663

664-
signingKeyPath := GetExpandedArg(v, StakingSignerKeyPathKey)
664+
signingKeyPath := getExpandedArg(v, StakingSignerKeyPathKey)
665665
_, err := os.Stat(signingKeyPath)
666666
if !errors.Is(err, fs.ErrNotExist) {
667667
signingKeyBytes, err := os.ReadFile(signingKeyPath)
@@ -703,9 +703,9 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err
703703
SybilProtectionEnabled: v.GetBool(SybilProtectionEnabledKey),
704704
SybilProtectionDisabledWeight: v.GetUint64(SybilProtectionDisabledWeightKey),
705705
PartialSyncPrimaryNetwork: v.GetBool(PartialSyncPrimaryNetworkKey),
706-
StakingKeyPath: GetExpandedArg(v, StakingTLSKeyPathKey),
707-
StakingCertPath: GetExpandedArg(v, StakingCertPathKey),
708-
StakingSignerPath: GetExpandedArg(v, StakingSignerKeyPathKey),
706+
StakingKeyPath: getExpandedArg(v, StakingTLSKeyPathKey),
707+
StakingCertPath: getExpandedArg(v, StakingCertPathKey),
708+
StakingSignerPath: getExpandedArg(v, StakingSignerKeyPathKey),
709709
}
710710
if !config.SybilProtectionEnabled && config.SybilProtectionDisabledWeight == 0 {
711711
return node.StakingConfig{}, errSybilProtectionDisabledStakerWeights
@@ -807,7 +807,7 @@ func getUpgradeConfig(v *viper.Viper, networkID uint32) (upgrade.Config, error)
807807
)
808808
switch {
809809
case v.IsSet(UpgradeFileKey):
810-
upgradeFileName := GetExpandedArg(v, UpgradeFileKey)
810+
upgradeFileName := getExpandedArg(v, UpgradeFileKey)
811811
upgradeBytes, err = os.ReadFile(upgradeFileName)
812812
if err != nil {
813813
return upgrade.Config{}, fmt.Errorf("unable to read upgrade file: %w", err)
@@ -836,7 +836,7 @@ func getGenesisData(v *viper.Viper, networkID uint32, stakingCfg *genesis.Stakin
836836

837837
// if content is not specified go for the file
838838
if v.IsSet(GenesisFileKey) {
839-
genesisFileName := GetExpandedArg(v, GenesisFileKey)
839+
genesisFileName := getExpandedArg(v, GenesisFileKey)
840840
return genesis.FromFile(networkID, genesisFileName, stakingCfg)
841841
}
842842

@@ -877,7 +877,7 @@ func getDatabaseConfig(v *viper.Viper, networkID uint32) (node.DatabaseConfig, e
877877
return node.DatabaseConfig{}, fmt.Errorf("unable to decode base64 content: %w", err)
878878
}
879879
} else if v.IsSet(DBConfigFileKey) {
880-
path := GetExpandedArg(v, DBConfigFileKey)
880+
path := getExpandedArg(v, DBConfigFileKey)
881881
configBytes, err = os.ReadFile(path)
882882
if err != nil {
883883
return node.DatabaseConfig{}, err
@@ -888,7 +888,7 @@ func getDatabaseConfig(v *viper.Viper, networkID uint32) (node.DatabaseConfig, e
888888
Name: v.GetString(DBTypeKey),
889889
ReadOnly: v.GetBool(DBReadOnlyKey),
890890
Path: filepath.Join(
891-
GetExpandedArg(v, DBPathKey),
891+
getExpandedArg(v, DBPathKey),
892892
constants.NetworkName(networkID),
893893
),
894894
Config: configBytes,
@@ -905,7 +905,7 @@ func getAliases(v *viper.Viper, name string, contentKey string, fileKey string)
905905
return nil, fmt.Errorf("unable to decode base64 content for %s: %w", name, err)
906906
}
907907
} else {
908-
aliasFilePath := filepath.Clean(GetExpandedArg(v, fileKey))
908+
aliasFilePath := filepath.Clean(getExpandedArg(v, fileKey))
909909
exists, err := storage.FileExists(aliasFilePath)
910910
if err != nil {
911911
return nil, err
@@ -941,7 +941,7 @@ func getChainAliases(v *viper.Viper) (map[ids.ID][]string, error) {
941941

942942
// getPathFromDirKey reads flag value from viper instance and then checks the folder existence
943943
func getPathFromDirKey(v *viper.Viper, configKey string) (string, error) {
944-
configDir := GetExpandedArg(v, configKey)
944+
configDir := getExpandedArg(v, configKey)
945945
cleanPath := filepath.Clean(configDir)
946946
ok, err := storage.FolderExists(cleanPath)
947947
if err != nil {
@@ -1223,7 +1223,7 @@ func getTraceConfig(v *viper.Viper) (trace.Config, error) {
12231223

12241224
// Returns the path to the directory that contains VM binaries.
12251225
func getPluginDir(v *viper.Viper) (string, error) {
1226-
pluginDir := GetExpandedString(v, v.GetString(PluginDirKey))
1226+
pluginDir := getExpandedArg(v, PluginDirKey)
12271227

12281228
if v.IsSet(PluginDirKey) {
12291229
// If the flag was given, assert it exists and is a directory
@@ -1452,9 +1452,9 @@ func GetNodeConfig(v *viper.Viper) (node.Config, error) {
14521452
return node.Config{}, err
14531453
}
14541454

1455-
nodeConfig.ChainDataDir = GetExpandedArg(v, ChainDataDirKey)
1455+
nodeConfig.ChainDataDir = getExpandedArg(v, ChainDataDirKey)
14561456

1457-
nodeConfig.ProcessContextFilePath = GetExpandedArg(v, ProcessContextFileKey)
1457+
nodeConfig.ProcessContextFilePath = getExpandedArg(v, ProcessContextFileKey)
14581458

14591459
nodeConfig.ProvidedFlags = providedFlags(v)
14601460
return nodeConfig, nil

config/flags.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,13 @@ func BuildFlagSet() *pflag.FlagSet {
394394
return fs
395395
}
396396

397-
// GetExpandedArg gets the string in viper corresponding to [key] and expands
397+
// getExpandedArg gets the string in viper corresponding to [key] and expands
398398
// any variables using the OS env. If the [AvalancheGoDataDirVar] var is used,
399399
// we expand the value of the variable with the string in viper corresponding to
400400
// [DataDirKey].
401-
func GetExpandedArg(v *viper.Viper, key string) string {
402-
return GetExpandedString(v, v.GetString(key))
403-
}
404-
405-
// GetExpandedString expands [s] with any variables using the OS env. If the
406-
// [AvalancheGoDataDirVar] var is used, we expand the value of the variable with
407-
// the string in viper corresponding to [DataDirKey].
408-
func GetExpandedString(v *viper.Viper, s string) string {
401+
func getExpandedArg(v *viper.Viper, key string) string {
409402
return os.Expand(
410-
s,
403+
v.GetString(key),
411404
func(strVar string) string {
412405
if strVar == AvalancheGoDataDirVar {
413406
return os.ExpandEnv(v.GetString(DataDirKey))

config/viper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func BuildViper(fs *pflag.FlagSet, args []string) (*viper.Viper, error) {
5757
}
5858

5959
case v.IsSet(ConfigFileKey):
60-
filename := GetExpandedArg(v, ConfigFileKey)
60+
filename := getExpandedArg(v, ConfigFileKey)
6161
v.SetConfigFile(filename)
6262
if err := v.ReadInConfig(); err != nil {
6363
return nil, err

0 commit comments

Comments
 (0)