Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Use red color for prd accounts (#35)
Browse files Browse the repository at this point in the history
* Use red color for prd accounts

* Add flag doc
  • Loading branch information
Johannes Gehrs authored Jan 19, 2022
1 parent 19f27a1 commit 2c0da0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ REQUIRED
OPTIONAL
--color="00ff7f" The hexcode color that should be set for each profile
--prd-color="ff0000" The hexcode color that should be set for each profile which name ends in 'prd' or 'global'
--use-role-name-in-profile=false Append the role name to the profile name
```

Expand Down
17 changes: 15 additions & 2 deletions pkg/cmd/switch_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ package cmd
*/

import (
"strings"

"github.com/moia-oss/aws-cfg-generator/pkg/util"
"github.com/rs/zerolog/log"
"gopkg.in/ini.v1"
)

// nolint:govet // we need the bare `required` tag here
type SwitchRolesCmd struct {
Color string `help:"The hexcode color that should be set for each profile" default:"00ff7f"`
Color string `help:"The hexcode color that should be set for each profile which name doesn't end in 'prd' or 'global'" default:"00ff7f"`
PrdColor string `help:"The hexcode color that should be set for each profile which name ends in 'prd' or 'global'" default:"ff0000"`
OutputFile string `help:"Where to save the config." required`
UseRoleNameInProfile bool `help:"Append the role name to the profile name" default:false`
}
Expand All @@ -33,6 +36,16 @@ func (swc *SwitchRolesCmd) Run(cli *CLI) error {
return nil
}

func envSpecificColor(profileName string, cmdOptions SwitchRolesCmd) string {
lowerKeyProfileName := strings.ToLower(profileName)

if strings.HasSuffix(lowerKeyProfileName, "prd") || strings.HasSuffix(lowerKeyProfileName, "global") {
return cmdOptions.PrdColor
}

return cmdOptions.Color
}

func generateSwitchRolesProfile(accountMap map[string]string, roleArns []string, cmdOptions SwitchRolesCmd) {
config := ini.Empty()

Expand All @@ -43,7 +56,7 @@ func generateSwitchRolesProfile(accountMap map[string]string, roleArns []string,

setKey("aws_account_id", profile.AccountID)
setKey("role_name", profile.RoleName)
setKey("color", cmdOptions.Color)
setKey("color", envSpecificColor(profile.ProfileName, cmdOptions))
}

err := config.SaveTo(cmdOptions.OutputFile)
Expand Down

0 comments on commit 2c0da0d

Please sign in to comment.