forked from jkroepke/helm-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenc.sh
71 lines (54 loc) · 1.48 KB
/
enc.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
#!/usr/bin/env sh
set -euf
enc_usage() {
cat <<EOF
helm secrets enc [ --driver <driver> | -d <driver> ] <path to file>
Encrypt secrets
It uses your gpg credentials to encrypt .yaml file. If the file is already
encrypted, look for a decrypted ${DEC_SUFFIX} file and encrypt that to .yaml.
This allows you to first decrypt the file, edit it, then encrypt it again.
You can use plain sops to encrypt - https://github.com/mozilla/sops
Example:
$ helm secrets enc <SECRET_FILE_PATH>
$ git add <SECRET_FILE_PATH>
$ git commit
$ git push
EOF
}
encrypt_helper() {
dir=$(dirname "$1")
file=$(basename "$1")
cd "$dir"
if [ ! -f "${file}" ]; then
printf 'File does not exist: %s\n' "${dir}/${file}"
exit 1
fi
file_dec="$(_file_dec_name "${file}")"
if [ ! -f "${file_dec}" ]; then
file_dec="${file}"
fi
if driver_is_file_encrypted "${file_dec}"; then
printf "Already encrypted: %s\n" "${file_dec}"
exit 1
fi
driver_encrypt_file "yaml" "${file_dec}" "${file}"
if [ "${file}" = "${file_dec}" ]; then
printf 'Encrypted %s\n' "${file_dec}"
else
printf 'Encrypted %s to %s\n' "${file_dec}" "${file}"
fi
}
enc() {
if is_help "$1"; then
enc_usage
return
fi
file="$1"
if [ ! -f "${file}" ]; then
printf 'File does not exist: %s\n' "${file}"
exit 1
else
printf 'Encrypting %s\n' "${file}"
encrypt_helper "${file}"
fi
}