Files
threshold/internal/tests/cli/boundary/_targets.bash
T
Timothy Messier e66ea15fef 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.
2023-02-03 17:00:34 +00:00

95 lines
1.9 KiB
Bash

load _authorized_actions
export TGT_NAME='test'
export TGT_NAME_WITH_ADDR='test-address'
function create_tcp_target() {
local sid=$1
local port=$2
local name=$3
boundary targets create tcp \
-default-port $port \
-name $name \
-scope-id $sid \
-format json
}
function create_tcp_target_with_addr() {
local sid=$1
local addr=$2
local port=$3
local name=$4
boundary targets create tcp \
-address $addr \
-default-port $port \
-name $name \
-scope-id $sid \
-format json
}
function read_target() {
boundary targets read -id $1 -format json
}
function delete_target() {
boundary targets delete -id $1 -format json
}
function list_targets() {
boundary targets list -scope-id $1 -format json
}
function update_address() {
local id=$1
local addr=$2
boundary targets update tcp -id $id -address $2
}
function assoc_host_sources() {
local id=$1
local hst=$2
boundary targets add-host-sources -id $id -host-source $hst
}
function remove_host_sources() {
local id=$1
local hst=$2
boundary targets remove-host-sources -id $id -host-source $hst
}
function target_id_from_name() {
local sid=$1
local name=$2
strip $(list_targets $sid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]")
}
function target_host_source_ids() {
local tid=$1
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)
for id in $ids; do
if [ $(strip "$id") == "$hsid" ]; then
return 0
fi
done
return 1
}
function has_default_target_actions() {
local out=$1
local actions=('read' 'update' 'delete' 'add-host-sources' 'set-host-sources' 'remove-host-sources' 'authorize-session')
for action in ${actions[@]}; do
$(has_authorized_action "$out" "$action") || {
echo "failed to find $action action in output: $out"
return 1
}
done
}