forked from jkroepke/helm-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdec.sh
59 lines (42 loc) · 1.28 KB
/
dec.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
#!/usr/bin/env sh
set -euf
dec_usage() {
cat <<EOF
helm secrets dec [ --driver <driver> | -d <driver> ] <path to file>
Decrypt secrets
It uses your gpg credentials to decrypt previously encrypted .yaml file.
Produces ${DEC_SUFFIX} file.
You can use plain sops to decrypt specific files - https://github.com/mozilla/sops
Typical usage:
$ helm secrets dec secrets/myproject/secrets.yaml
$ vim secrets/myproject/secrets.yaml.dec
EOF
}
decrypt_helper() {
encrypted_file_path="${1}"
if ! driver_is_file_encrypted "${encrypted_file_path}"; then
return 1
fi
encrypted_file_dec="$(_file_dec_name "${encrypted_file_path}")"
if ! driver_decrypt_file "yaml" "${encrypted_file_path}" "${encrypted_file_dec}"; then
printf '[helm-secrets] Error while decrypting file: %s\n' "${file}"
exit 1
fi
return 0
}
dec() {
if is_help "$1"; then
dec_usage
return
fi
file="$1"
printf '[helm-secrets] Decrypting %s\n' "${file}"
if ! encrypted_file_path=$(_file_get "${file}"); then
printf '[helm-secrets] File does not exist: %s\n' "${file}"
exit 1
fi
if ! decrypt_helper "${encrypted_file_path}"; then
printf '[helm-secrets] File is not encrypted: %s\n' "${file}"
exit 1
fi
}