]> git.immae.eu Git - github/fretlink/ansible-rundeck-jobs.git/blob - files/fetch_keys.sh
Add an option to remove existing keys that are not declared in ansible
[github/fretlink/ansible-rundeck-jobs.git] / files / fetch_keys.sh
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 BASE_URL="$1"
6 TOKEN="$2"
7 BASE_PATH="$3"
8
9 list_path_rec() {
10 path="$1"
11 result=$(curl -ks "$BASE_URL/storage/$path?authtoken=$TOKEN")
12
13 case "$(echo "$result" | jq -r .type)" in
14 "file") echo "$result" | jq -r .path | sed -e "s@^$BASE_PATH/@@"
15 ;;
16 "directory")
17 echo "$result" | jq -r ".resources[]|.path" | while read p; do list_path_rec "$p"; done
18 ;;
19 esac
20 }
21
22 list_path_rec "$BASE_PATH"