-
-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·172 lines (147 loc) · 3.69 KB
/
run.sh
File metadata and controls
executable file
·172 lines (147 loc) · 3.69 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
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
#!/usr/bin/env sh
set -eu
# Path to current directory
SCRIPT_DIR="$(dirname "$0")"
# Output debug infos
QUIET="${HELM_SECRETS_QUIET:-false}"
# Define the secret driver engine
SECRET_DRIVER="${HELM_SECRETS_DRIVER:-sops}"
# The suffix to use for decrypted files. The default can be overridden using
# the HELM_SECRETS_DEC_SUFFIX environment variable.
DEC_SUFFIX="${HELM_SECRETS_DEC_SUFFIX:-.yaml.dec}"
DEC_DIR="${HELM_SECRETS_DEC_DIR:-}"
# Make sure HELM_BIN is set (normally by the helm command)
HELM_BIN="${HELM_BIN:-helm}"
usage() {
cat <<EOF
Secrets encryption in Helm Charts
This plugin provides ability to encrypt/decrypt secrets files
to store in less secure places, before they are installed using
Helm.
To decrypt/encrypt/edit you need to initialize/first encrypt secrets with
sops - https://github.com/mozilla/sops
Available Commands:
enc Encrypt secrets file
dec Decrypt secrets file
view Print secrets decrypted
edit Edit secrets file and encrypt afterwards
clean Remove all decrypted files in specified directory (recursively)
<cmd> wrapper that decrypts encrypted yaml files before running helm <cmd>
EOF
}
is_help() {
case "$1" in
-h | --help | help)
return 0
;;
*)
return 1
;;
esac
}
file_dec_name() {
if [ "${DEC_DIR}" != "" ]; then
printf '%s' "${DEC_DIR}/$(basename "${1}" ".yaml")${DEC_SUFFIX}"
else
printf '%s' "$(dirname "${1}")/$(basename "${1}" ".yaml")${DEC_SUFFIX}"
fi
}
load_secret_driver() {
driver="${1}"
if [ -f "${driver}" ]; then
# Allow to load out of tree drivers.
# shellcheck disable=SC1090
. "${driver}"
else
if [ ! -f "${SCRIPT_DIR}/drivers/${driver}.sh" ]; then
echo "Can't find secret driver: ${driver}"
exit 1
fi
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/drivers/${driver}.sh"
fi
}
load_secret_driver "$SECRET_DRIVER"
while true; do
case "${1:-}" in
enc)
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/commands/enc.sh"
if [ $# -lt 2 ]; then
enc_usage
echo "Error: secrets file required."
exit 1
fi
enc "$2"
break
;;
dec)
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/commands/dec.sh"
if [ $# -lt 2 ]; then
dec_usage
echo "Error: secrets file required."
exit 1
fi
dec "$2"
break
;;
view)
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/commands/view.sh"
if [ $# -lt 2 ]; then
view_usage
echo "Error: secrets file required."
exit 1
fi
view "$2"
break
;;
edit)
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/commands/edit.sh"
if [ $# -lt 2 ]; then
edit_usage
echo "Error: secrets file required."
exit 1
fi
edit "$2"
break
;;
clean)
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/commands/clean.sh"
if [ $# -lt 2 ]; then
clean_usage
echo "Error: Chart package required."
exit 1
fi
clean "$2"
break
;;
--help | -h | help)
usage
break
;;
--driver | -d)
load_secret_driver "$2"
shift
;;
--quiet | -q)
# shellcheck disable=SC2034
QUIET=true
;;
"")
usage
exit 1
;;
*)
# shellcheck disable=SC1090
. "${SCRIPT_DIR}/commands/helm.sh"
helm_command "$@"
break
;;
esac
shift
done
exit 0