Skip to content
Snippets Groups Projects

[#15] Modification of scripts for adding/removing groups to projects and wrapper script

Merged [#15] Modification of scripts for adding/removing groups to projects and wrapper script
Merged Christina Petala requested to merge modify_group_scripts into master
3 files
+ 51
6
Compare changes
  • Side-by-side
  • Inline
Files
3
#!/bin/bash
usage() { echo "Usage: $0 [--group-name <GROUP> --project <PROJECT>]" 1>&2; exit 1; }
KUBECONFIG=~/.kube/config
# Options
ARGS=$(getopt -o 'g:p:' --long 'group-name:project:' -- "$@") || exit 1
eval "set -- $ARGS"
@@ -35,15 +38,30 @@ ROLE_ID=$(echo $ROLE_LIST | jq -r '.data[] | select(.name=="administrator") | .i
GROUP_EXISTS=$(curl --silent -X GET "${AUTHZAPI_URL}/${AUTHZAPI_VERSION}/Group/${GROUP_NAME}" -H "accept: text/plain" -H "Authorization: Bearer ${BEARER_TOKEN}" -d "" -o /dev/null -w "%{http_code}")
if [[ $GROUP_EXISTS != "200" ]]; then
echo "Error trying to find group in API, error code: ${GROUP_EXISTS}"
exit 1
fi
# Add group ${GROUP_NAME} to ${ROLE_ID} (administrator) in ${APPLICATION_ID}, as per https://authorization-service-api.web.cern.ch/swagger/index.html#operations-Application-post_api_v1_0_Application__id__roles__roleid__groups__groupid_
SUCCESS=$(curl --silent -X POST "${AUTHZAPI_URL}/${AUTHZAPI_VERSION}/Application/${APPLICATION_ID}/roles/${ROLE_ID}/groups/${GROUP_NAME}" -H "accept: text/plain" -H "Authorization: Bearer ${BEARER_TOKEN}" -d "" -o /dev/null -w "%{http_code}")
if [[ $SUCCESS != "200" ]]; then
echo "Error binding group to admin role, error code: ${SUCCESS}"
SUCCESS=$(curl --silent -X POST "${AUTHZAPI_URL}/${AUTHZAPI_VERSION}/Application/${APPLICATION_ID}/roles/${ROLE_ID}/groups/${GROUP_NAME}" -H "accept: text/plain" -H "Authorization: Bearer ${BEARER_TOKEN}" -d "" -i > /tmp/report.txt -w "%{http_code}")
DUPLICATE=$(grep -irn "Duplicate" /tmp/report.txt | awk -F ":" '{print $3}' | awk -F " " '{print $1}'| tr -d '"')
if [[ $SUCCESS != 200 ]]; then
if [[ -z "$DUPLICATE" ]]; then
echo "Successfully binded ${GROUP_NAME} to applicationID ${APPLICATION_ID}"
exit 1
fi
if [[ $DUPLICATE != "Duplicate" ]]; then
echo "http error - Please read /tmp/report.txt file"
exit 1
fi
else
echo "Successfully binded ${GROUP_NAME} to applicationID ${APPLICATION_ID}"
exit 1
fi
echo "Successfully binded ${GROUP_NAME} to applicationID ${APPLICATION_ID}"
Loading