v5.0.0
===================================================================== Excited to bring V5 to life. This includes some BREAKING CHANGES to several aspects of ZSH-type scwrypts. Please refer to the readme for upgrade details (specifically docs/upgrade/v4-to-v5.md) --- New Features ------------------------- - ZSH testing library with basic mock capabilities - new scwrypts environment file format includes metadata and more advanced features like optional parent env overrides, selection inheritence, and improved structurual flexibility - speedup cache for non-CI runs of ZSH-type scwrypts - ${scwryptsmodule} syntax now allows a consistent unique-naming scheme for functions in ZSH-type scwrypts while providing better insight into origin of API calls in other modules - reusable, case-statement-driven argument parsers in ZSH-type scwrypts --- Changes ------------------------------ - several utility function renames in ZSH-type scwrypts to improve consistency - documentation comments included in ZSH libraries - ZSH-type scwrypts now allow library modules to live alongside executables (zsh/lib still supported; autodetection determines default) --- Bug Fixes ---------------------------- - hardened environment checking for REQUIRED_ENV variables; this removes the ability to overwrite variables in local function contexts
This commit is contained in:
94
plugins/kube/redis/redis.module.zsh
Normal file
94
plugins/kube/redis/redis.module.zsh
Normal file
@ -0,0 +1,94 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(
|
||||
redis-cli
|
||||
docker
|
||||
)
|
||||
|
||||
REQUIRED_ENV+=()
|
||||
|
||||
utils.environment.check SCWRYPTS_KUBECTL_REDIS --default managed
|
||||
|
||||
#####################################################################
|
||||
|
||||
kube.redis() {
|
||||
[ ! $USAGE ] && local USAGE="
|
||||
usage: [...options...]
|
||||
|
||||
options:
|
||||
--subsession [0-9] use a particular subsession
|
||||
|
||||
-p, --prefix apply dynamic prefix to the next command line argument
|
||||
|
||||
--get-prefix output key prefix for current session+subsession
|
||||
--get-static-definition output the static ZSH function definition for kube.redis
|
||||
|
||||
additional arguments and options are passed through to 'redis-cli'
|
||||
"
|
||||
|
||||
local REDIS_ARGS=() USER_ARGS=()
|
||||
|
||||
[ $SUBSESSION ] || local SUBSESSION=0
|
||||
|
||||
local REDIS_PREFIX=$(eval echo '$SCWRYPTS_KUBECTL_REDIS_KEY_PREFIX__'$SCWRYPTS_KUBECTL_REDIS)
|
||||
[ $REDIS_PREFIX ] && REDIS_PREFIX+=':'
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
( -p | --prefix ) USER_ARGS+=("${REDIS_PREFIX}${SCWRYPTS_ENV}:${SUBSESSION}:$2"); shift 1 ;;
|
||||
|
||||
( --subsession ) SUBSESSION=$2; shift 1 ;;
|
||||
|
||||
( --get-prefix ) echo $REDIS_PREFIX; return 0 ;;
|
||||
( --get-static-definition ) ECHO_STATIC_DEFINITION=1 ;;
|
||||
|
||||
( * ) USER_ARGS+=($1) ;;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
local REDIS_HOST=$(eval echo '$SCWRYPTS_KUBECTL_REDIS_HOST__'$SCWRYPTS_KUBECTL_REDIS)
|
||||
local REDIS_PORT=$(eval echo '$SCWRYPTS_KUBECTL_REDIS_PORT__'$SCWRYPTS_KUBECTL_REDIS)
|
||||
local REDIS_AUTH=$(eval echo '$SCWRYPTS_KUBECTL_REDIS_AUTH__'$SCWRYPTS_KUBECTL_REDIS)
|
||||
|
||||
[ $REDIS_HOST ] && REDIS_ARGS+=(-h $REDIS_HOST)
|
||||
[ $REDIS_PORT ] && REDIS_ARGS+=(-p $REDIS_PORT)
|
||||
[ $REDIS_AUTH ] && REDIS_ARGS+=(-a $REDIS_AUTH)
|
||||
|
||||
REDIS_ARGS+=(--raw)
|
||||
|
||||
[[ $ECHO_STATIC_DEFINITION -eq 1 ]] && {
|
||||
echo "kube.redis() {\
|
||||
local USER_ARGS=(); \
|
||||
[ ! \$SUBSESSION ] && local SUBSESSION=0 ;\
|
||||
while [[ \$# -gt 0 ]]; \
|
||||
do \
|
||||
case \$1 in
|
||||
( -p | --prefix ) USER_ARGS+=(\"${REDIS_PREFIX}\${SCWRYPTS_ENV}:\${SUBSESSION}:\$2\"); shift 1 ;; \
|
||||
( * ) USER_ARGS+=(\$1) ;; \
|
||||
esac; \
|
||||
shift 1; \
|
||||
done; \
|
||||
redis-cli ${REDIS_ARGS[@]} \${USER_ARGS[@]}; \
|
||||
}" | sed 's/\s\+/ /g'
|
||||
return 0
|
||||
}
|
||||
|
||||
redis-cli ${REDIS_ARGS[@]} ${USER_ARGS[@]}
|
||||
}
|
||||
|
||||
kube.redis ping 2>/dev/null | grep -qi pong || {
|
||||
RPID=$(docker ps -a | grep scwrypts-kubectl-redis | awk '{print $1;}')
|
||||
[ $RPID ] && echo.status 'refreshing redis instance' && docker rm -f $RPID
|
||||
unset RPID
|
||||
|
||||
docker run \
|
||||
--detach \
|
||||
--name scwrypts-kubectl-redis \
|
||||
--publish $SCWRYPTS_KUBECTL_REDIS_PORT__managed:6379 \
|
||||
redis >/dev/null 2>&1
|
||||
|
||||
echo.status 'awaiting redis connection'
|
||||
until kube.redis ping 2>/dev/null | grep -qi pong; do sleep 0.5; done
|
||||
}
|
Reference in New Issue
Block a user