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

Add 'apiclient get' for simple API retrieval #1836

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

tjkirch
Copy link
Contributor

@tjkirch tjkirch commented Nov 20, 2021

Description of changes:

This adds an apiclient get subcommand for simpler retrieval of settings, without having to understand the URIs or query parameters involved (for simple cases). You can specify any number of prefixes, like get settings or get settings.motd settings.host-containers, or you can specify a URI to reach non-model parts of the API, like get /updates/status.

I think there's an opportunity to add filtering, as well, so you could say something like "show me only enabled host containers." I looked into a few options but they didn't work out for now. (In short, I couldn't figure out JSONPath or JMESPath queries that accomplished that example, wasn't sure about statically linking jq, and didn't want to go with a homebrew or less common language. Maybe later!)

Note: this is stacked on a branch representing #1835 because it needs the /?prefix= functionality. I'll need to change the base branch of this PR to develop after that's merged.

Testing done:

Here's an empty response if a prefix doesn't match:

$ apiclient get ready
{}

Here's a prefix match for settings:

$ apiclient get set
{
  "settings": {
    "aws": {
...

Here's the usage information:

$ apiclient go
Unknown argument 'go'
...
get options:
    [ PREFIX [PREFIX ...] ]    The settings you want to get.  Full settings names work fine,
                               or you can specify prefixes to fetch all settings under them.
    [ /desired-uri ]           The API URI to fetch.  Cannot be specified with prefixes.

                               If neither prefixes nor URI are specified, get will show
                               settings and OS info.

Ok, with that minor trolling out of the way, I also tested all the get commands in the updated docs, tested get services, get services.motd, get os, get os.arch, etc. and they all prefix correctly.

The default shows os and settings, which seems useful:

$ apiclient get
{
  "os": {
    "arch": "x86_64",
    "build_id": "697eef79",
    "pretty_name": "Bottlerocket OS 1.4.0 (aws-k8s-1.21)",
    "variant_id": "aws-k8s-1.21",
    "version_id": "1.4.0"
  },
  "settings": {
    "aws": {
...

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

sources/api/apiclient/src/get.rs Outdated Show resolved Hide resolved
sources/api/apiclient/src/main.rs Show resolved Hide resolved
sources/api/apiclient/README.md Show resolved Hide resolved
@tjkirch
Copy link
Contributor Author

tjkirch commented Nov 23, 2021

^ This push fixes the inconsistent capitalization in error messages, per @zmrow.

Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

🧦

@bcressey
Copy link
Contributor

Any idea why the checks didn't run for this PR?

@tjkirch
Copy link
Contributor Author

tjkirch commented Nov 30, 2021

Any idea why the checks didn't run for this PR?

I'm pretty sure it's because this is based on a branch other than develop, since I had to stack this on #1835. We should see results when I merge that and change this base branch.

@tjkirch tjkirch changed the base branch from api-prefix to develop November 30, 2021 18:17
@tjkirch
Copy link
Contributor Author

tjkirch commented Nov 30, 2021

^ This push is just a rebase on develop, because I couldn't figure out any other way to get GitHub to start Checks.

@tjkirch tjkirch merged commit 47640f7 into bottlerocket-os:develop Nov 30, 2021
@tjkirch tjkirch deleted the apiclient-get branch November 30, 2021 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants