refactor: args

ADP-179_sops_manage_keys
LeeW 11 months ago
parent c8c0187a18
commit 002982c4ac

@ -2,11 +2,33 @@
# Purpose: manage .sops.yaml based on gpg keys in the same dir _and_ verify correct configuration
set -euo pipefail
keyfiles_dir="$(realpath "${1?"E: specify dir containing keyfiles"}")"; shift;
sops_config_dir="$(realpath "${1?"E: specify dir containing .sops.yaml"}")"; shift;
sops_config="${sops_config_dir}/.sops.yaml"
# OPTIONS AND ARGPARSING
# assume location of script as running directly from repo with keys (instead of as a standalone packaged tool)
keyfiles_dir="$(realpath $(dirname "${BASH_SOURCE[0]}")/..)"
# assume location of secrets config file in pwd
sops_config_dir="${PWD}"
while (( $# >= 1 ));do
cur="${1}";
case $cur in
-k|--key|--keyfiles) keyfiles_dir="${2}"; shift ;;
-c|--config_dir) sops_config_dir="${2}"; shift ;;
esac
shift;
done
secrets_file="${1:-0}"
keyfiles_dir="$(realpath "${keyfiles_dir}")"
test -d "${keyfiles_dir}" || (echo "E: specify dir containing keyfiles; invalid dir: '${keyfiles_dir}'" && exit 1)
sops_config_dir="$(realpath "${sops_config_dir}")"
test -d "${sops_config_dir}" || (echo "E: specify dir containing .sops.yaml, invalid dir: '${sops_config_dir}'" && exit 1)
sops_config="${sops_config_dir}/.sops.yaml"
test -e "${sops_config}" || (echo "E: could not locate .sops.yaml, tried ${sops_config}" && exit 1)
if [[ "${secrets_file}" != "0" ]]; then
test -e "${secrets_file}" || (echo "E: could not locate .sops.yaml, tried ${secrets_file}" && exit 1)
fi
# /OPTIONS AND ARGPARSING
function fn_extract_fpr(){
gpgkeyfile=$1;shift;
# fingerprint

@ -10,4 +10,5 @@ secrets_file="mock_secrets.yaml"
test -e "${secrets_file}" || (yq -n '.demo.credentials.secret = "hunter2"' > "${secrets_file}" && sops -e -i "${secrets_file}" )
set -x
../bin/update_sops.sh "${keys_dir}" "${sops_cfg_dir}" "${secrets_file}"
# ../bin/update_sops.sh -k "${keys_dir}" -c "${sops_cfg_dir}" "${secrets_file}"
../bin/update_sops.sh "${secrets_file}"

Loading…
Cancel
Save