cli(aliases): Support aliases for connect and targets in the CLI (#4356)
* cli(aliases): Support aliases for boundary connect and boundary targets CLI
This commit is contained in:
1 parent
5a17c9cd39
commit
ba21e076bb
14 files changed
+541
-36
No files matched your search
@@ -0,0 +1,58 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
load _authorized_actions
|
||||
|
||||
function read_target_by_alias() {
|
||||
boundary targets read $1 -format json
|
||||
}
|
||||
|
||||
function update_address_by_alias() {
|
||||
local aid=$1
|
||||
local addr=$2
|
||||
boundary targets update tcp $aid -address $2
|
||||
}
|
||||
|
||||
function delete_target_by_alias() {
|
||||
boundary targets delete $1 -format json
|
||||
}
|
||||
|
||||
function add_target_host_sources_by_alias() {
|
||||
local tid=$1
|
||||
local hostSources=${@:2}
|
||||
for i in "${hostSources}"; do
|
||||
hostSource+="-host-source $i "
|
||||
done
|
||||
|
||||
boundary targets add-host-sources $tid $hostSource
|
||||
}
|
||||
|
||||
function target_has_host_source_id_by_alias() {
|
||||
local tid=$1
|
||||
local format=$2
|
||||
local hostSources=${@:3}
|
||||
|
||||
if [[ "$format" == "json" ]]; then
|
||||
ids=$(boundary targets read $tid -format json | jq '.item.host_sources[].id')
|
||||
for i in "${hostSources}"; do
|
||||
local hsid=$i
|
||||
for id in $ids; do
|
||||
if [ $(strip "$id") == "$hsid" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
return 1
|
||||
elif [[ "$format" == "table" ]]; then
|
||||
for i in "${hostSources}"; do
|
||||
pattern="Host Sources:.*ID:.*$i*"
|
||||
OUTPUT=$(boundary targets read $tid -format table)
|
||||
if ! [[ $OUTPUT =~ $pattern ]]; then
|
||||
echo "Host source id '$i' not found on target"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
Reference in new issue
Block a user