-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpermission_list.go
More file actions
57 lines (48 loc) · 1.57 KB
/
permission_list.go
File metadata and controls
57 lines (48 loc) · 1.57 KB
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
57
package iam
import (
"io"
"github.com/spf13/cobra"
iamv1 "github.com/qdrant/qdrant-cloud-public-api/gen/go/qdrant/cloud/iam/v1"
"github.com/qdrant/qcloud-cli/internal/cmd/base"
"github.com/qdrant/qcloud-cli/internal/cmd/output"
"github.com/qdrant/qcloud-cli/internal/state"
)
func newPermissionListCommand(s *state.State) *cobra.Command {
return base.ListCmd[*iamv1.ListPermissionsResponse]{
Use: "list",
Short: "List all available permissions",
Long: `List all permissions known in the system for the account.
Permissions are the individual access rights that can be assigned to roles.
Each permission has a value (e.g. "read:clusters") and a category
(e.g. "Cluster").`,
Example: `# List all available permissions
qcloud iam permission list
# Output as JSON
qcloud iam permission list --json`,
Fetch: func(s *state.State, cmd *cobra.Command) (*iamv1.ListPermissionsResponse, error) {
ctx := cmd.Context()
client, err := s.Client(ctx)
if err != nil {
return nil, err
}
accountID, err := s.AccountID()
if err != nil {
return nil, err
}
return client.IAM().ListPermissions(ctx, &iamv1.ListPermissionsRequest{
AccountId: accountID,
})
},
PrintText: func(_ *cobra.Command, w io.Writer, resp *iamv1.ListPermissionsResponse) error {
t := output.NewTable[*iamv1.Permission](w)
t.AddField("PERMISSION", func(v *iamv1.Permission) string {
return v.GetValue()
})
t.AddField("CATEGORY", func(v *iamv1.Permission) string {
return v.GetCategory()
})
t.Write(resp.GetPermissions())
return nil
},
}.CobraCommand(s)
}