-
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.
Merge remote-tracking branch 'upstream/main' into fix-vschemaddl-flake
Signed-off-by: Harshit Gangal <[email protected]>
- Loading branch information
Showing
50 changed files
with
2,629 additions
and
1,373 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
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,36 @@ | ||
/* | ||
Copyright 2023 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 agreedto 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 ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var AddAuth = &cobra.Command{ | ||
Use: "addAuth <digest> <user:pass>", | ||
Args: cobra.ExactArgs(2), | ||
RunE: commandAddAuth, | ||
} | ||
|
||
func commandAddAuth(cmd *cobra.Command, args []string) error { | ||
scheme, auth := cmd.Flags().Arg(0), cmd.Flags().Arg(1) | ||
return fs.Conn.AddAuth(cmd.Context(), scheme, []byte(auth)) | ||
} | ||
|
||
func init() { | ||
Root.AddCommand(AddAuth) | ||
} |
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,103 @@ | ||
/* | ||
Copyright 2023 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 agreedto 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" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/z-division/go-zookeeper/zk" | ||
"golang.org/x/term" | ||
|
||
"vitess.io/vitess/go/cmd/zk/internal/zkfilepath" | ||
"vitess.io/vitess/go/vt/log" | ||
"vitess.io/vitess/go/vt/topo" | ||
"vitess.io/vitess/go/vt/topo/zk2topo" | ||
) | ||
|
||
var ( | ||
catArgs = struct { | ||
LongListing bool | ||
Force bool | ||
DecodeProto bool | ||
}{} | ||
|
||
Cat = &cobra.Command{ | ||
Use: "cat <path1> [<path2> ...]", | ||
Example: `zk cat /zk/path | ||
# List filename before file data | ||
zk cat -l /zk/path1 /zk/path2`, | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: commandCat, | ||
} | ||
) | ||
|
||
func commandCat(cmd *cobra.Command, args []string) error { | ||
resolved, err := zk2topo.ResolveWildcards(cmd.Context(), fs.Conn, cmd.Flags().Args()) | ||
if err != nil { | ||
return fmt.Errorf("cat: invalid wildcards: %w", err) | ||
} | ||
if len(resolved) == 0 { | ||
// the wildcards didn't result in anything, we're done | ||
return nil | ||
} | ||
|
||
hasError := false | ||
for _, arg := range resolved { | ||
zkPath := zkfilepath.Clean(arg) | ||
data, _, err := fs.Conn.Get(cmd.Context(), zkPath) | ||
if err != nil { | ||
hasError = true | ||
if !catArgs.Force || err != zk.ErrNoNode { | ||
log.Warningf("cat: cannot access %v: %v", zkPath, err) | ||
} | ||
continue | ||
} | ||
|
||
if catArgs.LongListing { | ||
fmt.Printf("%v:\n", zkPath) | ||
} | ||
decoded := "" | ||
if catArgs.DecodeProto { | ||
decoded, err = topo.DecodeContent(zkPath, data, false) | ||
if err != nil { | ||
log.Warningf("cat: cannot proto decode %v: %v", zkPath, err) | ||
decoded = string(data) | ||
} | ||
} else { | ||
decoded = string(data) | ||
} | ||
fmt.Print(decoded) | ||
if len(decoded) > 0 && decoded[len(decoded)-1] != '\n' && (term.IsTerminal(int(os.Stdout.Fd())) || catArgs.LongListing) { | ||
fmt.Print("\n") | ||
} | ||
} | ||
if hasError { | ||
return fmt.Errorf("cat: some paths had errors") | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
Cat.Flags().BoolVarP(&catArgs.LongListing, "longListing", "l", false, "long listing") | ||
Cat.Flags().BoolVarP(&catArgs.Force, "force", "f", false, "no warning on nonexistent node") | ||
Cat.Flags().BoolVarP(&catArgs.DecodeProto, "decodeProto", "p", false, "decode proto files and display them as text") | ||
|
||
Root.AddCommand(Cat) | ||
} |
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,91 @@ | ||
/* | ||
Copyright 2023 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 agreedto 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/zk/internal/zkfilepath" | ||
"vitess.io/vitess/go/cmd/zk/internal/zkfs" | ||
"vitess.io/vitess/go/vt/log" | ||
"vitess.io/vitess/go/vt/topo/zk2topo" | ||
) | ||
|
||
var Chmod = &cobra.Command{ | ||
Use: "chmod <mode> <path>", | ||
Example: `zk chmod n-mode /zk/path | ||
zk chmod n+mode /zk/path`, | ||
Args: cobra.MinimumNArgs(2), | ||
RunE: commandChmod, | ||
} | ||
|
||
func commandChmod(cmd *cobra.Command, args []string) error { | ||
mode := cmd.Flags().Arg(0) | ||
if mode[0] != 'n' { | ||
return fmt.Errorf("chmod: invalid mode") | ||
} | ||
|
||
addPerms := false | ||
if mode[1] == '+' { | ||
addPerms = true | ||
} else if mode[1] != '-' { | ||
return fmt.Errorf("chmod: invalid mode") | ||
} | ||
|
||
permMask := zkfs.ParsePermMode(mode[2:]) | ||
|
||
resolved, err := zk2topo.ResolveWildcards(cmd.Context(), fs.Conn, cmd.Flags().Args()[1:]) | ||
if err != nil { | ||
return fmt.Errorf("chmod: invalid wildcards: %w", err) | ||
} | ||
if len(resolved) == 0 { | ||
// the wildcards didn't result in anything, we're done | ||
return nil | ||
} | ||
|
||
hasError := false | ||
for _, arg := range resolved { | ||
zkPath := zkfilepath.Clean(arg) | ||
aclv, _, err := fs.Conn.GetACL(cmd.Context(), zkPath) | ||
if err != nil { | ||
hasError = true | ||
log.Warningf("chmod: cannot set access %v: %v", zkPath, err) | ||
continue | ||
} | ||
if addPerms { | ||
aclv[0].Perms |= permMask | ||
} else { | ||
aclv[0].Perms &= ^permMask | ||
} | ||
err = fs.Conn.SetACL(cmd.Context(), zkPath, aclv, -1) | ||
if err != nil { | ||
hasError = true | ||
log.Warningf("chmod: cannot set access %v: %v", zkPath, err) | ||
continue | ||
} | ||
} | ||
if hasError { | ||
return fmt.Errorf("chmod: some paths had errors") | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
Root.AddCommand(Chmod) | ||
} |
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,43 @@ | ||
/* | ||
Copyright 2023 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 agreedto 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 "github.com/spf13/cobra" | ||
|
||
var Cp = &cobra.Command{ | ||
Use: "cp <src> <dst>", | ||
Example: `zk cp /zk/path . | ||
zk cp ./config /zk/path/config | ||
# Trailing slash indicates directory | ||
zk cp ./config /zk/path/`, | ||
Args: cobra.MinimumNArgs(2), | ||
RunE: commandCp, | ||
} | ||
|
||
func commandCp(cmd *cobra.Command, args []string) error { | ||
switch cmd.Flags().NArg() { | ||
case 2: | ||
return fs.CopyContext(cmd.Context(), cmd.Flags().Arg(0), cmd.Flags().Arg(1)) | ||
default: | ||
return fs.MultiCopyContext(cmd.Context(), cmd.Flags().Args()) | ||
} | ||
} | ||
|
||
func init() { | ||
Root.AddCommand(Cp) | ||
} |
Oops, something went wrong.