Skip to content

Commit

Permalink
rpadmin: add singleKeyConfig()
Browse files Browse the repository at this point in the history
`rpk cluster config get` requests only a single cluster property from
`redpanda`.

However, currently we return the entire JSON of the cluster properties
to `rpk`, and then parse the desired property from there.

To support retrieving only a single value from the cluster properties
(and also to support aliased properties in the future), add
`singleKeyConfig()`, which uses a string to be used as the query parameter
`key` to the `redpanda` admin endpoint.
  • Loading branch information
WillemKauf committed Jul 31, 2024
1 parent 2b374ca commit b19a5fd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rpadmin/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ func (a *AdminAPI) Config(ctx context.Context, includeDefaults bool) (Config, er
return unmarshaled, nil
}

func (a *AdminAPI) SingleKeyConfig(ctx context.Context, key string) (Config, error) {
var rawResp []byte
err := a.sendAny(ctx, http.MethodGet, fmt.Sprintf("/v1/cluster_config?key=%s", key), nil, &rawResp)
if err != nil {
return nil, err
}
var unmarshaled Config
if err := json.Unmarshal(rawResp, &unmarshaled); err != nil {
return nil, fmt.Errorf("unable to decode response body: %w", err)
}
return unmarshaled, nil
}

// SetLogLevel sets the logger level for the logger `name` to the given level
// for the single admin host in this client. This function will return an error
// if the client has multiple URLs configured.
Expand Down

0 comments on commit b19a5fd

Please sign in to comment.