Skip to content

Commit

Permalink
Add missing permissions commands
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Dec 27, 2024
1 parent 0e3a8e1 commit 8afa466
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 32 deletions.
80 changes: 80 additions & 0 deletions go/cmd/vtctldclient/command/permissions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package command

import (
"fmt"

"github.com/spf13/cobra"

"vitess.io/vitess/go/cmd/vtctldclient/cli"
"vitess.io/vitess/go/vt/topo/topoproto"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

var (
// GetPermissions makes a GetPermissions gRPC call to a vtctld.
GetPermissions = &cobra.Command{
Use: "GetPermissions <tablet_alias>",
Short: "Displays the permissions for a tablet.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandGetPermissions,
}
/*
{
name: "ValidatePermissionsShard",
method: commandValidatePermissionsShard,
params: "<keyspace/shard>",
help: "Validates that the permissions on primary match all the replicas.",
},
{
name: "ValidatePermissionsKeyspace",
method: commandValidatePermissionsKeyspace,
params: "<keyspace name>",
help: "Validates that the permissions on primary of shard 0 match those of all of the other tablets in the keyspace.",
},
*/
)

func commandGetPermissions(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

resp, err := client.GetPermissions(commandCtx, &vtctldatapb.GetPermissionsRequest{
TabletAlias: alias,
})
if err != nil {
return err
}
p, err := cli.MarshalJSON(resp.Permissions)
if err != nil {
return err
}
fmt.Printf("%s\n", p)

return nil
}

func init() {
Root.AddCommand(GetPermissions)
}
32 changes: 0 additions & 32 deletions go/cmd/vtctldclient/command/tablets.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ Note: hook names may not contain slash (/) characters.
Args: cobra.ExactArgs(1),
RunE: commandGetFullStatus,
}
// GetPermissions makes a GetPermissions gRPC call to a vtctld.
GetPermissions = &cobra.Command{
Use: "GetPermissions <tablet_alias>",
Short: "Displays the permissions for a tablet.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandGetPermissions,
}
// GetTablet makes a GetTablet gRPC call to a vtctld.
GetTablet = &cobra.Command{
Use: "GetTablet <alias>",
Expand Down Expand Up @@ -380,29 +372,6 @@ func commandGetFullStatus(cmd *cobra.Command, args []string) error {
return nil
}

func commandGetPermissions(cmd *cobra.Command, args []string) error {
alias, err := topoproto.ParseTabletAlias(cmd.Flags().Arg(0))
if err != nil {
return err
}

cli.FinishedParsing(cmd)

resp, err := client.GetPermissions(commandCtx, &vtctldatapb.GetPermissionsRequest{
TabletAlias: alias,
})
if err != nil {
return err
}
p, err := cli.MarshalJSON(resp.Permissions)
if err != nil {
return err
}
fmt.Printf("%s\n", p)

return nil
}

func commandGetTablet(cmd *cobra.Command, args []string) error {
aliasStr := cmd.Flags().Arg(0)
alias, err := topoproto.ParseTabletAlias(aliasStr)
Expand Down Expand Up @@ -685,7 +654,6 @@ func init() {

Root.AddCommand(ExecuteHook)
Root.AddCommand(GetFullStatus)
Root.AddCommand(GetPermissions)
Root.AddCommand(GetTablet)

GetTablets.Flags().StringSliceVarP(&getTabletsOptions.TabletAliasStrings, "tablet-alias", "t", nil, "List of tablet aliases to filter by.")
Expand Down

0 comments on commit 8afa466

Please sign in to comment.