Skip to content

Commit

Permalink
fix: Fix handling of the privateKeyFile and api-enabled options (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou authored Nov 29, 2024
1 parent eaa4303 commit 04d2136
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
14 changes: 9 additions & 5 deletions pkg/config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ type AppConfig struct {
// 3. Override with values from the configuration file.
// 4. Override with command-line flags.
//
// In case of any errors it returns nill with an error object
// In case of any errors it returns nil with an error object
func GetConfig() (*AppConfig, error) {
instance := &AppConfig{}
instance.setDefaultConfig()
// TODO Shouldn't the env vars override the file config, instead of the other way around?
instance.setEnvVariableConfig()
instance.setFileConfig(viper.GetString("FILE_PATH"))

Expand All @@ -87,6 +86,9 @@ func GetConfig() (*AppConfig, error) {
return nil, fmt.Errorf("Unable to unmarshal config into struct, %v", err)
}

if instance.PrivateKeyFile == DefaultPrivKeyFile {
instance.PrivateKeyFile = filepath.Join(instance.MasaDir, DefaultPrivKeyFile)
}
instance.APIEnabled = viper.GetBool("api_enabled")

keyManager, err := masacrypto.NewKeyManager(instance.PrivateKey, instance.PrivateKeyFile)
Expand Down Expand Up @@ -121,9 +123,11 @@ func (c *AppConfig) setDefaultConfig() {
viper.SetDefault(AllowedPeer, true)
viper.SetDefault(LogLevel, "info")
viper.SetDefault(LogFilePath, "masa_node.log")
viper.SetDefault(PrivKeyFile, filepath.Join(viper.GetString(MasaDir), "masa_oracle_key"))
// It should be ${MASA_DIR}/masa_oracle_key. However, we really don't know the value of MASA_DIR at this point.
// We set it up with a marker value which we will have to fix once we load the full config.
viper.SetDefault(PrivKeyFile, DefaultPrivKeyFile)

viper.SetDefault("api_enabled", false)
viper.SetDefault(APIEnabled, false)
}

// setFileConfig loads configuration from a YAML file.
Expand Down Expand Up @@ -185,7 +189,7 @@ func (c *AppConfig) setCommandLineConfig() error {
pflag.BoolVar(&c.TelegramScraper, "telegramScraper", viper.GetBool(TelegramScraper), "Telegram Scraper")
pflag.BoolVar(&c.WebScraper, "webScraper", viper.GetBool(WebScraper), "Web Scraper")
pflag.BoolVar(&c.Faucet, "faucet", viper.GetBool(Faucet), "Faucet")
pflag.BoolVar(&c.APIEnabled, "api-enabled", viper.GetBool("api_enabled"), "Enable API server")
pflag.BoolVar(&c.APIEnabled, "api-enabled", viper.GetBool(APIEnabled), "Enable API server")

pflag.Parse()

Expand Down
19 changes: 10 additions & 9 deletions pkg/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ const (
Rendezvous = "masa-mdns"
PageSize = 25

TwitterUsername = "TWITTER_USERNAME"
TwitterPassword = "TWITTER_PASSWORD"
Twitter2FaCode = "TWITTER_2FA_CODE"
DiscordBotToken = "DISCORD_BOT_TOKEN"
TwitterScraper = "TWITTER_SCRAPER"
DiscordScraper = "DISCORD_SCRAPER"
TelegramScraper = "TELEGRAM_SCRAPER"
WebScraper = "WEB_SCRAPER"
APIEnabled = "API_ENABLED"
TwitterUsername = "TWITTER_USERNAME"
TwitterPassword = "TWITTER_PASSWORD"
Twitter2FaCode = "TWITTER_2FA_CODE"
DiscordBotToken = "DISCORD_BOT_TOKEN"
TwitterScraper = "TWITTER_SCRAPER"
DiscordScraper = "DISCORD_SCRAPER"
TelegramScraper = "TELEGRAM_SCRAPER"
WebScraper = "WEB_SCRAPER"
APIEnabled = "API_ENABLED"
DefaultPrivKeyFile = "masa_oracle_key"
)

0 comments on commit 04d2136

Please sign in to comment.