diff --git a/go/cmd/vtctldclient/command/permissions.go b/go/cmd/vtctldclient/command/permissions.go new file mode 100644 index 00000000000..59025104ba4 --- /dev/null +++ b/go/cmd/vtctldclient/command/permissions.go @@ -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 ", + Short: "Displays the permissions for a tablet.", + DisableFlagsInUseLine: true, + Args: cobra.ExactArgs(1), + RunE: commandGetPermissions, + } + /* + { + name: "ValidatePermissionsShard", + method: commandValidatePermissionsShard, + params: "", + help: "Validates that the permissions on primary match all the replicas.", + }, + { + name: "ValidatePermissionsKeyspace", + method: commandValidatePermissionsKeyspace, + params: "", + 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) +} diff --git a/go/cmd/vtctldclient/command/tablets.go b/go/cmd/vtctldclient/command/tablets.go index bb468fbd7ff..3ee7de1e867 100644 --- a/go/cmd/vtctldclient/command/tablets.go +++ b/go/cmd/vtctldclient/command/tablets.go @@ -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 ", - 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 ", @@ -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) @@ -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.")