From 79b2f4d473ba10a39abe3da4233ba09e2ec33c2d Mon Sep 17 00:00:00 2001 From: ItamarYuran <95186982+ItamarYuran@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:16:19 +0200 Subject: [PATCH] command to check current user in lakectl (#8322) --- cmd/lakectl/cmd/identity.go | 45 +++++++++++++++++++++++++++++ docs/reference/cli.md | 29 +++++++++++++++++++ esti/golden/lakectl_help.golden | 1 + esti/golden/lakectl_identity.golden | 2 ++ esti/lakectl_test.go | 10 +++++++ 5 files changed, 87 insertions(+) create mode 100644 cmd/lakectl/cmd/identity.go create mode 100644 esti/golden/lakectl_identity.golden diff --git a/cmd/lakectl/cmd/identity.go b/cmd/lakectl/cmd/identity.go new file mode 100644 index 00000000000..c4a2696180c --- /dev/null +++ b/cmd/lakectl/cmd/identity.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "net/http" + + "github.com/spf13/cobra" +) + +const userInfoTemplate = `User ID: {{.UserID|yellow}} +{{if .Email}}Email: {{.Email|blue}} +{{end}}Creation Date: {{.CreationDate|date}} +` + +var identityCmd = &cobra.Command{ + Use: "identity", + Short: "Show identity info", + Long: "Show the info of the user cofigurated in lakectl", + Example: "lakectl identity", + Args: cobra.ExactArgs(0), + ValidArgsFunction: ValidArgsRepository, + Run: func(cmd *cobra.Command, args []string) { + client := getClient() + resp, err := client.GetCurrentUserWithResponse(cmd.Context()) + DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK) + if resp.JSON200 == nil { + Die("Bad response from server", 1) + } + + id := resp.JSON200.User.Id + CreationDate := resp.JSON200.User.CreationDate + email := resp.JSON200.User.Email + + Write(userInfoTemplate, struct { + UserID string + Email string + CreationDate int64 + }{UserID: id, CreationDate: CreationDate, Email: *email}) + + }, +} + +//nolint:gochecknoinits +func init() { + rootCmd.AddCommand(identityCmd) +} diff --git a/docs/reference/cli.md b/docs/reference/cli.md index de7d3a2d469..3c23ec50751 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -2067,6 +2067,35 @@ lakectl help [command] [flags] +### lakectl identity + +Show identity info + +#### Synopsis +{:.no_toc} + +Show the info of the user cofigurated in lakectl + +``` +lakectl identity [flags] +``` + +#### Examples +{:.no_toc} + +``` +lakectl identity +``` + +#### Options +{:.no_toc} + +``` + -h, --help help for identity +``` + + + ### lakectl import Import data from external source to a destination branch diff --git a/esti/golden/lakectl_help.golden b/esti/golden/lakectl_help.golden index 85f2557db1a..f1b29916c16 100644 --- a/esti/golden/lakectl_help.golden +++ b/esti/golden/lakectl_help.golden @@ -19,6 +19,7 @@ Available Commands: fs View and manipulate objects gc Manage the garbage collection policy help Help about any command + identity Show identity info import Import data from external source to a destination branch local Sync local directories with lakeFS paths log Show log of commits diff --git a/esti/golden/lakectl_identity.golden b/esti/golden/lakectl_identity.golden new file mode 100644 index 00000000000..856fea994f2 --- /dev/null +++ b/esti/golden/lakectl_identity.golden @@ -0,0 +1,2 @@ +User ID: esti +Creation Date: