forked from robinbryce/apikeystore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tusk.yml
127 lines (116 loc) · 3.7 KB
/
tusk.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
interpreter: bash -c
name: auth-apikeystore
usage: conveniences and ergonomics for auth-apikeystore
options:
address1:
default: "https://hoy.polysensus.io/auth-apikeystore"
#default: "http://127.0.0.1:8401"
address2:
default: "http://127.0.0.1:8401"
service:
default: "apibin.APIKeyStore"
method:
default: "Create"
verbose:
type: bool
default: false
short: "v"
verify:
type: bool
default: false
short: "K"
launchdir:
default:
command: echo $PWD
tasks:
create:
options:
display_name:
default:
command: echo $USER-$(date +%Y%m%d.%s)
short: "n"
aud:
default: "test audience"
scopes:
default: "rpc://eth_* rpc://net_* rpc://admin_nodeInfo"
run:
- command:
exec: |
set -e
OUTPUT=$(curl $(! ${verbose} && echo "-s") \
$(${verbose} && echo "-v") \
$(${verify} || echo "-k") \
-H "Content-Type: application/json" \
-d '{"display_name":"${display_name}","aud":"${aud}","scopes":"${scopes}"}' \
${address1}/clients)
! ${verbose} && echo -n "$OUTPUT" | jq -r .apikey && exit 0
echo $OUTPUT
get:
args:
client_id:
run:
- command:
exec: |
set -e
OUTPUT=$(curl $(! ${verbose} && echo "-s") \
$(${verbose} && echo "-v") \
$(${verify} || echo "-k") \
-H "Content-Type: application/json" \
${address1}/clients/${client_id})
! ${verbose} && echo -n "$OUTPUT" | jq -r . && exit 0
echo $OUTPUT
authz:
args:
key:
run:
- command:
exec: |
set -e
curl \
$(${verbose} && echo "-v") \
$(${noverify} && echo "-k") \
${address1}/access/${key}
create2:
options:
outdir:
default: "."
short: "o"
usage: "the directory to write the flatc bins to"
schema:
usage: "flatbuffer schema file (fbs)"
short: "s"
jsonfile:
default: "create.json"
short: "j"
run:
- command:
exec: |
set -e
# flatc -b api/apikeystore.fbs ${jsonfile}
# It is not possible to transcode json to binary on stdout. flatc
# insists on generating files. the c++ library can do it tho
#
VERBOSE=${verbose}
NOVERIFY=${noverify}
[ ! -f "${jsonfile}" ] && echo "json file \"${jsonfile}\" does not exist" && exit 1
export BASENAME=$(basename ${jsonfile} .json)
SCHEMA=${schema}
SCHEMA=${SCHEMA+api/$BASENAME.fbs}
[ ! -f "${SCHEMA}" ] && echo "schema file \"${SCHEMA}\" does not exist" && exit 1
flatc -o ${outdir} -b "${SCHEMA}" "${jsonfile}"
cat <<PYEND | python3 > ${outdir}/$BASENAME.req.bin
import os, sys, os.path
data = open(os.path.join("${outdir}", os.environ["BASENAME"] + ".bin"), "rb").read()
sys.stdout.buffer.write(bytes(1)) # write 0 byte - not compressed
sys.stdout.buffer.write(len(data).to_bytes(4, 'big'))
sys.stdout.buffer.write(data)
PYEND
cat ${outdir}/$BASENAME.req.bin \
| curl \
$(${verbose} && echo "-v") \
$(${noverify} && echo "-k") \
--http2-prior-knowledge --data-binary @- \
-H "Content-Type: application/grpc" \
-H "TE: trailers" ${address2}/${service}/${method} \
-so ${outdir}/$BASENAME.res.bin
xxd ${outdir}/$BASENAME.res.bin