-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuploader.sh
More file actions
executable file
·102 lines (81 loc) · 1.66 KB
/
uploader.sh
File metadata and controls
executable file
·102 lines (81 loc) · 1.66 KB
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
#!/usr/bin/env bash
readonly DEFAULT_VERSION="v1"
readonly MANDATORY_ARG=(
"API_SERVER"
"PORT"
"NAME"
"ADDR"
"PRE_RUN"
"MAIN"
"LEFT_BRANCH"
"RIGHT_BRANCH"
)
readonly OPTIONAL_ARG=(
"VERSION"
)
readonly help_usage=\
"usage: $0 [CONFIG_FILE]
CONFIG_FILE: a file contains lines of [NAME]=[VALUE]
NAME: should be one of these:
mandatory:
${MANDATORY_ARG[*]}
optional:
${OPTIONAL_ARG[*]}
VALUE: string"
readonly help_config_missing=\
"config file is missing:"
readonly help_var_undefined=\
"var is missing:"
readonly help_version_undefined=\
"VERSION is missing, use default: $DEFAULT_VERSION"
readonly help_file_missing=\
"file is missing: "
if [ $# != 1 ]; then
echo "$help_usage"
exit 255
fi
conf="$1"
if [ ! -e "$conf" ]; then
echo "$help_config_missing $conf"
exit 255
fi
source $conf
for arg in "${MANDATORY_ARG[@]}" ; do
if [ ! -v "$arg" ]; then
echo "$help_var_undefined $arg"
exit 255
fi
done
if [ ! -v VERSION ]; then
echo "$help_version_undefined"
VERSION=$DEFAULT_VERSION
fi
readonly FILES=(
"$PRE_RUN"
"$MAIN"
)
for file in "${FILES[@]}" ; do
if [ ! -e "$file" ]; then
echo "$help_file_missing $file"
exit 255
fi
done
data=\
"{
\"apiVersion\": \"$VERSION\",
\"kind\": \"Func\",
\"metadata\": {
\"name\": \"$NAME\",
\"namespace\": \"default\"
},
\"spec\": {
\"name\":\"$NAME\",
\"preRun\":\"$(base64 "$PRE_RUN"| tr -d '\n')\",
\"function\":\"$(base64 "$MAIN"| tr -d '\n')\",
\"left\":\"$LEFT_BRANCH\",
\"right\":\"$RIGHT_BRANCH\",
\"serviceAddress\":\"$ADDR\"
}
}"
curl -X POST "$API_SERVER:$PORT/api/funcs/template/" --data "$data"
echo