-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
174 additions
and
20 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
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,19 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "auth", | ||
Short: "Utils for auth.", | ||
Long: `Utils for auth.`, | ||
} | ||
|
||
func init() { | ||
setupWhoamiCmdCmd(rootCmd) | ||
} | ||
|
||
func SetupCmd(root *cobra.Command) { | ||
root.AddCommand(rootCmd) | ||
} |
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,58 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl" | ||
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/common" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/spf13/cobra" | ||
"os" | ||
) | ||
|
||
var whoamiCmd = &cobra.Command{ | ||
Use: "whoami", | ||
Short: "Check who you are", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctl.GlobalOption.Verbose = true | ||
client := common.GetClientOrDie() | ||
|
||
acc, err := client.GetCallerIdentity(context.TODO()) | ||
common.ExitIfError(err) | ||
table := tablewriter.NewWriter(os.Stdout) | ||
//table.SetAutoMergeCells(true) | ||
table.SetAutoWrapText(true) | ||
table.SetAutoFormatHeaders(false) | ||
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetAlignment(tablewriter.ALIGN_LEFT) | ||
table.SetCenterSeparator("") | ||
table.SetColumnSeparator("") | ||
table.SetRowSeparator("") | ||
table.SetHeaderLine(false) | ||
table.EnableBorder(false) | ||
table.SetTablePadding(" ") | ||
table.SetNoWhiteSpace(true) | ||
|
||
table.Append([]string{"AccountId", acc.RootUId}) | ||
table.Append([]string{"IdentityType", acc.IdentityType()}) | ||
if acc.Role.RoleId != "" { | ||
table.Append([]string{"RoleId", acc.Role.RoleId}) | ||
table.Append([]string{"RoleName", acc.Role.RoleName}) | ||
} else if acc.User.Id != "" { | ||
table.Append([]string{"UserId", acc.User.Id}) | ||
table.Append([]string{"UserName", acc.User.Name}) | ||
} | ||
table.Append([]string{"Arn", acc.Arn}) | ||
table.Append([]string{"PrincipalId", acc.PrincipalId}) | ||
|
||
table.Render() | ||
}, | ||
} | ||
|
||
func setupWhoamiCmdCmd(rootCmd *cobra.Command) { | ||
rootCmd.AddCommand(whoamiCmd) | ||
|
||
whoamiCmd.Flags().StringVar( | ||
&ctl.GlobalOption.FinalAssumeRoleAnotherRoleArn, "role-arn", "", | ||
"Assume an RAM Role ARN when send request or sign token") | ||
} |
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
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
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
23 changes: 22 additions & 1 deletion
23
vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/aliyuncli.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.