-
Notifications
You must be signed in to change notification settings - Fork 1
/
agreements-deleteall
executable file
·46 lines (32 loc) · 1.74 KB
/
agreements-deleteall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
auth 2>/dev/null || authn 2>/dev/null
tenant=$(cat tenant)
okapi_url=$(cat okapi.url)
okapi_token=$(cat okapi.token)
all_agreements=""
offset=0
recsretrieved=100
while [[ $recsretrieved -eq 100 ]] ;do
apicall=$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/erm/sas?perPage=100&offset=$offset")
recsretrieved=$(echo ${apicall} |jq '. |length')
totalrecs=$(($offset + $recsretrieved))
printf "%s records retrieved\r" $totalrecs
all_agreements="${all_agreements}$(echo ${apicall} |jq .[])"
offset=$(($offset + 100))
done
agreement_arr=($(echo "${all_agreements}" |jq -r .id))
counter=1
totalrecs=${#agreement_arr[@]}
for agreement_uuid in ${agreement_arr[@]};do
## must GET each agreement, unlink orgs and licenses, before deleting
agreement=$(curl -s -w '\n' -X GET -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/erm/sas/${agreement_uuid}")
deleteId=$(echo ${agreement} |jq '.linkedLicenses[0].id')
name=$(echo ${agreement} |jq '.name')
echo "Processing ${name} -- ${agreement_uuid} : Record $counter of $totalrecs"
if [[ ${deleteId} =~ [0-9] ]];then
agreement=$(echo ${agreement} |jq ". | .linkedLicenses = [{\"id\":${deleteId},\"_delete\":true}]")
apicall=$(curl --http1.1 -s -w '\n' -X PUT -H "Content-type: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" -d "${agreement}" "${okapi_url}/erm/sas/${agreement_uuid}")
echo "Removing license for ${name}"
fi
curl -s -w '\n' -X DELETE -D -H "Accept: application/json" -H "X-Okapi-Tenant: ${tenant}" -H "x-okapi-token: ${okapi_token}" "${okapi_url}/erm/sas/${agreement_uuid}"
counter=$(($counter + 1))
done