Skip to content

Commit

Permalink
Merge pull request #38 from twmb/raw-req
Browse files Browse the repository at this point in the history
kcl misc raw-req: trust an input version if one exists
twmb authored Feb 7, 2024
2 parents 2572bb0 + 38a8e62 commit 27ac524
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commands/misc/misc.go
Original file line number Diff line number Diff line change
@@ -257,6 +257,12 @@ func probeVersion(cl *client.Client) {
fmt.Println("Kafka " + v.VersionGuess())
}

type pinReq struct {
kmsg.Request
}

func (*pinReq) SetVersion(int16) {}

func rawCommand(cl *client.Client) *cobra.Command {
var key int16
var b int
@@ -269,9 +275,16 @@ func rawCommand(cl *client.Client) *cobra.Command {
if req == nil {
out.Die("request key %d unknown", key)
}
req.SetVersion(-1)
raw, err := io.ReadAll(os.Stdin)
out.MaybeDie(err, "unable to read stdin: %v", err)
err = json.Unmarshal(raw, req)
// If the raw json specified a Version field, it
// overwrote our -1. We want to pin the version to
// what the user specified.
if req.GetVersion() != -1 {
req = &pinReq{req}
}
out.MaybeDie(err, "unable to unmarshal stdin: %v", err)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

0 comments on commit 27ac524

Please sign in to comment.