-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmessaging
executable file
·51 lines (39 loc) · 1.21 KB
/
messaging
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
#!/usr/bin/env bash
set -o errexit
qos=0
output=silent # silent or verbose
source ./settings.sh # configuration
source ./localutils.sh # getservicekey getval gettoken
source ./messaging.sh # messaging API functions
main() {
local qos=0
local command=$1
local functions
functions=$(messaging_functions)
# Either we're being asked to list the functions (for bash completion)
# or a function is being invoked.
case $command in
completion | "")
echo "$functions"
;;
*)
# TODO make this check more accurate
if [[ ! "$functions" =~ $command ]]; then
err Command \""$command"\" is not recognised
exit 1
fi
shift
# Retrieve service key and parse out relevant sections.
sk=$(getservicekey "$instance" "$servicekey")
messaging=$(getval "$sk" "(.credentials//.).messaging")
httprest=$(getval "$messaging" '.[] | select(.broker.type == "saprestmgw")')
# Determine API call details for MESSAGING-HTTPREST incl OAuth 2.0 token
uri=$(getval "$httprest" .uri)
oauth=$(getval "$httprest" .oa2)
token=$(gettoken "$oauth")
# Now we can run the requested command
$command "$@"
;;
esac
}
main "$@"