Config cleanup, create_mrshughes refactoring
This commit is contained in:
@@ -8,6 +8,7 @@ SSH_CONFIG_FILE="${SSH_CONFIG_FILE:-$HOME/.ssh/config.oci}"
|
||||
OCI_BIN="${OCI_BIN:-/opt/homebrew/bin/oci}"
|
||||
OCI_SESSION_REGION="${OCI_SESSION_REGION:-us-chicago-1}"
|
||||
OCI_PROFILE_NAME="${OCI_PROFILE_NAME:-DEFAULT}"
|
||||
OCI_SESSION_VALIDATE_TIMEOUT_SECONDS="${OCI_SESSION_VALIDATE_TIMEOUT_SECONDS:-2}"
|
||||
RESET_AGENT="${RESET_AGENT:-0}"
|
||||
DEDICATED_AGENT_PID=""
|
||||
DEDICATED_AGENT_SOCK=""
|
||||
@@ -26,14 +27,64 @@ run_oci() {
|
||||
"${OCI_BIN}" --profile "${OCI_PROFILE_NAME}" "$@"
|
||||
}
|
||||
|
||||
resolve_timeout_bin() {
|
||||
local candidate
|
||||
|
||||
for candidate in timeout gtimeout /opt/homebrew/bin/timeout /opt/homebrew/bin/gtimeout; do
|
||||
if [[ "${candidate}" == /* ]]; then
|
||||
if [[ -x "${candidate}" ]]; then
|
||||
print -r -- "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
|
||||
if command -v "${candidate}" >/dev/null 2>&1; then
|
||||
command -v "${candidate}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
get_validate_timeout_seconds() {
|
||||
local timeout_seconds="${OCI_SESSION_VALIDATE_TIMEOUT_SECONDS}"
|
||||
|
||||
if [[ ! "${timeout_seconds}" =~ '^[0-9]+([.][0-9]+)?$' ]]; then
|
||||
log "Warning: invalid OCI_SESSION_VALIDATE_TIMEOUT_SECONDS=${timeout_seconds}; using 2 seconds."
|
||||
print -r -- "2"
|
||||
return 0
|
||||
fi
|
||||
|
||||
print -r -- "${timeout_seconds}"
|
||||
}
|
||||
|
||||
run_oci_with_timeout() {
|
||||
local timeout_seconds="$1"
|
||||
shift
|
||||
|
||||
local timeout_bin
|
||||
if ! timeout_bin="$(resolve_timeout_bin)"; then
|
||||
log "Warning: no timeout binary found; running OCI command without a timeout."
|
||||
run_oci "$@"
|
||||
return $?
|
||||
fi
|
||||
|
||||
"${timeout_bin}" "${timeout_seconds}" "${OCI_BIN}" --profile "${OCI_PROFILE_NAME}" "$@"
|
||||
}
|
||||
|
||||
ensure_oci_session() {
|
||||
if [[ ! -x "${OCI_BIN}" ]]; then
|
||||
print -u2 "OCI CLI not found or not executable: ${OCI_BIN}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local validate_timeout_seconds
|
||||
validate_timeout_seconds="$(get_validate_timeout_seconds)"
|
||||
|
||||
set +e
|
||||
run_oci session validate >/dev/null 2>&1
|
||||
run_oci_with_timeout "${validate_timeout_seconds}" session validate >/dev/null 2>&1
|
||||
local validate_rc=$?
|
||||
set -e
|
||||
|
||||
@@ -42,6 +93,10 @@ ensure_oci_session() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ${validate_rc} -eq 124 ]]; then
|
||||
log "OCI CLI session validation timed out after ${validate_timeout_seconds} seconds; treating session as invalid."
|
||||
fi
|
||||
|
||||
log "OCI CLI session is not valid; attempting refresh."
|
||||
set +e
|
||||
run_oci session refresh >/dev/null 2>&1
|
||||
|
||||
Reference in New Issue
Block a user