Bound pool declaration reads and document operator commands
This commit is contained in:
+14
-2
@@ -1002,13 +1002,25 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
}
|
||||
var data []byte
|
||||
if file == "-" {
|
||||
data, err = io.ReadAll(a.In)
|
||||
input := a.In
|
||||
if input == nil {
|
||||
input = os.Stdin
|
||||
}
|
||||
data, err = io.ReadAll(io.LimitReader(input, 256*1024+1))
|
||||
} else {
|
||||
data, err = os.ReadFile(file)
|
||||
var input *os.File
|
||||
input, err = os.Open(file)
|
||||
if err == nil {
|
||||
data, err = io.ReadAll(io.LimitReader(input, 256*1024+1))
|
||||
_ = input.Close()
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(data) > 256*1024 {
|
||||
return fmt.Errorf("resource pool input exceeds 262144 bytes")
|
||||
}
|
||||
var pool protocol.ResourcePool
|
||||
if err := json.Unmarshal(data, &pool); err != nil {
|
||||
return fmt.Errorf("invalid resource pool JSON: %w", err)
|
||||
|
||||
@@ -415,6 +415,22 @@ func TestResourcePoolOperatorCLIConfigureReadbackAndPreserveLease(t *testing.T)
|
||||
t.Fatal(err)
|
||||
}
|
||||
var out bytes.Buffer
|
||||
for _, fromStdin := range []bool{false, true} {
|
||||
oversized := strings.Repeat(" ", 256*1024+1)
|
||||
path := filepath.Join(t.TempDir(), "oversized.json")
|
||||
if err := os.WriteFile(path, []byte(oversized), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fromStdin {
|
||||
path = "-"
|
||||
}
|
||||
bounded := cli.App{Out: &out, Err: &out, In: strings.NewReader(oversized)}
|
||||
err := bounded.Run(ctx, []string{"--url", endpoint, "resource-pool-configure", path, "--yes", "--json"})
|
||||
if err == nil || !strings.Contains(err.Error(), "exceeds 262144 bytes") {
|
||||
t.Fatalf("oversized pool input (stdin=%v): %v", fromStdin, err)
|
||||
}
|
||||
out.Reset()
|
||||
}
|
||||
app := cli.App{Out: &out, Err: &out, In: strings.NewReader("")}
|
||||
if err := app.Run(ctx, []string{"--url", "ws" + strings.TrimPrefix(srv.URL, "http"), "resource-pool-configure", declaration, "--yes", "--json"}); err != nil {
|
||||
t.Fatalf("configure CLI: %v\n%s", err, out.String())
|
||||
|
||||
Reference in New Issue
Block a user