-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output in a format that credentials process understands
- Loading branch information
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters