Skip to content

Commit

Permalink
Merge pull request #117 from Appliscale/issue_116
Browse files Browse the repository at this point in the history
`mfa` mode should not require configuration file #116
  • Loading branch information
Piotr Figwer authored Jun 14, 2018
2 parents ce92f03 + 80113ef commit d4f0d32
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,20 @@ func (config Configuration) GetSpecificationFileURLForCurrentRegion() (string, e

// Return perun configuration read from file.
func GetConfiguration(cliArguments cliparser.CliArguments, logger *logger.Logger) (config Configuration, err error) {
if getMode(cliArguments) != cliparser.ConfigureMode {
var configPath string
configPath, err = getConfigurationPath(cliArguments, logger)
if err != nil {
return
}
var rawConfiguration []byte
rawConfiguration, err = ioutil.ReadFile(configPath)
if err != nil {
return
}
err = yaml.Unmarshal(rawConfiguration, &config)
if err != nil {
return
}
postProcessing(&config, cliArguments)
mode := getMode(cliArguments)

if mode == cliparser.ConfigureMode {
return
}

config, err = getConfigurationFromFile(cliArguments, logger)
if err != nil && mode != cliparser.MfaMode {
return
}

err = nil
postProcessing(&config, cliArguments)

return
}

Expand Down Expand Up @@ -141,3 +137,21 @@ func SaveToFile(config Configuration, path string, logger logger.Logger) {
obj, _ := yaml.Marshal(config)
_, err = file.Write(obj)
}

func getConfigurationFromFile(cliArguments cliparser.CliArguments, logger *logger.Logger) (config Configuration, err error) {
var configPath string
configPath, err = getConfigurationPath(cliArguments, logger)
if err != nil {
return
}
var rawConfiguration []byte
rawConfiguration, err = ioutil.ReadFile(configPath)
if err != nil {
return
}
err = yaml.Unmarshal(rawConfiguration, &config)
if err != nil {
return
}
return
}

0 comments on commit d4f0d32

Please sign in to comment.