Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix handling of the privateKeyFile and api-enabled options #640

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
// 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 @@
return nil, fmt.Errorf("Unable to unmarshal config into struct, %v", err)
}

if instance.PrivateKeyFile == DefaultPrivKeyFile {
instance.PrivateKeyFile = filepath.Join(instance.MasaDir, DefaultPrivKeyFile)
}

Check warning on line 91 in pkg/config/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/app.go#L89-L91

Added lines #L89 - L91 were not covered by tests
instance.APIEnabled = viper.GetBool("api_enabled")

keyManager, err := masacrypto.NewKeyManager(instance.PrivateKey, instance.PrivateKeyFile)
Expand Down Expand Up @@ -121,9 +123,11 @@
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)

Check warning on line 128 in pkg/config/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/app.go#L126-L128

Added lines #L126 - L128 were not covered by tests

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

Check warning on line 130 in pkg/config/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/app.go#L130

Added line #L130 was not covered by tests
}

// setFileConfig loads configuration from a YAML file.
Expand Down Expand Up @@ -185,7 +189,7 @@
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")

Check warning on line 192 in pkg/config/app.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/app.go#L192

Added line #L192 was not covered by tests

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"
)