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

refactor: move configuration location code to public helper function #422

Merged
merged 1 commit into from
Jan 24, 2023
Merged
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
15 changes: 10 additions & 5 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,7 @@ func CreateProviderClient(

// LoadFromFile attempts to read and unmarshal toml-based configuration into a configuration struct.
func (cp *Processor) loadFromFile(config interface{}, configType string) error {
configDir := environment.GetConfigDir(cp.lc, cp.flags.ConfigDirectory())
profileDir := environment.GetProfileDir(cp.lc, cp.flags.Profile())
configFileName := environment.GetConfigFileName(cp.lc, cp.flags.ConfigFileName())

filePath := configDir + "/" + profileDir + configFileName
filePath := GetConfigLocation(cp.lc, cp.flags)

contents, err := ioutil.ReadFile(filePath)
if err != nil {
Expand All @@ -399,6 +395,15 @@ func (cp *Processor) loadFromFile(config interface{}, configType string) error {
return nil
}

// GetConfigLocation uses the environment variables and flags to determine the location of the configuration
func GetConfigLocation(lc logger.LoggingClient, flags flags.Common) string {
configDir := environment.GetConfigDir(lc, flags.ConfigDirectory())
profileDir := environment.GetProfileDir(lc, flags.Profile())
configFileName := environment.GetConfigFileName(lc, flags.ConfigFileName())

return configDir + "/" + profileDir + configFileName
}

// ProcessWithProvider puts configuration if doesnt exist in provider (i.e. self-seed) or
// gets configuration from provider and updates the service's configuration with envVars overrides after receiving
// them from the provider so that envVars override supersede any changes made in the provider.
Expand Down