SPB Git

Repository Public

dev-session.sh 1.7 KB 33 lines shellscript

1#!/usr/bin/env bash2# SP Chat iOS3# File: Scripts/dev-session.sh4# Description: Creates (or renews) a test session in the DEV database (chat_spboucher_dev) of the backend worktree on M4M64c5#              and stores its token in ~/.config/spchat-dev/session-token. Never touches the production database.6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9set -euo pipefail10NODE="${SPCHAT_DEV_NODE:-M4M64c}"11# SPCHAT_DEV_SLOT gives a parallel run its own test session (and token file), so two runs never rotate each other's token12SLOT="$(printf %s "${SPCHAT_DEV_SLOT:-}" | tr -cd 'a-z0-9')"13FILE=~/.config/spchat-dev/session-token${SLOT:+-$SLOT}14mkdir -p ~/.config/spchat-dev && chmod 700 ~/.config/spchat-dev15ssh "$NODE" "SLOT='$SLOT' bash -s" <<'REMOTE' > "$FILE"16set -euo pipefail17cd ~/work/csa-v318PSQL=/opt/homebrew/opt/postgresql@17/bin/psql19DB=$(grep ^DATABASE_URL= .env.local | cut -d= -f2-)20case "$DB" in *_dev*) ;; *) echo "refus : la base n'est pas une base *_dev" >&2; exit 1;; esac21TOKEN=$(python3 -c "import secrets;print(secrets.token_urlsafe(32))")22HASH=$(printf %s "$TOKEN" | shasum -a 256 | cut -d" " -f1)23PUBLIC="ses_iosdevtests${SLOT:-0001}"24"$PSQL" "$DB" -q -v h="$HASH" -v p="$PUBLIC" <<'SQL' >/dev/null25INSERT INTO sessions (id, public_id, expires_at, absolute_expires_at, auth_at, user_agent, ip, label)26VALUES (:'h', :'p', now() + interval '30 days', now() + interval '90 days', now(), 'SPChat-iOS dev tests', 'local', 'iPhone · tests iOS (dev)')27ON CONFLICT (public_id) DO UPDATE SET id = EXCLUDED.id, revoked_at = NULL, expires_at = EXCLUDED.expires_at, absolute_expires_at = EXCLUDED.absolute_expires_at, auth_at = now();28SQL29printf %s "$TOKEN"30REMOTE31chmod 600 "$FILE"32echo "jeton de test (dev) écrit : $(wc -c < "$FILE" | tr -d ' ') caractères"33
Files main
Menu

Theme