Skip to content

Commit

Permalink
Merge pull request #122 from christopherhein/feature/85-add-token-onl…
Browse files Browse the repository at this point in the history
…y-flag

Adding a flag to only output the token
  • Loading branch information
mattlandis authored Jul 29, 2018
2 parents 9d41dd5 + 713a733 commit 01dd27d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/aws-iam-authenticator/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var tokenCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
roleARN := viper.GetString("role")
clusterID := viper.GetString("clusterID")
tokenOnly := viper.GetBool("tokenOnly")

if clusterID == "" {
fmt.Fprintf(os.Stderr, "Error: cluster ID not specified\n")
Expand All @@ -58,13 +59,18 @@ var tokenCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "could not get token: %v\n", err)
os.Exit(1)
}
fmt.Println(gen.FormatJSON(tok))
if !tokenOnly {
tok = gen.FormatJSON(tok)
}
fmt.Println(tok)
},
}

func init() {
rootCmd.AddCommand(tokenCmd)
tokenCmd.Flags().StringP("role", "r", "", "Assume an IAM Role ARN before signing this token")
tokenCmd.Flags().Bool("token-only", false, "Return only the token for use with Bearer token based tools")
viper.BindPFlag("role", tokenCmd.Flags().Lookup("role"))
viper.BindPFlag("tokenOnly", tokenCmd.Flags().Lookup("token-only"))
viper.BindEnv("role", "DEFAULT_ROLE")
}

0 comments on commit 01dd27d

Please sign in to comment.