-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathabaco-submit.sh
executable file
·94 lines (79 loc) · 2.19 KB
/
abaco-submit.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
THIS=$(basename $0)
THIS=${THIS%.sh}
THIS=${THIS//[-]/ }
HELP="
Usage: ${THIS} [OPTION]... [ACTORID]
Executes the actor with provided ID and returns execution ID. Message (-m)
is required and can be string or JSON.
Options:
-h show help message
-z api access token
-m value of actor env variable $MSG
-q query string to pass to actor env
-v verbose output
-V very verbose output
"
# function usage() { echo "$0 usage:" && grep " .)\ #" $0; exit 0; }
function usage() { echo "$HELP"; exit 0; }
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/abaco-common.sh"
tok=
while getopts ":hm:q:vz:V" o; do
case "${o}" in
z) # custom token
tok=${OPTARG}
;;
m) # msg to pass to actor environment as $MSG
msg=${OPTARG}
;;
q) # query string to pass to actor environment
query=${OPTARG}
;;
v) # verbose
verbose="true"
;;
V) # verbose
very_verbose="true"
;;
h | *) # print help text
usage
;;
esac
done
shift $((OPTIND-1))
if [ ! -z "$tok" ]; then TOKEN=$tok; fi
if [[ "$very_verbose" == "true" ]];
then
verbose="true"
fi
actor="$1"
if [ -z "$actor" ]; then
echo "Please give an actor ID at the end of the command"
usage
fi
if [ -z "$msg" ]; then
echo "Please give a message (eg. "execute yourself") with the -m flag."
usage
fi
# check if $msg is JSON; if so, add JSON header
if $(is_json "$msg"); then
curlCommand="curl -sk -H \"Authorization: Bearer $TOKEN\" -X POST -H \"Content-Type: application/json\" -d '$msg' '$BASE_URL/actors/v2/${actor}/messages?${query}'"
else
msg="$(single_quote "$msg")"
curlCommand="curl -sk -H \"Authorization: Bearer $TOKEN\" -X POST --data \"message=${msg}\" '$BASE_URL/actors/v2/${actor}/messages?${query}'"
fi
function filter() {
local output="$(eval $@ | jq -r '.result')"
echo $output | jq -r '.executionId'
echo $output | jq -r '.msg'
}
if [[ "$very_verbose" == "true" ]];
then
echo "Calling $curlCommand"
fi
if [[ "$verbose" == "true" ]]; then
eval $curlCommand
else
filter $curlCommand
fi