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:
17 files changed
+101
-62
No files matched your search
@@ -4,7 +4,7 @@ function create_role() {
|
||||
local sid=$1
|
||||
local name=$2
|
||||
local gsid=$3
|
||||
|
||||
|
||||
boundary roles create \
|
||||
-scope-id $sid \
|
||||
-name $name \
|
||||
@@ -17,7 +17,7 @@ function read_role() {
|
||||
}
|
||||
|
||||
function delete_role() {
|
||||
boundary roles delete -id $1
|
||||
boundary roles delete -id $1 -format json
|
||||
}
|
||||
|
||||
function list_roles() {
|
||||
@@ -27,28 +27,28 @@ function list_roles() {
|
||||
function assoc_role_grant() {
|
||||
local grant=$1
|
||||
local id=$2
|
||||
|
||||
|
||||
boundary roles add-grants -grant $grant -id $id
|
||||
}
|
||||
|
||||
function assoc_role_principal() {
|
||||
local principal=$1
|
||||
local id=$2
|
||||
|
||||
boundary roles add-principals -principal $principal -id $id
|
||||
|
||||
boundary roles add-principals -principal $principal -id $id
|
||||
}
|
||||
|
||||
function remove_role_grant() {
|
||||
local grant=$1
|
||||
local id=$2
|
||||
|
||||
|
||||
boundary roles remove-grants -grant $grant -id $id
|
||||
}
|
||||
|
||||
function remove_role_principal() {
|
||||
local principal=$1
|
||||
local id=$2
|
||||
|
||||
|
||||
boundary roles remove-principals -principal $principal -id $id
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ function role_id() {
|
||||
|
||||
function role_principal_ids() {
|
||||
local rid=$1
|
||||
strip $(read_role $rid | jq '.item["principals"][]["id"]')
|
||||
strip $(read_role $rid | jq '.item["principals"][]["id"]')
|
||||
}
|
||||
|
||||
function role_has_principal_id() {
|
||||
@@ -69,10 +69,10 @@ function role_has_principal_id() {
|
||||
local ids=$(role_principal_ids $rid)
|
||||
for id in $ids; do
|
||||
if [ $(strip "$id") == "$pid" ]; then
|
||||
return 0
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
return 1
|
||||
}
|
||||
|
||||
function role_grants() {
|
||||
@@ -86,10 +86,10 @@ function role_has_grant() {
|
||||
local hasgrants=$(role_grants $rid)
|
||||
for grant in $hasgrants; do
|
||||
if [ $(strip_all "$grant") == "$g" ]; then
|
||||
return 0
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
return 1
|
||||
}
|
||||
|
||||
function has_default_role_actions() {
|
||||
@@ -99,7 +99,7 @@ function has_default_role_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
|
||||
}
|
||||
Reference in new issue
Block a user