git-secret/src/commands/git_secret_removeperson.sh

52 lines
1.4 KiB
Bash
Raw Normal View History

2016-02-21 13:26:17 +00:00
#!/usr/bin/env bash
function removeperson {
OPTIND=1
2016-06-30 19:32:42 +00:00
while getopts 'h' opt; do
case "$opt" in
h) _show_manual_for 'removeperson';;
*) _invalid_option_for 'removeperson';;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
2016-02-21 13:26:17 +00:00
_user_required
# Command logic:
local emails=( "$@" )
if [[ ${#emails[@]} -eq 0 ]]; then
_abort "at least one email is required for removeperson."
2016-02-21 13:26:17 +00:00
fi
# Getting the local git-secret `gpg` key directory:
local secrets_dir_keys
secrets_dir_keys=$(_get_secrets_dir_keys)
_assert_keyring_contains_emails "$secrets_dir_keys" "git-secret keyring" "${emails[@]}"
for email in "${emails[@]}"; do
# see https://github.com/bats-core/bats-core#file-descriptor-3-read-this-if-bats-hangs for info about 3>&-
$SECRETS_GPG_COMMAND --homedir "$secrets_dir_keys" --no-permission-warning --batch --yes --delete-key "$email" 3>&-
2018-06-13 18:03:30 +00:00
local exit_code=$?
if [[ "$exit_code" -ne 0 ]]; then
2018-06-13 18:32:15 +00:00
_abort "problem deleting key for '$email' with gpg: exit code $exit_code"
2018-06-13 18:03:30 +00:00
fi
done
_message 'removed keys.'
_message "now [$*] do not have an access to the repository."
_message 'make sure to hide the existing secrets again.'
2016-02-21 13:26:17 +00:00
}
function killperson {
echo 'Warning: `killperson` has been renamed to `removeperson`. This alias will be removed in the future versions, please switch to call `removeperson` going forward.'
removeperson "$@"
}