-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
command to check current user in lakectl (#8322)
- Loading branch information
1 parent
e50348e
commit 79b2f4d
Showing
5 changed files
with
87 additions
and
0 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,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) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User ID: esti | ||
Creation Date: <DATE> <TIME> <TZ> |
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