Skip to content

Commit

Permalink
fix: added load permission script
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Mar 6, 2024
1 parent 3e7376d commit dcd73d9
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 25 deletions.
41 changes: 21 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
"@ngneat/falso": "^6.4.0",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"@onecx/accelerator": "^4.1.2",
"@onecx/integration-interface": "^4.1.2",
"@onecx/keycloak-auth": "^4.1.2",
"@onecx/portal-integration-angular": "^4.1.2",
"@onecx/portal-layout-styles": "^4.1.2",
"@onecx/accelerator": "^4.9.0",
"@onecx/integration-interface": "^4.9.0",
"@onecx/keycloak-auth": "^4.9.0",
"@onecx/portal-integration-angular": "^4.9.0",
"@onecx/portal-layout-styles": "^4.9.0",
"file-saver": "^2.0.5",
"i18n-iso-countries": "^7.6.0",
"ngx-color": "^8.0.3",
Expand Down
79 changes: 79 additions & 0 deletions scripts/load-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# relative paths to values.yaml and Chart.yaml
values_file="helm/values.yaml"
chart_file="helm/Chart.yaml"

array=()

if [ ! -f "$values_file" ]; then
echo "\"$values_file\" cannot be found - execute this script from product root directory"
exit 1
fi
if [ ! -f "$chart_file" ]; then
echo "\"$chart_file\" cannot be found - execute this script from product root directory"
exit 1
fi

extract_app_id_and_product_name() {
app_id=$(sed -n '2 s/^name: \([^ ]*\).*/\1/p' "$chart_file")
app_name=$(sed -n '4 s/description: //p' "$chart_file")
product_name=$(echo "$app_id" | sed 's/-ui$//')
echo "=> app id: $app_id"
echo "=> app name: $app_name"
echo "=> product name: $product_name"
}

find_permissions() {
while IFS= read -r line; do
if [[ "$line" == *"permissions:"* ]]; then
permissions_spaces=$(echo "$line" | grep -oE '^[[:space:]]*' | wc -c)

while IFS= read -r next_line; do
next_spaces=$(echo "$next_line" | grep -oE '^[[:space:]]*' | wc -c)

if (( next_spaces <= permissions_spaces )); then
break
fi
if (( next_spaces == permissions_spaces + 2 )); then
current_key=$(echo "$next_line" | tr -d ':' | tr -d ' ')
elif (( next_spaces == permissions_spaces + 4 )); then
value=$(echo "$next_line" | awk -F ':' '{print $1}' | tr -d ' ')
description=$(echo "$next_line" | awk -F ':' '{$1=""; print $0}' | sed 's/^ *//')
echo -e "Key: $current_key \t Value: $value \t Description: $description"
array+=( "{\"resource\":\"$current_key\",\"action\":\"$value\",\"description\":\"$description\"}" )
fi
done < <(sed -n "/permissions:/,/^$/p" "$values_file" | tail -n +2)
break
fi
done < "$values_file"
}

create_json() {
permissions_json="{"
permissions_json+="\"name\": \"$app_name\","
permissions_json+="\"description\": \"local permission import\","
permissions_json+="\"permissions\":["

for ((i = 0; i < ${#array[@]}; i++)); do
permissions_json+="${array[i]}"
if ((i < ${#array[@]} - 1)); then
permissions_json+=","
fi
done

permissions_json+="]"
permissions_json+="}"
}

send_permission_to_svc() {
echo "=> send permissions to service"
curl -v -X PUT -H "Content-Type: application/json" -d "$permissions_json" \
http://onecx-permission-svc/operator/v1/$product_name/$app_id
}

extract_app_id_and_product_name
find_permissions
create_json
send_permission_to_svc
exit 0

0 comments on commit dcd73d9

Please sign in to comment.