WIP: app secret rm

This commit is contained in:
Luke Murphy 2020-10-30 02:09:59 +01:00
parent 8d7194fcce
commit b15a214049
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

71
abra
View File

@ -25,7 +25,7 @@ Usage:
abra [options] app <domain> secret auto
abra [options] app <domain> secret generate <secret> <version> [<cmd>]
abra [options] app <domain> secret insert <secret> <version> <data>
abra [options] app <domain> secret (delete|rm) [<secret>] [--all] [--pass] [--force]
abra [options] app <domain> secret (delete|rm) [<secret>] [--all --pass --force]
abra [options] server add <host> [<user>] [<port>]
abra [options] server (list|ls)
abra [options] server rm <host>
@ -142,11 +142,11 @@ eval "var_$1+=($value)"; else eval "var_$1=$value"; fi; return 0; fi; done
return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() {
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1368}
usage=${DOC:40:1060}; digest=28b2a; shorts=(-h -e -s -v '' '' '' '' '' '')
longs=(--help --env --stack --version --server --domain --pass --force --user --all)
argcounts=(0 1 1 0 1 1 0 0 1 0); node_0(){ switch __help 0; }; node_1(){
value __env 1; }; node_2(){ value __stack 2; }; node_3(){ switch __version 3; }
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1364}
usage=${DOC:40:1056}; digest=afcff; shorts=(-v -s -h -e '' '' '' '' '' '')
longs=(--version --stack --help --env --server --domain --pass --force --user --all)
argcounts=(0 1 0 1 1 1 0 0 1 0); node_0(){ switch __version 0; }; node_1(){
value __stack 1; }; node_2(){ switch __help 2; }; node_3(){ value __env 3; }
node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
switch __pass 6; }; node_7(){ switch __force 7; }; node_8(){ value __user 8; }
node_9(){ switch __all 9; }; node_10(){ value _app_ a; }; node_11(){
@ -176,24 +176,23 @@ required 47 24 11 35 13 14; }; node_64(){ optional 8; }; node_65(){ oneormore 15
required 47 24 11 36 12 65; }; node_68(){ required 47 24 11 37 38; }; node_69(){
optional 18; }; node_70(){ required 47 24 11 37 39 16 17 69; }; node_71(){
required 47 24 11 37 40 16 17 19; }; node_72(){ optional 16; }; node_73(){
optional 9; }; node_74(){ optional 6; }; node_75(){
required 47 24 11 37 57 72 73 74 58; }; node_76(){ optional 21; }; node_77(){
optional 22; }; node_78(){ required 47 41 42 20 76 77; }; node_79(){
required 47 41 51; }; node_80(){ required 47 41 32 20; }; node_81(){
required 47 41 43 20; }; node_82(){ required 47 41 44 20; }; node_83(){
required 47 45; }; node_84(){ required 47 23 65; }; node_85(){
either 49 52 53 54 55 59 61 62 63 66 67 68 70 71 75 78 79 80 81 82 83 84; }
node_86(){ required 85; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1060}" >&2
exit 1; }'; unset var___help var___env var___stack var___version var___server \
optional 9 6 7; }; node_74(){ required 47 24 11 37 57 72 73; }; node_75(){
optional 21; }; node_76(){ optional 22; }; node_77(){ required 47 41 42 20 75 76
}; node_78(){ required 47 41 51; }; node_79(){ required 47 41 32 20; }
node_80(){ required 47 41 43 20; }; node_81(){ required 47 41 44 20; }
node_82(){ required 47 45; }; node_83(){ required 47 23 65; }; node_84(){
either 49 52 53 54 55 59 61 62 63 66 67 68 70 71 74 77 78 79 80 81 82 83; }
node_85(){ required 84; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1056}" >&2
exit 1; }'; unset var___version var___stack var___help var___env var___server \
var___domain var___pass var___force var___user var___all var__app_ \
var__domain_ var__service_ var__src_ var__dst_ var__args_ var__secret_ \
var__version_ var__cmd_ var__data_ var__host_ var__user_ var__port_ \
var__command_ var_app var_new var_list var_ls var_deploy var_undeploy \
var_config var_delete var_rm var_logs var_multilogs var_cp var_run var_secret \
var_auto var_generate var_insert var_server var_add var_use var_init var_upgrade
parse 86 "$@"; local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__help" \
"${prefix}__env" "${prefix}__stack" "${prefix}__version" "${prefix}__server" \
parse 85 "$@"; local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__version" \
"${prefix}__stack" "${prefix}__help" "${prefix}__env" "${prefix}__server" \
"${prefix}__domain" "${prefix}__pass" "${prefix}__force" "${prefix}__user" \
"${prefix}__all" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \
"${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" \
@ -204,10 +203,10 @@ parse 86 "$@"; local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__help" \
"${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \
"${prefix}secret" "${prefix}auto" "${prefix}generate" "${prefix}insert" \
"${prefix}server" "${prefix}add" "${prefix}use" "${prefix}init" \
"${prefix}upgrade"; eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__env=${var___env:-}'
"${prefix}upgrade"; eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__server=${var___server:-}'
eval "${prefix}"'__domain=${var___domain:-}'
eval "${prefix}"'__pass=${var___pass:-false}'
@ -245,8 +244,8 @@ eval "${prefix}"'add=${var_add:-false}'; eval "${prefix}"'use=${var_use:-false}'
eval "${prefix}"'init=${var_init:-false}'
eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__help" "${prefix}__env" "${prefix}__stack" \
"${prefix}__version" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \
declare -p "${prefix}__version" "${prefix}__stack" "${prefix}__help" \
"${prefix}__env" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \
"${prefix}__force" "${prefix}__user" "${prefix}__all" "${prefix}_app_" \
"${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
"${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" \
@ -593,7 +592,25 @@ sub_app_secret_delete(){
}
sub_app_secret_rm(){
echo "TODO"
NAMES=$(docker secret ls --filter "name=s1_${abra__secret_}" --format "{{.Name}}")
if [ -z "$NAMES" ]; then
error "Could not find any secrets under ${STACK_NAME}_${abra__secret_}"
fi
if [ "$abra___force" != "true" ]; then
warning "Delete $(echo $NAMES | paste -d "")?"
read -rp "Enter to continue, Ctrl+C to quit"
fi
for NAME in "${NAMES}"; do
docker secret rm "$NAME" > /dev/null
if [ "$abra___pass" == "true" ] && [ type pass > /dev/null 2>&1 ]; then
pass rm "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${abra__secret_}" > /dev/null
success "pass rm'd: hosts/$DOCKER_CONTEXT/${STACK_NAME}/${abra__secret_}"
fi
done
}
###### .. app <domain> secret generate
@ -859,6 +876,12 @@ abra() {
load_custom_commands
# Note(decentral1se): experimenting with subcmd parsing
if [ ${abra_app} ] && [ ${abra_secret} ] && [ ${abra_rm} ]; then
sub_app_secret_delete ${abra__args_[*]}
return
fi
# Search for sub_* functions, and check if any of them matches enabled
# arguments (i.e. is a command and is specified)
for SUBCOMMAND in $(declare -Ff | grep 'sub_' | cut -d' ' -f3 | sort -r); do