74
74
func GetRunnerConfig (v * viper.Viper ) (runner.Config , error ) {
75
75
config := runner.Config {
76
76
DisplayVersionAndExit : v .GetBool (VersionKey ),
77
- BuildDir : os . ExpandEnv ( v . GetString ( BuildDirKey ) ),
77
+ BuildDir : GetExpandedArg ( v , BuildDirKey ),
78
78
PluginMode : v .GetBool (PluginModeKey ),
79
79
}
80
80
@@ -100,6 +100,7 @@ func GetRunnerConfig(v *viper.Viper) (runner.Config, error) {
100
100
101
101
foundBuildDir := false
102
102
for _ , dir := range defaultBuildDirs {
103
+ dir = GetExpandedString (v , dir )
103
104
if validBuildDir (dir ) {
104
105
config .BuildDir = dir
105
106
foundBuildDir = true
@@ -136,7 +137,7 @@ func getConsensusConfig(v *viper.Viper) avalanche.Parameters {
136
137
137
138
func getLoggingConfig (v * viper.Viper ) (logging.Config , error ) {
138
139
loggingConfig := logging.Config {}
139
- loggingConfig .Directory = os . ExpandEnv ( v . GetString ( LogsDirKey ) )
140
+ loggingConfig .Directory = GetExpandedArg ( v , LogsDirKey )
140
141
var err error
141
142
loggingConfig .LogLevel , err = logging .ToLevel (v .GetString (LogLevelKey ))
142
143
if err != nil {
@@ -194,7 +195,7 @@ func getIPCConfig(v *viper.Viper) node.IPCConfig {
194
195
config .IPCDefaultChainIDs = strings .Split (v .GetString (IpcsChainIDsKey ), "," )
195
196
}
196
197
if v .IsSet (IpcsPathKey ) {
197
- config .IPCPath = os . ExpandEnv ( v . GetString ( IpcsPathKey ) )
198
+ config .IPCPath = GetExpandedArg ( v , IpcsPathKey )
198
199
}
199
200
return config
200
201
}
@@ -213,7 +214,7 @@ func getHTTPConfig(v *viper.Viper) (node.HTTPConfig, error) {
213
214
return node.HTTPConfig {}, fmt .Errorf ("unable to decode base64 content: %w" , err )
214
215
}
215
216
case v .IsSet (HTTPSKeyFileKey ):
216
- httpsKeyFilepath := os . ExpandEnv ( v . GetString ( HTTPSKeyFileKey ) )
217
+ httpsKeyFilepath := GetExpandedArg ( v , HTTPSKeyFileKey )
217
218
if httpsKey , err = os .ReadFile (filepath .Clean (httpsKeyFilepath )); err != nil {
218
219
return node.HTTPConfig {}, err
219
220
}
@@ -227,7 +228,7 @@ func getHTTPConfig(v *viper.Viper) (node.HTTPConfig, error) {
227
228
return node.HTTPConfig {}, fmt .Errorf ("unable to decode base64 content: %w" , err )
228
229
}
229
230
case v .IsSet (HTTPSCertFileKey ):
230
- httpsCertFilepath := os . ExpandEnv ( v . GetString ( HTTPSCertFileKey ) )
231
+ httpsCertFilepath := GetExpandedArg ( v , HTTPSCertFileKey )
231
232
if httpsCert , err = os .ReadFile (filepath .Clean (httpsCertFilepath )); err != nil {
232
233
return node.HTTPConfig {}, err
233
234
}
@@ -599,7 +600,7 @@ func getIPConfig(v *viper.Viper) (node.IPConfig, error) {
599
600
600
601
func getProfilerConfig (v * viper.Viper ) (profiler.Config , error ) {
601
602
config := profiler.Config {
602
- Dir : os . ExpandEnv ( v . GetString ( ProfileDirKey ) ),
603
+ Dir : GetExpandedArg ( v , ProfileDirKey ),
603
604
Enabled : v .GetBool (ProfileContinuousEnabledKey ),
604
605
Freq : v .GetDuration (ProfileContinuousFreqKey ),
605
606
MaxNumFiles : v .GetInt (ProfileContinuousMaxFilesKey ),
@@ -633,8 +634,8 @@ func getStakingTLSCertFromFlag(v *viper.Viper) (tls.Certificate, error) {
633
634
634
635
func getStakingTLSCertFromFile (v * viper.Viper ) (tls.Certificate , error ) {
635
636
// Parse the staking key/cert paths and expand environment variables
636
- stakingKeyPath := os . ExpandEnv ( v . GetString ( StakingKeyPathKey ) )
637
- stakingCertPath := os . ExpandEnv ( v . GetString ( StakingCertPathKey ) )
637
+ stakingKeyPath := GetExpandedArg ( v , StakingKeyPathKey )
638
+ stakingCertPath := GetExpandedArg ( v , StakingCertPathKey )
638
639
639
640
// If staking key/cert locations are specified but not found, error
640
641
if v .IsSet (StakingKeyPathKey ) || v .IsSet (StakingCertPathKey ) {
@@ -684,8 +685,8 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err
684
685
config := node.StakingConfig {
685
686
EnableStaking : v .GetBool (StakingEnabledKey ),
686
687
DisabledStakingWeight : v .GetUint64 (StakingDisabledWeightKey ),
687
- StakingKeyPath : os . ExpandEnv ( v . GetString ( StakingKeyPathKey ) ),
688
- StakingCertPath : os . ExpandEnv ( v . GetString ( StakingCertPathKey ) ),
688
+ StakingKeyPath : GetExpandedArg ( v , StakingKeyPathKey ),
689
+ StakingCertPath : GetExpandedArg ( v , StakingCertPathKey ),
689
690
}
690
691
if ! config .EnableStaking && config .DisabledStakingWeight == 0 {
691
692
return node.StakingConfig {}, errInvalidStakerWeights
@@ -755,7 +756,7 @@ func getGenesisData(v *viper.Viper, networkID uint32) ([]byte, ids.ID, error) {
755
756
756
757
// if content is not specified go for the file
757
758
if v .IsSet (GenesisConfigFileKey ) {
758
- genesisFileName := os . ExpandEnv ( v . GetString ( GenesisConfigFileKey ) )
759
+ genesisFileName := GetExpandedArg ( v , GenesisConfigFileKey )
759
760
return genesis .FromFile (networkID , genesisFileName )
760
761
}
761
762
@@ -794,7 +795,7 @@ func getDatabaseConfig(v *viper.Viper, networkID uint32) (node.DatabaseConfig, e
794
795
return node.DatabaseConfig {}, fmt .Errorf ("unable to decode base64 content: %w" , err )
795
796
}
796
797
} else if v .IsSet (DBConfigFileKey ) {
797
- path := os . ExpandEnv ( v . GetString ( DBConfigFileKey ) )
798
+ path := GetExpandedArg ( v , DBConfigFileKey )
798
799
configBytes , err = os .ReadFile (path )
799
800
if err != nil {
800
801
return node.DatabaseConfig {}, err
@@ -804,7 +805,7 @@ func getDatabaseConfig(v *viper.Viper, networkID uint32) (node.DatabaseConfig, e
804
805
return node.DatabaseConfig {
805
806
Name : v .GetString (DBTypeKey ),
806
807
Path : filepath .Join (
807
- os . ExpandEnv ( v . GetString ( DBPathKey ) ),
808
+ GetExpandedArg ( v , DBPathKey ),
808
809
constants .NetworkName (networkID ),
809
810
),
810
811
Config : configBytes ,
@@ -866,7 +867,7 @@ func getVMManager(v *viper.Viper) (vms.Manager, error) {
866
867
867
868
// getPathFromDirKey reads flag value from viper instance and then checks the folder existence
868
869
func getPathFromDirKey (v * viper.Viper , configKey string ) (string , error ) {
869
- configDir := os . ExpandEnv ( v . GetString ( configKey ) )
870
+ configDir := GetExpandedArg ( v , configKey )
870
871
cleanPath := filepath .Clean (configDir )
871
872
ok , err := storage .FolderExists (cleanPath )
872
873
if err != nil {
0 commit comments