diff --git a/global/common.zsh b/global/common.zsh new file mode 100644 index 0000000..656ace2 --- /dev/null +++ b/global/common.zsh @@ -0,0 +1,32 @@ +##################################################################### + +[ ! $SCWRYPTS_ROOT ] && SCWRYPTS_ROOT="$(dirname ${0:a:h})" + +source "${0:a:h}/config.zsh" + +##################################################################### + +__SCWRYPT=1 # arbitrary; indicates scwrypts exists + +__PREFERRED_PYTHON_VERSIONS=(3.10 3.9) +__NODE_VERSION=18.0.0 + +__ENV_TEMPLATE=$SCWRYPTS_ROOT/.env.template + +##################################################################### + +__RUN_SCWRYPT() { + ((SUBSCWRYPT+=1)) + printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " + echo " BEGIN SUBSCWRYPT : $(basename $1)" + + SUBSCWRYPT=$SUBSCWRYPT SCWRYPTS_ENV=$ENV_NAME \ + "$SCWRYPTS_ROOT/scwrypts" $@ + EXIT_CODE=$? + + printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " + echo " END SUBSCWRYPT : $(basename $1)" + ((SUBSCWRYPT-=1)) + + return $EXIT_CODE +} diff --git a/.config b/global/config.zsh similarity index 95% rename from .config rename to global/config.zsh index 377642a..00d85d9 100644 Binary files a/.config and b/global/config.zsh differ diff --git a/py/redis/client.py b/py/redis/client.py index 8060a79..8184be2 100644 --- a/py/redis/client.py +++ b/py/redis/client.py @@ -8,7 +8,7 @@ def __init__(self): super().__init__( host = getenv('REDIS_HOST'), port = getenv('REDIS_PORT'), - password = getenv('REDIS_AUTH'), + password = getenv('REDIS_AUTH', required=False), decode_responses = True, ) diff --git a/zsh/aws/eks/common.zsh b/zsh/aws/eks/common.zsh new file mode 100644 index 0000000..1110be3 --- /dev/null +++ b/zsh/aws/eks/common.zsh @@ -0,0 +1,6 @@ +_DEPENDENCIES+=( + kubectl +) +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### diff --git a/zsh/aws/eks/login b/zsh/aws/eks/login new file mode 100755 index 0000000..08b4835 --- /dev/null +++ b/zsh/aws/eks/login @@ -0,0 +1,19 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +__STATUS "performing AWS ECR docker login" + +CLUSTER_NAME=$(\ + _AWS eks list-clusters \ + | jq -r '.[] | .[]' \ + | __FZF 'select a cluster' +) +[ ! $CLUSTER_NAME ] && __ABORT + +__STATUS "updating kubeconfig for '$CLUSTER_NAME'" +_AWS eks update-kubeconfig --name $CLUSTER_NAME \ + && __SUCCESS "kubeconfig updated with '$CLUSTER_NAME'" \ + || __ERROR "failed to update kubeconfig; do you have permissions to access '$CLUSTER_NAME'?" diff --git a/zsh/common.zsh b/zsh/common.zsh index 9fabd01..a126dd6 100644 --- a/zsh/common.zsh +++ b/zsh/common.zsh @@ -1,17 +1,8 @@ ##################################################################### -[ ! $SCWRYPTS_ROOT ] && SCWRYPTS_ROOT="$(dirname ${0:a:h})" - -__PREFERRED_PYTHON_VERSIONS=(3.10 3.9) -__NODE_VERSION=18.0.0 -__ENV_TEMPLATE=$SCWRYPTS_ROOT/.env.template - -__SCWRYPT=1 - -source $SCWRYPTS_ROOT/.config -source ${0:a:h}/utils/utils.module.zsh || { - [ $DONT_EXIT ] && return 1 || exit 1 -} +source ${0:a:h}/../global/common.zsh +source ${0:a:h}/utils/utils.module.zsh \ + || { [ $DONT_EXIT ] && return 1 || exit 1; } ##################################################################### @@ -26,33 +17,15 @@ __GET_ENV_NAMES() { __GET_ENV_FILES | sed 's/.*\///'; } __GET_ENV_FILE() { echo "$SCWRYPTS_CONFIG_PATH/env/$1"; } __SELECT_OR_CREATE_ENV() { __GET_ENV_NAMES | __FZF_TAIL 'select/create an environment'; } -__SELECT_ENV() { __GET_ENV_NAMES | __FZF 'select an environment'; } +__SELECT_ENV() { __GET_ENV_NAMES | __FZF 'select an environment'; } + +##################################################################### __GET_AVAILABLE_SCRIPTS() { cd $SCWRYPTS_ROOT; find . -mindepth 2 -type f -executable \ | grep -v '\.git' \ - | grep -v '\.env' \ | grep -v 'node_modules' \ | sed 's/^\.\///; s/\.[^.]*$//' \ ; } - -##################################################################### - -__RUN_SCWRYPT() { - # run a scwrypt inside a scwrypt w/stack-depth indicators - ((SUBSCWRYPT+=1)) - printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " - echo " BEGIN SUBSCWRYPT : $(basename $1)" - - SUBSCWRYPT=$SUBSCWRYPT SCWRYPTS_ENV=$ENV_NAME \ - "$SCWRYPTS_ROOT/scwrypts" $@ - EXIT_CODE=$? - - printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) " - echo " END SUBSCWRYPT : $(basename $1)" - ((SUBSCWRYPT-=1)) - - return $EXIT_CODE -} diff --git a/zsh/scwrypts/configure b/zsh/scwrypts/configure index af30673..392cb03 100755 --- a/zsh/scwrypts/configure +++ b/zsh/scwrypts/configure @@ -13,7 +13,7 @@ source ${0:a:h}/common.zsh echo '#' echo '# configuration for scwrypts' echo '#' - sed -n '1d; /^###/q; p' $SCWRYPTS_ROOT/.config | sed '$d' + sed -n '1d; /^###/q; p' $SCWRYPTS_ROOT/global/config.zsh | sed '$d' } > $SCWRYPTS_CONFIG_PATH/config __EDIT $SCWRYPTS_CONFIG_PATH/config