Skip to content

Commit

Permalink
[DEV-172] Add get/list roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkula committed Oct 9, 2023
1 parent 9bb361d commit 410b491
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newGetAliasCmd() *cobra.Command {
return formatOne(cmd, alias)
},
}
cmd.Flags().StringP(WorkspaceFlag, WorkspaceShortFlag, DefaultWorkspace, "only show views for the selected workspace")
cmd.Flags().StringP(WorkspaceFlag, WorkspaceShortFlag, DefaultWorkspace, "get an alias for the selected workspace")

return cmd
}
58 changes: 58 additions & 0 deletions cmd/roles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cmd

import (
"github.com/rockset/cli/format"
"github.com/spf13/cobra"
)

func newListRolesCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "role",
Aliases: []string{"r", "roles"},
Args: cobra.NoArgs,
Short: "list roles",
Annotations: group("role"),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
rs, err := rockClient(cmd)
if err != nil {
return err
}

aliases, err := rs.ListRoles(ctx)
if err != nil {
return err
}

return formatList(cmd, format.ToInterfaceArray(aliases))
},
}

return cmd
}

func newGetRoleCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "role NAME",
Aliases: []string{"r"},
Args: cobra.ExactArgs(1),
Short: "get role information",
Annotations: group("role"),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
rs, err := rockClient(cmd)
if err != nil {
return err
}

alias, err := rs.GetRole(ctx, args[0])
if err != nil {
return err
}

return formatOne(cmd, alias)
},
}

return cmd
}
3 changes: 3 additions & 0 deletions cmd/verbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func addVerbs(root *cobra.Command) {
getCmd.AddCommand(newGetAliasCmd())
listCmd.AddCommand(newListAliasesCmd())

getCmd.AddCommand(newGetRoleCommand())
listCmd.AddCommand(newListRolesCommand())

getCmd.AddCommand(newGetAPIKeyCmd())
listCmd.AddCommand(newListAPIKeysCmd())

Expand Down
2 changes: 2 additions & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func defaultSelectorFor(f any) (DefaultSelector, error) {
return ViewDefaultSelector, nil
case openapi.VirtualInstance:
return VirtualInstanceDefaultSelector, nil
case openapi.Role:
return RoleDefaultSelector, nil
default:
return DefaultSelector{}, fmt.Errorf("no formatter for %T", t)
}
Expand Down
18 changes: 18 additions & 0 deletions format/role.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package format

import "github.com/rockset/rockset-go-client/openapi"

var RoleDefaultSelector = DefaultSelector{
Normal: "Name:.role_name,Created By:.created_by",
Wide: "Name:.role_name,Created By:.created_by,Description:.description",
}

// just to list available fields
var _ = openapi.Role{
CreatedAt: nil,
CreatedBy: nil,
Description: nil,
OwnerEmail: nil,
Privileges: nil,
RoleName: nil,
}

0 comments on commit 410b491

Please sign in to comment.