-
Notifications
You must be signed in to change notification settings - Fork 330
/
auth_users_credentials_list.go
56 lines (48 loc) · 1.65 KB
/
auth_users_credentials_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"net/http"
"time"
"github.com/spf13/cobra"
"github.com/treeverse/lakefs/pkg/api/apigen"
"github.com/treeverse/lakefs/pkg/api/apiutil"
)
var authUsersCredentialsList = &cobra.Command{
Use: "list",
Short: "List user credentials",
Run: func(cmd *cobra.Command, args []string) {
amount := Must(cmd.Flags().GetInt("amount"))
after := Must(cmd.Flags().GetString("after"))
id := Must(cmd.Flags().GetString("id"))
clt := getClient()
if id == "" {
resp, err := clt.GetCurrentUserWithResponse(cmd.Context())
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
if resp.JSON200 == nil {
Die("Bad response from server", 1)
}
id = resp.JSON200.User.Id
}
resp, err := clt.ListUserCredentialsWithResponse(cmd.Context(), id, &apigen.ListUserCredentialsParams{
After: apiutil.Ptr(apigen.PaginationAfter(after)),
Amount: apiutil.Ptr(apigen.PaginationAmount(amount)),
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
if resp.JSON200 == nil {
Die("Bad response from server", 1)
}
credentials := resp.JSON200.Results
rows := make([][]interface{}, len(credentials))
for i, c := range credentials {
ts := time.Unix(c.CreationDate, 0).String()
rows[i] = []interface{}{c.AccessKeyId, ts}
}
pagination := resp.JSON200.Pagination
PrintTable(rows, []interface{}{"Access Key ID", "Issued Date"}, &pagination, amount)
},
}
//nolint:gochecknoinits
func init() {
authUsersCredentialsList.Flags().String("id", "", "Username (email for password-based users, default: current user)")
addPaginationFlags(authUsersCredentialsList)
authUsersCredentials.AddCommand(authUsersCredentialsList)
}