Skip to content

Commit

Permalink
command to check current user in lakectl (#8322)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItamarYuran authored Oct 31, 2024
1 parent e50348e commit 79b2f4d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cmd/lakectl/cmd/identity.go
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 29 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions esti/golden/lakectl_help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions esti/golden/lakectl_identity.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User ID: esti
Creation Date: <DATE> <TIME> <TZ>
10 changes: 10 additions & 0 deletions esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ func TestLakectlAuthUsers(t *testing.T) {
runCmdAndVerifyResult(t, Lakectl()+" auth users delete --id "+userName, !isSupported, false, expected, vars)
}

// testing without user email for now, since it is a pain to config esti with a mail
func TestLakectlIdentity(t *testing.T) {

userId := "mike"
vars := map[string]string{
"ID": userId,
}
RunCmdAndVerifySuccessWithFile(t, Lakectl()+" identity", false, "lakectl_identity", vars)
}

func TestLakectlIngestS3(t *testing.T) {
// Specific S3 test - due to the limitation on ingest source type that has to match lakefs underlying block store,
// this test can only run on AWS setup, and therefore is skipped for other store types
Expand Down

0 comments on commit 79b2f4d

Please sign in to comment.