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

fix(cli): Status code on api error #2887

Merged
merged 3 commits into from
Feb 3, 2023
Merged

fix(cli): Status code on api error #2887

merged 3 commits into from
Feb 3, 2023

Conversation

tmessi
Copy link
Member

@tmessi tmessi commented Feb 1, 2023

When using the json output of the cli (-format=json), a successful call
to the controller API would place the HTTP status code in the JSON as
status_code. However, if there was an error from the API the status code
would be placed in the JSON as status. In order to be consistent, this
adds a status_code field to the error response case. For backwards
compatibility it still populates status in the error case.

This inconsistency was missed partially due to a bug in the CLI tests. The
assertion on status code was not valid and would always be successful. Thus
this also fixes the assertions and tests.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Shouldn't we just bite the bullet and remove status_code? Or at least deprecate it so we can remove it in a later release and move usage to status?

EDIT: I mean the other way around, deprecating the old one.

internal/tests/cli/boundary/_helpers.bash Show resolved Hide resolved
@tmessi tmessi force-pushed the llb-vault-ssh-cert-injection branch from 15c5fb5 to 8c6e0f1 Compare February 2, 2023 14:38
@tmessi tmessi requested a review from a team February 2, 2023 14:38
@tmessi tmessi requested a review from a team as a code owner February 2, 2023 14:38
@tmessi tmessi requested review from sarahethompson and jeanneryan and removed request for a team February 2, 2023 14:38
@tmessi tmessi force-pushed the llb-vault-ssh-cert-injection branch from 8c6e0f1 to accda14 Compare February 2, 2023 15:07
got=$(echo "$output")

run field_eq "$got" ".item.attributes.key_type" '"ecdsa"'
[ "$status" -eq 0 ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you want an echo "$output" here to get debug info from field_eq?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure how useful it is. The message from jq isn't the greatest. The output from the read_credential_library should already show the full json that is being used for the comparison.

@tmessi tmessi force-pushed the llb-vault-ssh-cert-injection branch from accda14 to a88bcc2 Compare February 2, 2023 17:02
@tmessi tmessi force-pushed the llb-vault-ssh-cert-injection branch from a88bcc2 to 8624819 Compare February 2, 2023 17:43
Base automatically changed from llb-vault-ssh-cert-injection to main February 2, 2023 17:44
@tmessi tmessi added this to the 0.12.x milestone Feb 3, 2023
This ensures that checks for features should work, and bails early if
that is not the case, since if this fails the binary is essentially
broken. This also simplifies code that performs these checks, ie instead
of:

    binaryVersion, err := version.GetReleaseVersion()
    if err != nil {
      // handle error? panic?
    }
    if version.SupportsFeature(binaryVersion, version.FeatureA) {
      // code for FeatureA
    } else {
      // without FeatureA
    }

Implementations can do:

    if version.SupportsFeature(version.Binary, version.FeatureA) {
      // code for FeatureA
    } else {
      // without FeatureA
    }
When using the json output of the cli (`-format=json`), a successful
call to the controller API would place the HTTP status code in the JSON
as `status_code`. However, if there was an error from the API the status
code would be placed in the JSON as `status`. In order to be consistent,
this adds a `status_code` field to the error response case. For
backwards compatibility it still populates `status` in the error case.

This inconsistency was missed partially due to a bug in the CLI tests.
The assertion on status code was not valid and would always be
successful. Thus this also fixes the assertions and tests.
This adds tests for updating specific fields of the credential library.
@tmessi tmessi merged commit ded3925 into main Feb 3, 2023
@tmessi tmessi deleted the tmessi-fix-cli-ui-tests branch February 3, 2023 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants