Add --pass for new apps command

See coop-cloud/abra#25.
This commit is contained in:
Luke Murphy 2020-10-30 00:04:53 +01:00
parent dba3c391bd
commit 26b994ab84
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

144
abra
View File

@ -11,7 +11,7 @@ DOC="
The cooperative cloud utility belt 🎩🐇 The cooperative cloud utility belt 🎩🐇
Usage: Usage:
abra [options] app new [--server=<server> --domain=<domain>] <app> abra [options] app new [--server=<server> --domain=<domain> --pass] <app>
abra [options] app (list|ls) abra [options] app (list|ls)
abra [options] app <domain> deploy abra [options] app <domain> deploy
abra [options] app <domain> undeploy abra [options] app <domain> undeploy
@ -141,71 +141,73 @@ 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() { return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() {
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() { printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() { [[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1274} printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1281}
usage=${DOC:40:966}; digest=09ccb; shorts=(-h -e -v -s '' '' '' '') usage=${DOC:40:973}; digest=6d7dd; shorts=(-h -v -e -s '' '' '' '' '')
longs=(--help --env --version --stack --server --domain --force --user) longs=(--help --version --env --stack --server --domain --pass --force --user)
argcounts=(0 1 0 1 1 1 0 1); node_0(){ switch __help 0; }; node_1(){ argcounts=(0 0 1 1 1 1 0 0 1); node_0(){ switch __help 0; }; node_1(){
value __env 1; }; node_2(){ switch __version 2; }; node_3(){ value __stack 3; } switch __version 1; }; node_2(){ value __env 2; }; node_3(){ value __stack 3; }
node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){ node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
switch __force 6; }; node_7(){ value __user 7; }; node_8(){ value _app_ a; } switch __pass 6; }; node_7(){ switch __force 7; }; node_8(){ value __user 8; }
node_9(){ value _domain_ a; }; node_10(){ value _service_ a; }; node_11(){ node_9(){ value _app_ a; }; node_10(){ value _domain_ a; }; node_11(){
value _src_ a; }; node_12(){ value _dst_ a; }; node_13(){ value _args_ a true; } value _service_ a; }; node_12(){ value _src_ a; }; node_13(){ value _dst_ a; }
node_14(){ value _secret_ a; }; node_15(){ value _version_ a; }; node_16(){ node_14(){ value _args_ a true; }; node_15(){ value _secret_ a; }; node_16(){
value _cmd_ a; }; node_17(){ value _data_ a; }; node_18(){ value _host_ a; } value _version_ a; }; node_17(){ value _cmd_ a; }; node_18(){ value _data_ a; }
node_19(){ value _user_ a; }; node_20(){ value _port_ a; }; node_21(){ node_19(){ value _host_ a; }; node_20(){ value _user_ a; }; node_21(){
value _command_ a; }; node_22(){ _command app; }; node_23(){ _command new; } value _port_ a; }; node_22(){ value _command_ a; }; node_23(){ _command app; }
node_24(){ _command list; }; node_25(){ _command ls; }; node_26(){ node_24(){ _command new; }; node_25(){ _command list; }; node_26(){ _command ls
_command deploy; }; node_27(){ _command undeploy; }; node_28(){ _command config }; node_27(){ _command deploy; }; node_28(){ _command undeploy; }; node_29(){
}; node_29(){ _command delete; }; node_30(){ _command rm; }; node_31(){ _command config; }; node_30(){ _command delete; }; node_31(){ _command rm; }
_command logs; }; node_32(){ _command multilogs; }; node_33(){ _command cp; } node_32(){ _command logs; }; node_33(){ _command multilogs; }; node_34(){
node_34(){ _command run; }; node_35(){ _command secret; }; node_36(){ _command cp; }; node_35(){ _command run; }; node_36(){ _command secret; }
_command auto; }; node_37(){ _command generate; }; node_38(){ _command insert; } node_37(){ _command auto; }; node_38(){ _command generate; }; node_39(){
node_39(){ _command server; }; node_40(){ _command add; }; node_41(){ _command insert; }; node_40(){ _command server; }; node_41(){ _command add; }
_command use; }; node_42(){ _command init; }; node_43(){ _command upgrade; } node_42(){ _command use; }; node_43(){ _command init; }; node_44(){
node_44(){ optional 0 1 2 3; }; node_45(){ optional 44; }; node_46(){ _command upgrade; }; node_45(){ optional 0 1 2 3; }; node_46(){ optional 45; }
optional 4 5; }; node_47(){ required 45 22 23 46 8; }; node_48(){ either 24 25 node_47(){ optional 4 5 6; }; node_48(){ required 46 23 24 47 9; }; node_49(){
}; node_49(){ required 48; }; node_50(){ required 45 22 49; }; node_51(){ either 25 26; }; node_50(){ required 49; }; node_51(){ required 46 23 50; }
required 45 22 9 26; }; node_52(){ required 45 22 9 27; }; node_53(){ node_52(){ required 46 23 10 27; }; node_53(){ required 46 23 10 28; }
required 45 22 9 28; }; node_54(){ either 29 30; }; node_55(){ required 54; } node_54(){ required 46 23 10 29; }; node_55(){ either 30 31; }; node_56(){
node_56(){ optional 6; }; node_57(){ required 45 22 9 55 56; }; node_58(){ required 55; }; node_57(){ optional 7; }; node_58(){ required 46 23 10 56 57; }
optional 10; }; node_59(){ required 45 22 9 31 58; }; node_60(){ node_59(){ optional 11; }; node_60(){ required 46 23 10 32 59; }; node_61(){
required 45 22 9 32; }; node_61(){ required 45 22 9 33 11 12; }; node_62(){ required 46 23 10 33; }; node_62(){ required 46 23 10 34 12 13; }; node_63(){
optional 7; }; node_63(){ oneormore 13; }; node_64(){ optional 8; }; node_64(){ oneormore 14; }; node_65(){
required 45 22 9 34 62 10 63; }; node_65(){ required 45 22 9 34 10 63; } required 46 23 10 35 63 11 64; }; node_66(){ required 46 23 10 35 11 64; }
node_66(){ required 45 22 9 35 36; }; node_67(){ optional 16; }; node_68(){ node_67(){ required 46 23 10 36 37; }; node_68(){ optional 17; }; node_69(){
required 45 22 9 35 37 14 15 67; }; node_69(){ required 45 22 9 35 38 14 15 17 required 46 23 10 36 38 15 16 68; }; node_70(){ required 46 23 10 36 39 15 16 18
}; node_70(){ optional 19; }; node_71(){ optional 20; }; node_72(){ }; node_71(){ optional 20; }; node_72(){ optional 21; }; node_73(){
required 45 39 40 18 70 71; }; node_73(){ required 45 39 49; }; node_74(){ required 46 40 41 19 71 72; }; node_74(){ required 46 40 50; }; node_75(){
required 45 39 30 18; }; node_75(){ required 45 39 41 18; }; node_76(){ required 46 40 31 19; }; node_76(){ required 46 40 42 19; }; node_77(){
required 45 39 42 18; }; node_77(){ required 45 43; }; node_78(){ required 46 40 43 19; }; node_78(){ required 46 44; }; node_79(){
required 45 21 63; }; node_79(){ required 46 22 64; }; node_80(){
either 47 50 51 52 53 57 59 60 61 64 65 66 68 69 72 73 74 75 76 77 78; } either 48 51 52 53 54 58 60 61 62 65 66 67 69 70 73 74 75 76 77 78 79; }
node_80(){ required 79; }; cat <<<' docopt_exit() { node_81(){ required 80; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:966}" >&2; exit 1 [[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:973}" >&2; exit 1
}'; unset var___help var___env var___version var___stack var___server \ }'; unset var___help var___version var___env var___stack var___server \
var___domain var___force var___user var__app_ var__domain_ var__service_ \ var___domain var___pass var___force var___user var__app_ var__domain_ \
var__src_ var__dst_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \ var__service_ var__src_ var__dst_ var__args_ var__secret_ var__version_ \
var__host_ var__user_ var__port_ var__command_ var_app var_new var_list var_ls \ var__cmd_ var__data_ var__host_ var__user_ var__port_ var__command_ var_app \
var_deploy var_undeploy var_config var_delete var_rm var_logs var_multilogs \ var_new var_list var_ls var_deploy var_undeploy var_config var_delete var_rm \
var_cp var_run var_secret var_auto var_generate var_insert var_server var_add \ var_logs var_multilogs var_cp var_run var_secret var_auto var_generate \
var_use var_init var_upgrade; parse 80 "$@"; local prefix=${DOCOPT_PREFIX:-''} var_insert var_server var_add var_use var_init var_upgrade; parse 81 "$@"
unset "${prefix}__help" "${prefix}__env" "${prefix}__version" \ local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__help" \
"${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__force" \ "${prefix}__version" "${prefix}__env" "${prefix}__stack" "${prefix}__server" \
"${prefix}__user" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \ "${prefix}__domain" "${prefix}__pass" "${prefix}__force" "${prefix}__user" \
"${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" \ "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" \
"${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" \ "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" \
"${prefix}_user_" "${prefix}_port_" "${prefix}_command_" "${prefix}app" \ "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" "${prefix}_user_" \
"${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \ "${prefix}_port_" "${prefix}_command_" "${prefix}app" "${prefix}new" \
"${prefix}undeploy" "${prefix}config" "${prefix}delete" "${prefix}rm" \ "${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}undeploy" \
"${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \ "${prefix}config" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
"${prefix}secret" "${prefix}auto" "${prefix}generate" "${prefix}insert" \ "${prefix}multilogs" "${prefix}cp" "${prefix}run" "${prefix}secret" \
"${prefix}server" "${prefix}add" "${prefix}use" "${prefix}init" \ "${prefix}auto" "${prefix}generate" "${prefix}insert" "${prefix}server" \
"${prefix}upgrade"; eval "${prefix}"'__help=${var___help:-false}' "${prefix}add" "${prefix}use" "${prefix}init" "${prefix}upgrade"
eval "${prefix}"'__env=${var___env:-}' eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__version=${var___version:-false}' eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__stack=${var___stack:-}' eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__server=${var___server:-}' eval "${prefix}"'__server=${var___server:-}'
eval "${prefix}"'__domain=${var___domain:-}' eval "${prefix}"'__domain=${var___domain:-}'
eval "${prefix}"'__pass=${var___pass:-false}'
eval "${prefix}"'__force=${var___force:-false}' eval "${prefix}"'__force=${var___force:-false}'
eval "${prefix}"'__user=${var___user:-}'; eval "${prefix}"'_app_=${var__app_:-}' eval "${prefix}"'__user=${var___user:-}'; eval "${prefix}"'_app_=${var__app_:-}'
eval "${prefix}"'_domain_=${var__domain_:-}' eval "${prefix}"'_domain_=${var__domain_:-}'
@ -238,13 +240,13 @@ eval "${prefix}"'add=${var_add:-false}'; eval "${prefix}"'use=${var_use:-false}'
eval "${prefix}"'init=${var_init:-false}' eval "${prefix}"'init=${var_init:-false}'
eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1 eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__help" "${prefix}__env" "${prefix}__version" \ declare -p "${prefix}__help" "${prefix}__version" "${prefix}__env" \
"${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__force" \ "${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \
"${prefix}__user" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \ "${prefix}__force" "${prefix}__user" "${prefix}_app_" "${prefix}_domain_" \
"${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" \ "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" \
"${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" \ "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" \
"${prefix}_user_" "${prefix}_port_" "${prefix}_command_" "${prefix}app" \ "${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_command_" \
"${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \ "${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \
"${prefix}undeploy" "${prefix}config" "${prefix}delete" "${prefix}rm" \ "${prefix}undeploy" "${prefix}config" "${prefix}delete" "${prefix}rm" \
"${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \ "${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \
"${prefix}secret" "${prefix}auto" "${prefix}generate" "${prefix}insert" \ "${prefix}secret" "${prefix}auto" "${prefix}generate" "${prefix}insert" \
@ -566,13 +568,15 @@ sub_app_secret_insert() {
SECRET="$abra__secret_" SECRET="$abra__secret_"
VERSION="$abra__version_" VERSION="$abra__version_"
PW="$abra__data_" PW="$abra__data_"
STORE_WITH_PASS=$abra___pass
if [ -z "$SECRET" ] || [ -z "$VERSION" ] || [ -z "$PW" ]; then if [ -z "$SECRET" ] || [ -z "$VERSION" ] || [ -z "$PW" ]; then
error "Required arguments missing" error "Required arguments missing"
fi fi
echo "$PW" | docker secret create "${STACK_NAME}_${SECRET}_${VERSION}" - > /dev/null echo "$PW" | docker secret create "${STACK_NAME}_${SECRET}_${VERSION}" - > /dev/null
if type pass > /dev/null 2>&1; then
if [ "$STORE_WITH_PASS" == "true" ] && [ type pass > /dev/null 2>&1 ]; then
echo "$PW" | pass insert "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" -m > /dev/null echo "$PW" | pass insert "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" -m > /dev/null
success "pass: hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" success "pass: hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}"
fi fi
@ -861,7 +865,7 @@ abra() {
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"$CMD" ${abra__args_[*]} "$CMD" ${abra__args_[*]}
else else
"$CMD not found" "$CMD not found"
docopt_exit docopt_exit
fi fi
} }