2023-02-02 17:15:17 -08:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2021-01-29 08:04:46 -08:00
|
|
|
load _authorized_actions
|
|
|
|
|
|
2020-10-12 17:00:34 -07:00
|
|
|
function create_host_set() {
|
|
|
|
|
local hcid=$1
|
|
|
|
|
local name=$2
|
|
|
|
|
boundary host-sets create static \
|
|
|
|
|
-host-catalog-id $hcid \
|
|
|
|
|
-name $name \
|
|
|
|
|
-description 'test group'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function read_host_set() {
|
|
|
|
|
boundary host-sets read -id $1 -format json
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_host_set() {
|
|
|
|
|
boundary host-sets delete -id $1 -format json
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function list_host_sets() {
|
|
|
|
|
boundary host-sets list -host-catalog-id $1 -format json
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assoc_host_set_host() {
|
|
|
|
|
boundary host-sets add-hosts -host $1 -id $2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function host_set_id() {
|
|
|
|
|
local name=$1
|
|
|
|
|
local hcid=$2
|
2021-02-25 12:43:17 -05:00
|
|
|
strip $(list_host_sets $hcid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]")
|
2020-10-12 17:00:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function host_set_host_ids() {
|
|
|
|
|
local id=$1
|
2021-02-25 12:43:17 -05:00
|
|
|
ids=$(read_host_set $id | jq '.item["host_ids"]')
|
2020-10-12 17:00:34 -07:00
|
|
|
echo "ids $ids"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function host_set_has_host_id() {
|
|
|
|
|
local hid=$1
|
|
|
|
|
local hsid=$2
|
|
|
|
|
ids=$(host_set_host_ids $hsid)
|
|
|
|
|
echo "ids $ids hid $hid hsid $hsid"
|
|
|
|
|
for id in $ids; do
|
|
|
|
|
if [ $(strip "$id") == "$hid" ]; then
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
return 1
|
|
|
|
|
}
|
2021-01-29 08:04:46 -08:00
|
|
|
|
|
|
|
|
function has_default_host_set_actions() {
|
|
|
|
|
local out=$1
|
|
|
|
|
local actions=('read' 'update' 'delete' 'add-hosts' 'set-hosts' 'remove-hosts')
|
|
|
|
|
|
|
|
|
|
for action in ${actions[@]}; do
|
|
|
|
|
$(has_authorized_action "$out" "$action") || {
|
|
|
|
|
echo "failed to find $action action in output: $out"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
done
|
|
|
|
|
}
|