init
This commit is contained in:
parent
92236209d1
commit
e56bea4b0f
4 changed files with 102 additions and 0 deletions
39
cleanup.d/delete_devices
Executable file
39
cleanup.d/delete_devices
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
token_path="$1"
|
||||
base_url="$2"
|
||||
verbose="true"
|
||||
|
||||
warn() {
|
||||
echo "WARN: $@" >&2
|
||||
}
|
||||
log() {
|
||||
if [[ "$verbose" == "true" ]]; then
|
||||
echo "LOG: $@" >&2
|
||||
fi
|
||||
}
|
||||
invoke_req() {
|
||||
log "invoke curl $@"
|
||||
curl -s --header "@${token_path}" --max-time 600 --connect-timeout 600 $@
|
||||
return $?
|
||||
}
|
||||
|
||||
ec=0
|
||||
|
||||
log "starting device cleanup - api url: ${base_url}"
|
||||
|
||||
for user_id in `invoke_req -X GET "${base_url}v2/users" | jq -r '.users[]|.name'`; do
|
||||
log "processing user ${user_id}"
|
||||
for device in `invoke_req -X GET "${base_url}v2/users/${user_id}/devices" | jq -r '.devices|sort_by(.last_seen_ts)[0:-5][]|.device_id'`; do
|
||||
warn "deleting device ${user_id}/${device}"
|
||||
#resp=$(invoke_req -X DELETE "${base_url}v2/users/${user_id}/devices/${device}")
|
||||
#rc=$?
|
||||
#if [[ "$resp" != "{}" ]]; then
|
||||
# ec=$rc
|
||||
# echo "Deletion of device '${user_id}/devices/${device}' failed:" >&2
|
||||
# echo "$resp" | jq '.' >&2
|
||||
#fi
|
||||
done
|
||||
done
|
||||
|
||||
exit $ec
|
Loading…
Add table
Add a link
Reference in a new issue