Files
threshold/internal/tests/cli/boundary/_roles.bash
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
2.0 KiB
Bash
Raw Normal View History

load _authorized_actions
2020-10-12 20:57:57 -07:00
function create_role() {
local sid=$1
local name=$2
local gsid=$3
2023-02-01 20:54:08 +00:00
2020-10-12 20:57:57 -07:00
boundary roles create \
-scope-id $sid \
-name $name \
-description 'test role' \
-grant-scope-id $gsid
}
function read_role() {
boundary roles read -id $1 -format json
}
function delete_role() {
2023-02-01 20:54:08 +00:00
boundary roles delete -id $1 -format json
2020-10-12 20:57:57 -07:00
}
function list_roles() {
boundary roles list -scope-id $1 -format json
}
function assoc_role_grant() {
local grant=$1
local id=$2
2023-02-01 20:54:08 +00:00
2020-10-12 20:57:57 -07:00
boundary roles add-grants -grant $grant -id $id
}
function assoc_role_principal() {
local principal=$1
local id=$2
2023-02-01 20:54:08 +00:00
boundary roles add-principals -principal $principal -id $id
2020-10-12 20:57:57 -07:00
}
function remove_role_grant() {
local grant=$1
local id=$2
2023-02-01 20:54:08 +00:00
2020-10-12 20:57:57 -07:00
boundary roles remove-grants -grant $grant -id $id
}
function remove_role_principal() {
local principal=$1
local id=$2
2023-02-01 20:54:08 +00:00
2020-10-12 20:57:57 -07:00
boundary roles remove-principals -principal $principal -id $id
}
function role_id() {
local name=$1
local sid=$2
2021-02-25 12:43:17 -05:00
strip $(list_roles $sid | jq -c ".items[] | select(.name | contains(\"$name\")) | .[\"id\"]")
2020-10-12 20:57:57 -07:00
}
function role_principal_ids() {
local rid=$1
2023-02-01 20:54:08 +00:00
strip $(read_role $rid | jq '.item["principals"][]["id"]')
2020-10-12 20:57:57 -07:00
}
function role_has_principal_id() {
local rid=$1
local pid=$2
local ids=$(role_principal_ids $rid)
for id in $ids; do
if [ $(strip "$id") == "$pid" ]; then
2023-02-01 20:54:08 +00:00
return 0
2020-10-12 20:57:57 -07:00
fi
done
2023-02-01 20:54:08 +00:00
return 1
2020-10-12 20:57:57 -07:00
}
function role_grants() {
local rid=$1
2021-02-25 12:43:17 -05:00
read_role $rid | jq -rc '.item.grant_strings | @sh'
2020-10-12 20:57:57 -07:00
}
function role_has_grant() {
local rid=$1
local g=$2
local hasgrants=$(role_grants $rid)
for grant in $hasgrants; do
if [ $(strip_all "$grant") == "$g" ]; then
2023-02-01 20:54:08 +00:00
return 0
2020-10-12 20:57:57 -07:00
fi
done
2023-02-01 20:54:08 +00:00
return 1
2020-10-12 20:57:57 -07:00
}
function has_default_role_actions() {
local out=$1
local actions=('read' 'update' 'delete' 'add-principals' 'set-principals' 'remove-principals' 'add-grants' 'set-grants' 'remove-grants')
for action in ${actions[@]}; do
$(has_authorized_action "$out" "$action") || {
echo "failed to find $action action in output: $out"
2023-02-01 20:54:08 +00:00
return 1
}
done
}