Skip to content

Commit

Permalink
Output in a format that credentials process understands
Browse files Browse the repository at this point in the history
  • Loading branch information
castrapel committed Oct 16, 2020
1 parent 1250e28 commit 9a66276
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 42 additions & 0 deletions cmd/credential_process.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"fmt"
"github.com/netflix/weep/consoleme"
"github.com/spf13/cobra"
"time"
)

func init() {
CredentialProcessCmd.PersistentFlags().BoolVarP(&exportNoIPRestrict, "no-ip", "n", false, "remove IP restrictions")
rootCmd.AddCommand(CredentialProcessCmd)
}

var CredentialProcessCmd = &cobra.Command{
Use: "credential_process [role_name]",
Short: "Retrieve credentials and writes them in credential_process format",
Args: cobra.ExactArgs(1),
RunE: runCredentialProcess,
}

func runCredentialProcess(cmd *cobra.Command, args []string) error {
exportRole = args[0]
client, err := consoleme.GetClient()
if err != nil {
return err
}
creds, err := client.GetRoleCredentials(exportRole, exportNoIPRestrict)
if err != nil {
return err
}
printCredentialProcess(creds)
return nil
}


func printCredentialProcess(creds consoleme.AwsCredentials) {
expirationTimeFormat := time.Unix(creds.Expiration, 0).Format(time.RFC3339)

fmt.Printf("{\n \"Version\": 1,\n \"AccessKeyId\": \"%s\",\n \"SecretAccessKey\": \"%s\",\n \"SessionToken\": \"%s\", \n \"Expiration\": \"%s\"\n}",
creds.AccessKeyId, creds.SecretAccessKey, creds.SessionToken, expirationTimeFormat)
}
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.60.0 h1:P5ZzC7RJO04094NJYlEnBdFK2wwmnCAy/+7sAzvWs60=
gopkg.in/ini.v1 v1.60.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down

0 comments on commit 9a66276

Please sign in to comment.