remote scwrypts v5 refactor

This commit is contained in:
2025-02-19 21:58:02 -07:00
parent f11c6dfad6
commit a3410d9b15
11 changed files with 191 additions and 181 deletions

View File

@ -4,19 +4,19 @@ DEPENDENCIES+=(yq)
#####################################################################
REMOTE__GET_CONNECTION_STRING() {
${scwryptsmodule}.get-connection-string() {
local REMOTE_NAME="$1"
[ $(REMOTE__QUERY_CONNECTION .sessions.$REMOTE_NAME.host) ] \
|| ERROR "no such connection $REMOTE_NAME exists" \
[ $(remote.config.query-connection .sessions.$REMOTE_NAME.host) ] \
|| echo.error "no such connection $REMOTE_NAME exists" \
|| return 1
local CONNECTION_HOST=$(REMOTE__QUERY_CONNECTION .sessions.$REMOTE_NAME.host)
local CONNECTION_HOST=$(remote.config.query-connection .sessions.$REMOTE_NAME.host)
[ $CONNECTION_HOST ] \
|| ERROR "connection $REMOTE_NAME is misconfigured; missing 'host' field" \
|| echo.error "connection $REMOTE_NAME is misconfigured; missing 'host' field" \
|| return 1
local CONNECTION_USER=$(REMOTE__QUERY_CONNECTION .sessions.$REMOTE_NAME.user)
[ $CONNECTION_USER ] || CONNECTION_USER=$(REMOTE__QUERY_CONNECTION .default.user)
local CONNECTION_USER=$(remote.config.query-connection .sessions.$REMOTE_NAME.user)
[ $CONNECTION_USER ] || CONNECTION_USER=$(remote.config.query-connection .default.user)
[ $CONNECTION_USER ] \
&& CONNECTION_STRING="${CONNECTION_USER}@${CONNECTION_HOST}" \
@ -26,7 +26,7 @@ REMOTE__GET_CONNECTION_STRING() {
echo $CONNECTION_STRING
}
REMOTE__GET_SSH_ARGS() {
${scwryptsmodule}.get-ssh-args() {
local REMOTE_NAME
local TYPE=ssh
local USE_TTY=true
@ -34,13 +34,13 @@ REMOTE__GET_SSH_ARGS() {
while [[ $# -gt 0 ]]
do
case $1 in
-t | --type ) TYPE=$2; shift 1 ;;
--use-tty ) USE_TTY=$2; shift 1 ;;
( -t | --type ) TYPE=$2; shift 1 ;;
( --use-tty ) USE_TTY=$2; shift 1 ;;
--no-tty ) USE_TTY=false ;;
( --no-tty ) USE_TTY=false ;;
* )
[ $REMOTE_NAME ] && { ERROR "too many args :c"; return 1; }
( * )
[ $REMOTE_NAME ] && { echo.error "too many args :c"; return 1; }
REMOTE_NAME=$1
;;
esac
@ -53,25 +53,25 @@ REMOTE__GET_SSH_ARGS() {
return 0
}
local PORT=$(REMOTE__QUERY_CONNECTION .sessions.$REMOTE_NAME.port)
local PORT=$(remote.config.query-connection .sessions.$REMOTE_NAME.port)
[ $PORT ] && {
case $TYPE in
ssh | xserver | tmux ) ARGS+=(-p $PORT) ;;
scp ) ARGS+=(-P $PORT) ;; # not really in use, just a sample
* )
WARNING "
( ssh | xserver | tmux ) ARGS+=(-p $PORT) ;;
( scp ) ARGS+=(-P $PORT) ;; # not really in use, just a sample
( * )
WARNING "
port is specified, but I'm not sure whether to use '-p' or '-P'
if this command fails, try adding your --type to the appropriate
list in '$SCWRYPTS_ROOT__remote/lib/config.module.zsh'
list in '$(scwrypts.config.group remote root)/lib/config.module.zsh'
"
ARGS+=(-p $PORT)
;;
esac
}
ARGS+=($(REMOTE__QUERY_CONNECTION .session.$REMOTE_NAME.$TYPE.args))
ARGS+=($(remote.config.query-connection .session.$REMOTE_NAME.$TYPE.args))
[[ $USE_TTY =~ true ]] && ARGS+=(-t)
@ -80,17 +80,17 @@ REMOTE__GET_SSH_ARGS() {
#####################################################################
REMOTE__QUERY_CONNECTION() {
YQ -oy -r $@ "$REMOTE_CONNECTIONS_FILE" \
${scwryptsmodule}.query-connection() {
utils.yq -oy -r $@ "$REMOTE_CONNECTIONS_FILE" \
| grep -v ^null$
}
REMOTE__QUERY_CONNECTION_WITH_FALLBACK() {
${scwryptsmodule}.query-connection-with-fallback() {
while [[ $# -gt 0 ]] && [ ! $QUERY_RESULT ]
do
case $1 in
.* ) QUERY_RESULT=$(REMOTE__QUERY_CONNECTION $1) ;;
* ) QUERY_RESULT="$1" ;; # allows raw default value
( .* ) QUERY_RESULT=$(remote.config.query-connection $1) ;;
( * ) QUERY_RESULT="$1" ;; # allows raw default value
esac
shift 1
done