-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.sh
executable file
·54 lines (51 loc) · 958 Bytes
/
encrypt.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
#!/bin/bash
usage() {
echo "Usage $0 " \
"[--profile <aws-profile>] " \
"[--key <key-id>] " \
"[--output <output-file>] " \
"[<input-file>] " \
>&2
}
aws_opts=()
input_file=
output_file=
key_id='alias/secrets'
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--help|help|-h)
usage
exit 3
;;
--profile|-p)
aws_opts+=(--profile "$2")
shift
;;
--key|-k)
key_name="$2"
shift
;;
--output|-o)
output_file="$2"
shift
;;
*)
if [ "$input_file" = "" ]; then
input_file="$1"
else
echo "Unrecognized option '${key}'" >&2
usage
exit 2
fi
;;
esac
shift
done
input_file="${input_file:-/dev/stdin}"
cat "$input_file" | \
aws ${aws_opts[@]} kms encrypt \
--key-id ${key_id} \
--plaintext file:///dev/stdin\
--query CiphertextBlob \
--output text > "${output_file:-/dev/stdout}"