Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the api command. #1946

Merged
merged 35 commits into from
Apr 7, 2022
Merged

Added the api command. #1946

merged 35 commits into from
Apr 7, 2022

Conversation

ericpromislow
Copy link
Contributor

@ericpromislow ericpromislow commented Mar 31, 2022

Fixes #1903

Currently supports these options:

--method | -X method (default PUT when input is specified, GET otherwise)
--input ( FILE | - ) (like the current settings.json file, `-` for stdin)
--body | -b input-body, normally JSON

And these endpoints:

GET settings
PUT settings <BODY>
PUT shutdown

Signed-off-by: Eric Promislow [email protected]

@ericpromislow ericpromislow requested a review from mook-as March 31, 2022 21:40
@jandubois
Copy link
Member

I expected this to work:

$ ./rdctl api list-settings
Error: server error return-code 404: 404 Not Found
Usage:
  rdctl api [flags]
[...]

Also the usage just says rdctl api [flags]. It should also mention the query-path argument.

Specifying an explicit API version works:

$ ./rdctl api /v0/list-settings
Status: {
  "version": 4,
[...]
}.

But it prefixes the output with the Status: string and appends a spurious . at the end, breaking the JSON format:

$ ./rdctl api /v0/list-settings | jq .version
parse error: Invalid numeric literal at line 1, column 7
$ ./rdctl api /v0/list-settings | sed 's/^Status: //' | sed 's/}\.$/}/' | jq .version
4

@ericpromislow ericpromislow self-assigned this Mar 31, 2022
@ericpromislow ericpromislow added this to the Next milestone Mar 31, 2022
@jandubois jandubois added kind/enhancement New feature or request kind/quality quality improvements, refactoring, Automation via CI, E2E, Integration, CLI or REST API labels Mar 31, 2022
@ericpromislow ericpromislow marked this pull request as draft March 31, 2022 22:53
Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run npm run lint — the go files are not correctly formatted (and our CI isn't catching that correctly).

(Abandoning review because the PR was marked as draft)

@jandubois jandubois removed this from the Next milestone Apr 1, 2022
@ericpromislow ericpromislow force-pushed the 1903-add-api-command branch from 5fc0462 to 7a299f2 Compare April 1, 2022 22:19
@ericpromislow ericpromislow marked this pull request as ready for review April 4, 2022 21:15
@ericpromislow ericpromislow force-pushed the 1903-add-api-command branch from 138538c to 72b2b68 Compare April 4, 2022 21:21
@ericpromislow ericpromislow requested a review from mook-as April 4, 2022 21:25
@jandubois
Copy link
Member

This is wrong:

$ resources/darwin/bin/rdctl api foo; echo $?
{"error":{"message":"404 Not Found","documentation_url":null}}
Unknown command: GET /v0/foo
0

The exit code should be non-zero when the API call failed. And there is no reason to wrap the error properties with another object, this should output:

$ resources/darwin/bin/rdctl api foo; echo $?
{"message":"404 Not Found","documentation_url":null}
Unknown command: GET /v0/foo
1

The HTTP status code (and exit code from rdctl) tell you that the output is an error object, and not the expected data. The error property is not some kind of reserved word to indicate a failure, so the wrapping isn't necessary and just makes extracting the message more complex than it needs to be.

Copy link
Contributor

@mook-as mook-as left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, if we're looping over test parameters we should have subtests.

ericpromislow and others added 6 commits April 6, 2022 09:50
Currently supports these options:
-X method (default PUT when input is specified, GET otherwise)
--input FILE (like the current settings.json file)
--raw-field|-f NAME=VALUE - string VALUEs must be double-quoted
--field|-F NAME=VALUE - double quotes added where needed

Signed-off-by: Eric Promislow <[email protected]>
- Start with list-settings and set subcommands.

Signed-off-by: Eric Promislow <[email protected]>
- Change /list-settings and /set endpoints to /settings
- Remove the --field and --rawField options until we have parameters

Signed-off-by: Eric Promislow <[email protected]>
Signed-off-by: Eric Promislow <[email protected]>
Eric Promislow and others added 7 commits April 6, 2022 09:50
Signed-off-by: Eric Promislow <[email protected]>
Also tabify the go code.

Signed-off-by: Eric Promislow <[email protected]>
Makes it easier to determine which output from an `rdctl api`
call is a server error.

Signed-off-by: Eric Promislow <[email protected]>
@ericpromislow ericpromislow force-pushed the 1903-add-api-command branch from 6ab5271 to 7dec9e2 Compare April 6, 2022 17:03
Signed-off-by: Eric Promislow <[email protected]>
- Use nested categories.
- Use nested tests for looping over options with feedback.

Signed-off-by: Eric Promislow <[email protected]>
Signed-off-by: Eric Promislow <[email protected]>
@ericpromislow ericpromislow force-pushed the 1903-add-api-command branch from ec188c3 to 6ca56f5 Compare April 7, 2022 18:09
Signed-off-by: Eric Promislow <[email protected]>
@ericpromislow ericpromislow requested review from mook-as April 7, 2022 18:30
@ericpromislow ericpromislow merged commit d843e25 into main Apr 7, 2022
@ericpromislow ericpromislow deleted the 1903-add-api-command branch April 7, 2022 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request kind/quality quality improvements, refactoring, Automation via CI, E2E, Integration, CLI or REST API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rdctl api command
3 participants