forked from jkroepke/helm-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·259 lines (227 loc) · 6.45 KB
/
run.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env sh
set -euf
if [ "${HELM_DEBUG:-}" = "1" ] || [ "${HELM_DEBUG:-}" = "true" ] || [ -n "${HELM_SECRETS_DEBUG+x}" ]; then
set -x
fi
# Path to current directory
SCRIPT_DIR="${HELM_PLUGIN_DIR}/scripts"
# shellcheck source=scripts/lib/common.sh
. "${SCRIPT_DIR}/lib/common.sh"
# shellcheck source=scripts/lib/expand_vars_strict.sh
. "${SCRIPT_DIR}/lib/expand_vars_strict.sh"
# shellcheck source=scripts/lib/file.sh
. "${SCRIPT_DIR}/lib/file.sh"
# shellcheck source=scripts/lib/backend.sh
. "${SCRIPT_DIR}/lib/backend.sh"
# shellcheck source=scripts/lib/http.sh
. "${SCRIPT_DIR}/lib/http.sh"
# Make sure HELM_BIN is set (normally by the helm command)
HELM_BIN="${HELM_SECRETS_HELM_PATH:-"${HELM_BIN:-helm}"}"
if on_cygwin; then
HELM_BIN="$(cygpath -u "${HELM_BIN}")"
fi
# Create a base temporary directory
TMPDIR="${HELM_SECRETS_DEC_TMP_DIR:-"$(mktemp -d)"}"
export TMPDIR
mkdir -p "${TMPDIR}"
# Output debug infos
if [ -n "${ARGOCD_APP_NAME+x}" ]; then
QUIET="${HELM_SECRETS_QUIET:-true}"
else
QUIET="${HELM_SECRETS_QUIET:-false}"
fi
# Define the secret backend
SECRET_BACKEND="${HELM_SECRETS_BACKEND:-sops}"
# Define the secret backend custom args
SECRET_BACKEND_ARGS="${HELM_SECRETS_BACKEND_ARGS:-}"
# The suffix to use for decrypted files. The default can be overridden using
# the HELM_SECRETS_DEC_SUFFIX environment variable.
# shellcheck disable=SC2034
DEC_PREFIX="${HELM_SECRETS_DEC_PREFIX-}"
# shellcheck disable=SC2034
DEC_SUFFIX="${HELM_SECRETS_DEC_SUFFIX-.dec}"
# shellcheck disable=SC2034
DEC_DIR="${HELM_SECRETS_DEC_DIR:-}"
# shellcheck disable=SC2034
IGNORE_MISSING_VALUES="${HELM_SECRETS_IGNORE_MISSING_VALUES:-false}"
# shellcheck disable=SC2034
EVALUATE_TEMPLATES="${HELM_SECRETS_EVALUATE_TEMPLATES:-false}"
# shellcheck disable=SC2034
EVALUATE_TEMPLATES_DECODE_SECRETS="${HELM_SECRETS_EVALUATE_TEMPLATES_DECODE_SECRETS:-false}"
# shellcheck disable=SC2034
LOAD_GPG_KEYS="${HELM_SECRETS_LOAD_GPG_KEYS:-false}"
trap _trap EXIT
trap 'trap - EXIT; _trap; exit 1' HUP INT QUIT TERM
load_secret_backend "${SECRET_BACKEND}"
DEFAULT_SECRET_BACKEND="${SECRET_BACKEND}"
if [ "${LOAD_GPG_KEYS}" != "false" ]; then
_gpg_load_keys
fi
if [ -n "${HELM_SECRET_WSL_INTEROP+x}" ]; then
shift
argc=$#
j=0
while [ $j -lt $argc ]; do
case "$1" in
*\\*)
set -- "$@" "$(wslpath "$(printf '%s' "$1" | tr "\\" '/')")"
;;
*)
set -- "$@" "$1"
;;
esac
shift
j=$((j + 1))
done
fi
while true; do
case "${1:-}" in
encrypt)
# shellcheck source=scripts/commands/encrypt.sh
. "${SCRIPT_DIR}/commands/encrypt.sh"
if [ $# -lt 2 ]; then
enc_usage
echo "Error: secrets file required."
exit 1
fi
shift
encrypt "$@"
break
;;
decrypt)
# shellcheck source=scripts/commands/decrypt.sh
. "${SCRIPT_DIR}/commands/decrypt.sh"
if [ $# -lt 2 ]; then
dec_usage
echo "Error: secrets file required."
exit 1
fi
shift
decrypt "$@"
break
;;
edit)
# shellcheck source=scripts/commands/edit.sh
. "${SCRIPT_DIR}/commands/edit.sh"
if [ $# -lt 2 ]; then
edit_usage
echo "Error: secrets file required."
exit 1
fi
edit "$2"
break
;;
dir)
_helm_winpath "$(dirname "${SCRIPT_DIR}")"
break
;;
post-renderer)
# shellcheck source=scripts/commands/downloader.sh
. "${SCRIPT_DIR}/commands/post-renderer.sh"
post_renderer
break
;;
downloader)
# shellcheck source=scripts/commands/downloader.sh
. "${SCRIPT_DIR}/commands/downloader.sh"
downloader "$2" "$3" "$4" "$5"
break
;;
patch)
# shellcheck source=scripts/commands/patch.sh
. "${SCRIPT_DIR}/commands/patch.sh"
patch "$2"
break
;;
--help | -h | help)
# shellcheck source=scripts/commands/help.sh
. "${SCRIPT_DIR}/commands/help.sh"
help_usage
break
;;
--version | -v | version)
# shellcheck source=scripts/commands/version.sh
. "${SCRIPT_DIR}/commands/version.sh"
version
break
;;
--backend | -b)
load_secret_backend "${2}"
DEFAULT_SECRET_BACKEND="${SECRET_BACKEND}"
shift
;;
--backend=*)
load_secret_backend "${1#*=}"
DEFAULT_SECRET_BACKEND="${SECRET_BACKEND}"
;;
--quiet | -q)
# shellcheck disable=SC2034
QUIET=true
;;
--backend-args | -a)
# shellcheck disable=SC2034
SECRET_BACKEND_ARGS="$2"
shift
;;
--backend-args=*)
# shellcheck disable=SC2034
SECRET_BACKEND_ARGS="${1#*=}"
;;
--ignore-missing-values)
if [ "$2" = "true" ] || [ "$2" = "false" ]; then
# shellcheck disable=SC2034
IGNORE_MISSING_VALUES="$2"
shift
else
# shellcheck disable=SC2034
IGNORE_MISSING_VALUES="true"
fi
;;
--ignore-missing-values=*)
# shellcheck disable=SC2034
IGNORE_MISSING_VALUES="${1#*=}"
;;
--evaluate-templates)
if [ "$2" = "true" ] || [ "$2" = "false" ]; then
# shellcheck disable=SC2034
EVALUATE_TEMPLATES="$2"
shift
else
# shellcheck disable=SC2034
EVALUATE_TEMPLATES="true"
fi
;;
--evaluate-templates=*)
# shellcheck disable=SC2034
EVALUATE_TEMPLATES="${1#*=}"
;;
--evaluate-templates-decode-secrets)
if [ "$2" = "true" ] || [ "$2" = "false" ]; then
# shellcheck disable=SC2034
EVALUATE_TEMPLATES_DECODE_SECRETS="$2"
shift
else
# shellcheck disable=SC2034
EVALUATE_TEMPLATES_DECODE_SECRETS="true"
fi
;;
--evaluate-templates-decode-secrets=*)
# shellcheck disable=SC2034
EVALUATE_TEMPLATES_DECODE_SECRETS="${1#*=}"
;;
"")
# shellcheck source=scripts/commands/help.sh
. "${SCRIPT_DIR}/commands/help.sh"
help_usage
exit 1
;;
*)
# shellcheck source=scripts/commands/helm.sh
. "${SCRIPT_DIR}/commands/helm.sh"
helm_command "$@"
break
;;
esac
shift
done
exit 0