feat(common): add sealed secrets script
Some checks failed
Check Kubernetes YAMLs / scan (push) Failing after 17s

This commit is contained in:
Lee 2024-09-23 22:29:21 +01:00
parent 61fb1964c6
commit a627d8ced3

30
common/seal-secret.sh Normal file
View File

@ -0,0 +1,30 @@
#!/bin/bash
# Function to seal a Kubernetes secret
seal_secret() {
local input_file="$1"
if [[ -z "$input_file" ]]; then
echo "Usage: seal <path-to-secret-file>"
exit 1
fi
if [[ ! -f "$input_file" ]]; then
echo "Error: File '$input_file' does not exist."
exit 1
fi
local output_file="$(dirname "$input_file")/sealed-$(basename "$input_file")"
echo "Sealing secret from '$input_file'..."
kubeseal --format=yaml < "$input_file" > "$output_file"
if [[ $? -eq 0 ]]; then
echo "Success! Sealed secret created at '$output_file'"
else
echo "Error: Failed to seal the secret."
exit 1
fi
}
# Call the function with the provided argument
seal_secret "$1"