Skip to content

Commit

Permalink
refactor: default region to US
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrombley committed Jul 8, 2021
1 parent 2e2d08b commit 7b55db1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
17 changes: 15 additions & 2 deletions internal/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func initializeCredentialsProvider() {
region.US.String(),
region.EU.String(),
),
Default: region.US.String(),
},
FieldDefinition{
Key: AccountID,
Expand Down Expand Up @@ -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 ""
}
Expand All @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions internal/configuration/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/profile/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 7b55db1

Please sign in to comment.