summaryrefslogtreecommitdiffstats
path: root/cac
diff options
context:
space:
mode:
Diffstat (limited to 'cac')
-rwxr-xr-xcac38
1 files changed, 28 insertions, 10 deletions
diff --git a/cac b/cac
index d8600c5..f72a74f 100755
--- a/cac
+++ b/cac
@@ -47,7 +47,8 @@ sed '
}
#
-cac_cache=${cac_cache-$HOME/tmp/cac_listservers_cache.json}
+cac_servers_cache=${cac_servers_cache-$HOME/tmp/cac_servers_cache.json}
+cac_templates_cache=${cac_templates_cache-$HOME/tmp/cac_templates_cache.json}
cac_secrets=${cac_secrets-$HOME/.secrets/cac}
. "$cac_secrets" >/dev/null 2>&1 || :
@@ -82,17 +83,23 @@ __cac_cli__console() {(
#? Print cached listservers JSON.
#?
__cac_cli__listservers() {
- jq -r . $cac_cache
+ jq -r . $cac_servers_cache
}
#? cac update
-#? Fetch and cache listservers JSON.
+#? Fetch and cache servers and templates JSON.
#?
__cac_cli__update() {(
umask 0077
- servers=$(_cac_listservers)
- echo $servers > $cac_listservers_cache.tmp
- mv $cac_listservers_cache.tmp $cac_cache
+ for resource in servers templates; do
+ {
+ json=$(_cac_list$resource)
+ eval file=\$cac_${resource}_cache
+ echo $json | jq . > "$file".tmp
+ mv "$file".tmp "$file"
+ } &
+ done
+ wait
)}
#? cac getserver SERVERSPEC
@@ -123,7 +130,7 @@ __cac_cli__getserver() {(
null
end
' \
- $cac_cache); then
+ $cac_servers_cache); then
echo $result | jq -r .
else
echo "$0 getserver $k:$v => not unique server found" >&2
@@ -302,14 +309,14 @@ __cac_cli__waitstatus() {
}
-# XXX for __cac_cli__waitforcacheupdate and __cac_cli__poll cache means $cac_cache
+# XXX for __cac_cli__waitforcacheupdate and __cac_cli__poll cache means $cac_servers_cache
#? cac waitforcacheupdate COMMAND [ARGS...]
#? Blocks until cache has been updated then executes "$@".
#?
__cac_cli__waitforcacheupdate() {
- case $(inotifywait --format %f -q -e moved_to $(dirname $cac_cache)) in
- $(basename $cac_cache)) "$@";;
+ case $(inotifywait --format %f -q -e moved_to $(dirname $cac_servers_cache)) in
+ $(basename $cac_servers_cache)) "$@";;
*) __cac_cli__waitforcacheupdate "$@";;
esac
}
@@ -345,6 +352,17 @@ _cac_listservers() {(
fi
)}
+_cac_listtemplates() {(
+ servers=$(_cac_get_api_v1 listtemplates)
+ status=$(echo $servers | jq -r .status)
+
+ if [ "$status" = ok ]; then
+ echo "$servers" | jq -r .data
+ else
+ echo "cac_listtemplates: bad listtemplates status: $status" >&2
+ exit 1
+ fi
+)}