|
|
|
@ -124,18 +124,17 @@ function main(){
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# "anchor" for actions relevant to this script
|
|
|
|
# "anchor" for actions relevant to this script
|
|
|
|
repo_root="$(realpath $(dirname "${BASH_SOURCE[0]}")/..)"
|
|
|
|
repo_root="$(realpath $(dirname "${BASH_SOURCE[0]}")/..)"
|
|
|
|
|
|
|
|
|
|
|
|
# OPTIONS: ARGPARSING and VALIDATION
|
|
|
|
# OPTIONS: ARGPARSING and VALIDATION
|
|
|
|
# assume location of script as running directly from repo with keys (instead of as a standalone packaged tool)
|
|
|
|
# assume location of script as running directly from repo with keys (instead of as a standalone packaged tool)
|
|
|
|
keyfiles_dir="${repo_root}"
|
|
|
|
keyfiles_dir="${repo_root}"
|
|
|
|
# assume location of secrets config file in pwd
|
|
|
|
# dir containing .sops.yaml
|
|
|
|
sops_config_dir=""
|
|
|
|
sops_config_dir=""
|
|
|
|
# path to group definitions
|
|
|
|
# path to group definitions
|
|
|
|
groups_def_dir="${repo_root}/groups"
|
|
|
|
groups_def_dir="${repo_root}/groups"
|
|
|
|
# optional:
|
|
|
|
|
|
|
|
opt_list_groups=0
|
|
|
|
opt_list_groups=0
|
|
|
|
# optional: specify "groups"
|
|
|
|
|
|
|
|
groups_list=()
|
|
|
|
groups_list=()
|
|
|
|
# optional: secrets files to be updated
|
|
|
|
opt_find_secrets=0
|
|
|
|
secrets_file_list=()
|
|
|
|
secrets_file_list=()
|
|
|
|
|
|
|
|
|
|
|
|
while (( $# >= 1 ));do
|
|
|
|
while (( $# >= 1 ));do
|
|
|
|
@ -151,6 +150,8 @@ function main(){
|
|
|
|
-lg|--list_groups) opt_list_groups=1 ;;
|
|
|
|
-lg|--list_groups) opt_list_groups=1 ;;
|
|
|
|
# ARGS: [optional] [list] specify "groups" which correspond to e.g. job groups, projects, etc
|
|
|
|
# ARGS: [optional] [list] specify "groups" which correspond to e.g. job groups, projects, etc
|
|
|
|
-g|--group) groups_list+=( "${2}" ); shift ;;
|
|
|
|
-g|--group) groups_list+=( "${2}" ); shift ;;
|
|
|
|
|
|
|
|
# ARGS: [optional] update all "secrets.yaml" files found below .sops.yaml location
|
|
|
|
|
|
|
|
-f|--find_secrets) opt_find_secrets=1;;
|
|
|
|
# ARGS: [optional] [list] specify files containing sops-encrypted secrets
|
|
|
|
# ARGS: [optional] [list] specify files containing sops-encrypted secrets
|
|
|
|
-s|--secrets_file|-f|--file) secrets_file_list+=( "${2}" ); shift ;;
|
|
|
|
-s|--secrets_file|-f|--file) secrets_file_list+=( "${2}" ); shift ;;
|
|
|
|
# ARGS: [optional] [list] specify files containing sops-encrypted secrets
|
|
|
|
# ARGS: [optional] [list] specify files containing sops-encrypted secrets
|
|
|
|
@ -184,12 +185,22 @@ function main(){
|
|
|
|
# locate appropriate sops config if default assumption not found
|
|
|
|
# locate appropriate sops config if default assumption not found
|
|
|
|
# dev note: '2> /dev/null' to disable debug output
|
|
|
|
# dev note: '2> /dev/null' to disable debug output
|
|
|
|
sops_config="$(fn_sops_locate_config_in_git_repo 2> /dev/null)"
|
|
|
|
sops_config="$(fn_sops_locate_config_in_git_repo 2> /dev/null)"
|
|
|
|
|
|
|
|
sops_config_dir="$(dirname "${sops_config}")"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Paths to Secrets Files
|
|
|
|
if [[ "${#secrets_file_list[@]}" != "0" ]]; then
|
|
|
|
if [[ "${#secrets_file_list[@]}" != "0" ]]; then
|
|
|
|
for secrets_file in "${secrets_file_list[@]}"; do
|
|
|
|
for secrets_file in "${secrets_file_list[@]}"; do
|
|
|
|
test -e "${secrets_file}" || (echo "E: could not locate file with secrets, tried: ${secrets_file}" && exit 1)
|
|
|
|
test -e "${secrets_file}" || (echo "E: could not locate file with secrets, tried: ${secrets_file}" && exit 1)
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${opt_find_secrets}" -eq 1 ]]; then
|
|
|
|
|
|
|
|
# DEV NOTE: this is far too complicated
|
|
|
|
|
|
|
|
# loop through find, src: https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find
|
|
|
|
|
|
|
|
while IFS= read -r -d $'\0'; do
|
|
|
|
|
|
|
|
secrets_file_list+=("${REPLY}")
|
|
|
|
|
|
|
|
done < <( find "${sops_config_dir}" -name secrets.yaml -print0 )
|
|
|
|
|
|
|
|
fi
|
|
|
|
# /VALIDATE INPUTS
|
|
|
|
# /VALIDATE INPUTS
|
|
|
|
# /OPTIONS: ARGPARSING and VALIDATION
|
|
|
|
# /OPTIONS: ARGPARSING and VALIDATION
|
|
|
|
|
|
|
|
|
|
|
|
|