diff --git a/internal/configuration/config.go b/internal/configuration/config.go index 7a40a5054..6638a8227 100644 --- a/internal/configuration/config.go +++ b/internal/configuration/config.go @@ -70,6 +70,7 @@ func initializeCredentialsProvider() { region.US.String(), region.EU.String(), ), + Default: region.US.String(), }, FieldDefinition{ Key: AccountID, @@ -155,8 +156,20 @@ func RequireActiveProfileString(key ConfigKey) string { return v } +func GetActiveProfileValue(profileName string, key ConfigKey) interface{} { + return GetProfileValue("", key) +} +func GetProfileValue(profileName string, key ConfigKey) interface{} { + v, err := credentialsProvider.GetWithScope(profileName, key) + if err != nil { + log.Fatalf("could not load value %s from config: %s", key, err) + } + + return v +} + func GetProfileString(profileName string, key ConfigKey) string { - v, err := credentialsProvider.GetStringWithScope(GetActiveProfileName(), key) + v, err := credentialsProvider.GetStringWithScope(profileName, key) if err != nil { return "" } @@ -180,7 +193,7 @@ func GetActiveProfileInt(key ConfigKey) int { func GetProfileInt(profileName string, key ConfigKey) int { v, err := credentialsProvider.GetIntWithScope(GetActiveProfileName(), key) if err != nil { - return 0 + log.Fatalf("could not load value %s from config: %s", key, err) } return int(v) diff --git a/internal/configuration/config_provider.go b/internal/configuration/config_provider.go index ef9afe19a..20b0c003f 100644 --- a/internal/configuration/config_provider.go +++ b/internal/configuration/config_provider.go @@ -205,8 +205,19 @@ func (p *ConfigProvider) GetStringWithScope(scope string, key ConfigKey) (string return "", err } - if s, ok := v.(string); ok { - return s, nil + switch v := v.(type) { + case int64: + return strconv.Itoa(int(v)), nil + case int32: + return strconv.Itoa(int(v)), nil + case float64: + return strconv.Itoa(int(v)), nil + case float32: + return strconv.Itoa(int(v)), nil + case int: + return strconv.Itoa(v), nil + case string: + return v, nil } return "", fmt.Errorf("value %v for key %s is not a string", v, key) @@ -236,7 +247,7 @@ func (p *ConfigProvider) GetWithScope(scope string, key ConfigKey) (interface{}, return d.Default, nil } - return "", err + return nil, err } return res.Value(), nil diff --git a/internal/profile/command.go b/internal/profile/command.go index a026a103b..c95363b2b 100644 --- a/internal/profile/command.go +++ b/internal/profile/command.go @@ -352,7 +352,6 @@ The delete command removes the profile specified by name. } func requireProfileName(cmd *cobra.Command, args []string) { - fmt.Println(configuration.SelectedProfileName) if configuration.SelectedProfileName == "" { log.Fatal("the --profileName argument is required") }