-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matt Lord <[email protected]>
- Loading branch information
Showing
15 changed files
with
2,450 additions
and
1,190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
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, | ||
} | ||
ValidatePermissionsShard = &cobra.Command{ | ||
Use: "ValidatePermissionsShard <keyspace/shard>", | ||
Short: "Validates that the permissions on primary match all the replicas.", | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.ExactArgs(1), | ||
RunE: commandValidatePermissionsShard, | ||
} | ||
ValidatePermissionsKeyspace = &cobra.Command{ | ||
Use: "ValidatePermissionsKeyspace <keyspace name>", | ||
Short: "Validates that the permissions on primary of the first shard match those of all of the other tablets in the keyspace.", | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.ExactArgs(1), | ||
RunE: commandValidatePermissionsKeyspace, | ||
} | ||
) | ||
|
||
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 commandValidatePermissionsKeyspace(cmd *cobra.Command, args []string) error { | ||
keyspace := cmd.Flags().Arg(0) | ||
|
||
cli.FinishedParsing(cmd) | ||
|
||
_, err := client.ValidatePermissionsKeyspace(commandCtx, &vtctldatapb.ValidatePermissionsKeyspaceRequest{ | ||
Keyspace: keyspace, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func commandValidatePermissionsShard(cmd *cobra.Command, args []string) error { | ||
keyspace, shard, err := topoproto.ParseKeyspaceShard(cmd.Flags().Arg(0)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cli.FinishedParsing(cmd) | ||
|
||
_, err = client.ValidatePermissionsKeyspace(commandCtx, &vtctldatapb.ValidatePermissionsKeyspaceRequest{ | ||
Keyspace: keyspace, | ||
Shards: []string{shard}, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func init() { | ||
Root.AddCommand(GetPermissions) | ||
Root.AddCommand(ValidatePermissionsKeyspace) | ||
Root.AddCommand(ValidatePermissionsShard) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.