-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun
executable file
·241 lines (208 loc) · 6.18 KB
/
run
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
set -e
DIR=$(cd `dirname $0` && pwd)
AVAILABLE_SDKS=("csharp dotnet java node php python ruby")
SELECTED_SDK=""
UPLOADS_DIR="${DIR}/file_uploads"
SERVER="api.hellosign.com"
DEV_MODE=0
main() {
while [ $# -gt 0 ]; do
case "$1" in
--sdk=*) SELECTED_SDK="${1#*=}"
;;
--sdk) SELECTED_SDK="${2#*}"
;;
--auth_type=*) AUTH_TYPE="${1#*=}"
;;
--auth_type) AUTH_TYPE="${2#*}"
;;
--auth_key=*) AUTH_KEY="${1#*=}"
;;
--auth_key) AUTH_KEY="${2#*}"
;;
--json=*) JSON="${1#*=}"
;;
--json) JSON="${2#*}"
;;
--server=*) SERVER="${1#*=}"
;;
--server) SERVER="${2#*}"
;;
--uploads_dir=*) UPLOADS_DIR="${1#*=}"
;;
--uploads_dir) UPLOADS_DIR="${2#*}"
;;
--dev_mode=*) DEV_MODE=1
;;
--dev_mode) DEV_MODE=1
;;
--help) show_help && exit 0
;;
esac
shift
done
# lowercase
# SELECTED_SDK="${SELECTED_SDK,,}"
if [[ "${SELECTED_SDK}" == "csharp" ]]; then
SELECTED_SDK="dotnet"
fi
validate_auth
validate_json_data
validate_uploads_dir
validate_selected_sdk
run_${SELECTED_SDK}
}
function show_help() {
cat << EOF
Uses the selected Dropbox Sign OpenAPI SDK to make a request to the Dropbox Sign API
--sdk one of "dotnet", "java", "node", "php", "python", "ruby"
(required)
--auth_type one of "apikey", "oauth"
(required)
--auth_key auth key
If --auth_type=apikey, pass API Key
If --auth_type=oauth, pass OAuth Bearer Token
(required)
--json valid JSON file containing all request data
OR base64-encoded JSON string
(required)
--server API server to use, must be like "api.hellosign.com".
(defaults to api.hellosign.com)
--uploads_dir directory where files that can be uploaded to the API live.
(defaults to ${DIR}/file_uploads)
--dev_mode run container in dev mode
(optional, default false)
--help display this help and exit
Example if using a JSON file:
./run \\
--sdk=php \\
--auth_type=apikey \\
--auth_key=4e0a8a8bd9fea228a1de515a43a75ded2e495471b830069cc8e1821c13c31ce4 \\
--json="\$PWD/test_fixtures/accountCreate-example_01.json"
Example if using a base64-encoded JSON string:
./run \\
--sdk=php \\
--auth_type=apikey \\
--auth_key=4e0a8a8bd9fea228a1de515a43a75ded2e495471b830069cc8e1821c13c31ce4 \\
--json="ewogICJvcGVyYXRpb25JZCI6ICJhY2NvdW50Q3JlYXRlIiwKICAicGFyYW1ldGVycyI6IHt9LAogICJkYXRhIjogewogICAgImVtYWlsX2FkZHJlc3MiOiAic2lnbmVyMUBoZWxsb3NpZ24uY29tIgogIH0sCiAgImZpbGVzIjoge30KfQo="
EOF
}
function validate_auth()
{
if [[ "${AUTH_TYPE}" != "apikey" &&
"${AUTH_TYPE}" != "oauth"
]]; then
printf "Invalid auth type (--auth_type) value: ${AUTH_TYPE}\n\n"
show_help
exit 1
fi
if [[ -z "${AUTH_KEY}" ]]; then
printf "Missing argument: --auth_key.\n\n"
show_help
exit 1
fi
}
function validate_json_data()
{
if [[ -z "${JSON}" ]]; then
printf "You must specify either a JSON file or a base64-encoded JSON string (--json)\n\n"
show_help
exit 1
fi
if [[ -f "${JSON}" ]]; then
JSON=$(cat "${JSON}" | base64)
fi
}
function validate_uploads_dir()
{
if [[ ! -d "${UPLOADS_DIR}" ]]; then
printf "Uploads directory does not exist: ${UPLOADS_DIR}\n\n"
show_help
exit 1
fi
}
function validate_selected_sdk()
{
if [[ ! " ${AVAILABLE_SDKS[*]} " =~ " ${SELECTED_SDK} " ]]; then
printf "Invalid SDK selected: ${SELECTED_SDK}\n"
show_help
exit 1
fi
}
function run_dotnet()
{
CONTAINER="docker.io/dropbox/sign-dotnet"
REQUESTER_FILE=""
CMD="dotnet run -v quiet --project /app/dropbox-sign-dotnet/sdk-tester/sdk-tester.csproj -- ${AUTH_TYPE} ${AUTH_KEY} ${SERVER} ${JSON} ${DEV_MODE}"
if [[ $DEV_MODE -eq 1 ]]; then
REQUESTER_FILE="-v ${DIR}/data_dotnet/Program.cs:/app/dropbox-sign-dotnet/sdk-tester/Program.cs"
fi
run_container
}
function run_java()
{
CONTAINER="docker.io/dropbox/sign-java"
REQUESTER_FILE=""
CMD="java -jar /app/target/dropbox-sign-sdk_tester-java-1.0-SNAPSHOT.jar"
if [[ $DEV_MODE -eq 1 ]]; then
REQUESTER_FILE="-v ${DIR}/data_java/Requester.java:/app/Requester.java"
CMD="bash /app/run-dev"
fi
run_container
}
function run_node()
{
CONTAINER="docker.io/dropbox/sign-node"
REQUESTER_FILE=""
CMD="npm run start --silent"
if [[ $DEV_MODE -eq 1 ]]; then
REQUESTER_FILE="-v ${DIR}/data_node/requester.ts:/app/requester.ts"
CMD="npm run dev --silent"
fi
run_container
}
function run_php()
{
CONTAINER="docker.io/dropbox/sign-php"
REQUESTER_FILE=""
CMD="php /app/requester.php"
if [[ $DEV_MODE -eq 1 ]]; then
REQUESTER_FILE="-v ${DIR}/data_php/requester.php:/app/requester.php"
fi
run_container
}
function run_python()
{
CONTAINER="docker.io/dropbox/sign-python"
REQUESTER_FILE=""
CMD="python /app/requester.py"
if [[ $DEV_MODE -eq 1 ]]; then
REQUESTER_FILE="-v ${DIR}/data_python/requester.py:/app/requester.py"
fi
run_container
}
function run_ruby()
{
CONTAINER="docker.io/dropbox/sign-ruby"
REQUESTER_FILE=""
CMD="bundle exec ruby /app/requester.rb"
if [[ $DEV_MODE -eq 1 ]]; then
REQUESTER_FILE="-v ${DIR}/data_ruby/requester.rb:/app/requester.rb"
fi
run_container
}
function run_container()
{
docker container run --rm \
-e AUTH_TYPE="${AUTH_TYPE}" \
-e AUTH_KEY="${AUTH_KEY}" \
-e API_SERVER="${SERVER}" \
-e JSON_DATA="${JSON}" \
-e DEV_MODE="${DEV_MODE}" \
-v ${UPLOADS_DIR}:"/file_uploads" \
${REQUESTER_FILE} \
${CONTAINER} ${CMD}
}
main "$@";
exit