fix(cli): Status code on api error

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 commit is contained in:
Timothy Messier committed 2023-02-03 17:00:34 +00:00
1 parent 99a8875d3e
commit e66ea15fef
17 files changed
+101 -62

No files matched your search

+7 -7
View File
@@ -32,7 +32,7 @@ function read_target() {
}
function delete_target() {
boundary targets delete -id $1
boundary targets delete -id $1 -format json
}
function list_targets() {
@@ -65,20 +65,20 @@ function target_id_from_name() {
function target_host_source_ids() {
local tid=$1
boundary targets read -id $tid -format json | jq '.item.host_sources[].id'
boundary targets read -id $tid -format json | jq '.item.host_sources[].id'
}
function target_has_host_source_id() {
local tid=$1
local hsid=$2
ids=$(target_host_source_ids $tid)
ids=$(target_host_source_ids $tid)
for id in $ids; do
if [ $(strip "$id") == "$hsid" ]; then
return 0
return 0
fi
done
return 1
return 1
}
function has_default_target_actions() {
@@ -88,7 +88,7 @@ function has_default_target_actions() {
for action in ${actions[@]}; do
$(has_authorized_action "$out" "$action") || {
echo "failed to find $action action in output: $out"
return 1
}
return 1
}
done
}