Add success() method & secret insert
subcommand
This commit is contained in:
parent
5627e67bf7
commit
aa1ffd5d8a
40
abra
40
abra
@ -57,6 +57,10 @@ warning() {
|
||||
echo "$(tput setaf 3)WARNING: $*$(tput sgr0)"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo "$(tput setaf 2)$*$(tput sgr0)"
|
||||
}
|
||||
|
||||
###### Top-level arguments
|
||||
|
||||
ABRA_CONFIG=abra.yml
|
||||
@ -102,7 +106,9 @@ fi
|
||||
load_context() {
|
||||
if [ -z "$DOCKER_CONTEXT" ]; then
|
||||
warning "\$DOCKER_CONTEXT not set, (slowly) looking it up"
|
||||
# shellcheck disable=SC2063
|
||||
DOCKER_CONTEXT=$(docker context ls | grep '*' | cut -d' ' -f1)
|
||||
# FIXME 3wc: make sure grep doesn't parse this, we're want a literal '*'
|
||||
fi
|
||||
}
|
||||
|
||||
@ -159,24 +165,38 @@ sub_secret_help() {
|
||||
echo ""
|
||||
echo "Subcommands:"
|
||||
echo " generate SECRET VERSION [PW] generate & store secret"
|
||||
echo " insert SECRET VERSION PW save PW in docker and pass"
|
||||
}
|
||||
|
||||
sub_secret_generate(){
|
||||
sub_secret_insert() {
|
||||
require_stack
|
||||
load_context
|
||||
|
||||
SECRET=$1
|
||||
VERSION=$2
|
||||
PW=${3:-pwqgen}
|
||||
PW=$3
|
||||
|
||||
if [ -z "$SECRET" ] || [ -z "$VERSION" ]; then
|
||||
echo "Usage: $PROGRAM_NAME secret_generate SECRET VERSION"
|
||||
if [ -z "$SECRET" ] || [ -z "$VERSION" ] || [ -z "$PW" ]; then
|
||||
echo "Usage: $PROGRAM_NAME secret insert SECRET VERSION PW"
|
||||
exit
|
||||
fi
|
||||
|
||||
$PW | tee \
|
||||
>(docker secret create "${STACK_NAME}_${SECRET}_${VERSION}" -) \
|
||||
>(pass insert "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" -m)
|
||||
echo "$PW" | docker secret create "${STACK_NAME}_${SECRET}_${VERSION}" - > /dev/null
|
||||
echo "$PW" | pass insert "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" -m > /dev/null
|
||||
}
|
||||
|
||||
sub_secret_generate(){
|
||||
SECRET=$1
|
||||
VERSION=$2
|
||||
PWGEN=${3:-pwqgen}
|
||||
|
||||
PW=$($PWGEN)
|
||||
|
||||
success "Password: $PW"
|
||||
|
||||
echo "sub_secret_insert \"$SECRET\" \"$VERSION\" \"$PW\""
|
||||
exit
|
||||
sub_secret_insert "$SECRET" "$VERSION" "$PW"
|
||||
}
|
||||
|
||||
sub_secret() {
|
||||
@ -197,7 +217,7 @@ sub_run_args(){
|
||||
shift 2
|
||||
|
||||
if [ -z "$SERVICE" ]; then
|
||||
echo "Usage: $PROGRAM_NAME run SERVICE [CMD]"
|
||||
echo "Usage: $PROGRAM_NAME run SERVICE DOCKER_ARGS [CMD]"
|
||||
exit
|
||||
fi
|
||||
|
||||
@ -251,9 +271,9 @@ sub_deploy (){
|
||||
# shellcheck disable=SC2086
|
||||
if docker stack deploy -c ${COMPOSE_FILE/:/ -c } "$STACK_NAME"; then
|
||||
if [ -n "$DOMAIN" ]; then
|
||||
echo "$(tput setaf 2)Yay! App should be available at https://${DOMAIN}$(tput sgr0)"
|
||||
success "Yay! App should be available at https://${DOMAIN}"
|
||||
else
|
||||
echo "$(tput setaf 2)Yay! That worked. No \$DOMAIN defined, check logs.(tput sgr0)"
|
||||
success "Yay! That worked. No \$DOMAIN defined, check logs."
|
||||
fi
|
||||
else
|
||||
error "Oh no! Something went wrong 😕 Check errors above"
|
||||
|
Reference in New Issue
Block a user