aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/wm-request
blob: 618da62ff2708b0f60f99899d7bad896726622e3 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

if ! [ "$1" ]
then
   echo "Usage: $0 VERB [ARGS]" >&2
   exit 1
fi

for i in uuidgen curl
do
   which $i 2>/dev/null 1>&2 || { echo "Program $i is missing" >&2; exit 1; }
done

set -eu

if which python 2>/dev/null 1>&2 && echo '{ "test": "1" }' | python -m json.tool 2>/dev/null 1>&2
then
   if which pygmentize 2>/dev/null 1>&2
   then
      json_pretty() {
         python -m json.tool | pygmentize -l json
      }
   else
      json_pretty() {
         python -m json.tool
      }
   fi
else
   json_pretty() {
      cat
   }
fi

verb=$1
shift

args=""
for i in "$@"
do
   args="$i"
done

if [ "$args" ]
then
   args="?$args"
fi

UUIDFILE=/tmp/wm-request-uuid
if ! [ -f $UUIDFILE ]
then
   uuidgen > $UUIDFILE
fi
UUID="`cat $UUIDFILE`"

curl -H "x-afb-uuid: $UUID" -s http://localhost:1234/api/winman/${verb}${args} | json_pretty

# vim:set ft=sh: