Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit dddd495

Browse files
authored
add --pretty flag to credential_process generation (#120)
1 parent b3d67bd commit dddd495

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

cmd/credential_process.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cmd
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
"strings"
2223
"time"
2324

2425
"github.com/sirupsen/logrus"
@@ -38,6 +39,7 @@ import (
3839
func init() {
3940
CredentialProcessCmd.PersistentFlags().BoolVarP(&generate, "generate", "g", false, "generate ~/.aws/config with credential process config")
4041
CredentialProcessCmd.PersistentFlags().StringVarP(&destinationConfig, "output", "o", getDefaultAwsConfigFile(), "output file for AWS config")
42+
CredentialProcessCmd.PersistentFlags().BoolVarP(&prettyPrint, "pretty", "p", false, "when combined with --generate/-g, use 'account_name-role_name' format for generated profiles instead of arn")
4143
rootCmd.AddCommand(CredentialProcessCmd)
4244
}
4345

@@ -49,7 +51,7 @@ var CredentialProcessCmd = &cobra.Command{
4951
RunE: runCredentialProcess,
5052
}
5153

52-
func writeConfigFile(roles []string, destination string) error {
54+
func writeConfigFile(roles []creds.ConsolemeRolesResponse, destination string) error {
5355
var configINI *ini.File
5456
var err error
5557

@@ -72,9 +74,18 @@ func writeConfigFile(roles []string, destination string) error {
7274
configINI = ini.Empty()
7375
}
7476

77+
replacer := strings.NewReplacer("_", "-", " ", "-")
78+
7579
for _, r := range roles {
76-
profileName := fmt.Sprintf("profile %s", r)
77-
command := fmt.Sprintf("weep credential_process %s", r)
80+
var profileName string
81+
if prettyPrint {
82+
accountName := strings.ToLower(replacer.Replace(r.AccountName))
83+
roleName := strings.ToLower(replacer.Replace(r.RoleName))
84+
profileName = fmt.Sprintf("profile %s-%s", accountName, roleName)
85+
} else {
86+
profileName = fmt.Sprintf("profile %s", r.Arn)
87+
}
88+
command := fmt.Sprintf("weep credential_process %s", r.Arn)
7889
configINI.Section(profileName).Key("credential_process").SetValue(command)
7990
}
8091
err = configINI.SaveTo(destinationConfig)
@@ -93,7 +104,7 @@ func generateCredentialProcessConfig(destination string) error {
93104
if err != nil {
94105
return err
95106
}
96-
roles, err := client.Roles()
107+
roles, err := client.RolesExtended()
97108
if err != nil {
98109
return err
99110
}

cmd/vars.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040
noIpRestrict bool
4141
noOpen bool
4242
profileName string
43+
prettyPrint bool
4344
region string
4445
roleRefreshARN string
4546
shellInfo string

docs/weep_credential_process.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@ weep credential_process [role_name] [flags]
99
### Options
1010

1111
```
12-
-h, --help help for credential_process
13-
-n, --no-ip remove IP restrictions
12+
-h, --help help for credential_process
13+
-g, --generate generate ~/.aws/config with credential process config
14+
-o, --output string output file for AWS config (default "~/.aws/config")
15+
-p, --pretty when combined with --generate/-g, use 'account_name-role_name' format for generated profiles instead of arn
1416
```
1517

1618
### Options inherited from parent commands
1719

1820
```
19-
-c, --config string config file (default is $HOME/.weep.yaml)
20-
--log-format string log format (json or tty)
21-
--log-level string log level (debug, info, warn)
21+
-A, --assume-role strings one or more roles to assume after retrieving credentials
22+
-c, --config string config file (default is $HOME/.weep.yaml)
23+
--extra-config-file string extra-config-file <yaml_file>
24+
--log-file string log file path (default "/tmp/weep.log")
25+
--log-format string log format (json or tty)
26+
--log-level string log level (debug, info, warn)
27+
-n, --no-ip remove IP restrictions
28+
-r, --region string AWS region (default "us-east-1")
2229
```
2330

2431
### SEE ALSO

0 commit comments

Comments
 (0)