feat: Enhance log inspection and querying capabilities for test environments
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
---
|
||||
name: query-shz-highgo
|
||||
description: Query the SHZ HighGo Security Enterprise Edition database through its SSH gateway using a guarded read-only psql workflow. Use when Codex is working in the shz-backend project and needs to inspect database schemas, tables, columns, row counts, or application data; diagnose data-related behavior; or execute SELECT, WITH, SHOW, or EXPLAIN statements against the project's HighGo database.
|
||||
description: Query the SHZ HighGo Security Enterprise Edition database in the test or production environment through an SSH gateway using a guarded read-only psql workflow. Use when Codex is working in the shz-backend project and needs to inspect database schemas, tables, columns, row counts, or application data; diagnose data-related behavior; or execute SELECT, WITH, SHOW, or EXPLAIN statements against the project's HighGo database.
|
||||
---
|
||||
|
||||
# Query SHZ HighGo
|
||||
|
||||
Use the bundled script to run read-only SQL through the configured SSH gateway.
|
||||
Use the bundled script to run read-only SQL through the configured SSH gateway. The existing one-argument form queries production; pass `test` as the first argument to query the test environment.
|
||||
|
||||
## Query workflow
|
||||
|
||||
@@ -15,6 +15,9 @@ Use the bundled script to run read-only SQL through the configured SSH gateway.
|
||||
|
||||
```bash
|
||||
.codex/skills/query-shz-highgo/scripts/query.sh 'SELECT current_database(), current_user, current_schema()'
|
||||
|
||||
# Test environment
|
||||
.codex/skills/query-shz-highgo/scripts/query.sh test 'SELECT current_database(), current_user, current_schema()'
|
||||
```
|
||||
|
||||
4. Summarize the result and distinguish returned facts from inferences.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
interface:
|
||||
display_name: "查询 SHZ 翰高数据库"
|
||||
short_description: "通过 SSH 网关安全执行本项目翰高数据库只读 SQL 查询"
|
||||
default_prompt: "Use $query-shz-highgo to run a read-only query against this project's SHZ HighGo database."
|
||||
short_description: "通过 SSH 安全查询 SHZ 测试或线上翰高数据库"
|
||||
default_prompt: "Use $query-shz-highgo to run a read-only query against this project's test or production HighGo database."
|
||||
|
||||
@@ -9,4 +9,16 @@
|
||||
- Detected server: HighGo Security Enterprise Edition Database System 4.5.10
|
||||
- Password source: `../.password`, mode `600`; override with `HIGHGO_PASSWORD_FILE`
|
||||
|
||||
## Test environment
|
||||
|
||||
- SSH gateway: `root@47.111.103.66:22`
|
||||
- HighGo client: `/opt/HighGo4.5.7-see/bin/psql`
|
||||
- Database endpoint from the test profile: `127.0.0.1:5866` (on the test server)
|
||||
- Database: `highgo`
|
||||
- User: `sysdba`
|
||||
- Default schemas: `shz,public`
|
||||
- Password source: `HIGHGO_TEST_PASSWORD_FILE` when set; otherwise the existing `HIGHGO_PASSWORD_FILE` or `../.password`
|
||||
|
||||
The test connection is made by SSHing to `47.111.103.66` and running the HighGo client there against its loopback database endpoint. Override the test endpoint with `HIGHGO_TEST_SSH_HOST`, `HIGHGO_TEST_SSH_PORT`, `HIGHGO_TEST_PSQL_PATH`, `HIGHGO_TEST_DB_HOST`, `HIGHGO_TEST_DB_PORT`, `HIGHGO_TEST_DB_NAME`, or `HIGHGO_TEST_DB_USER` if the server layout differs.
|
||||
|
||||
The SSH gateway must be reachable with the workstation's existing SSH key. Keep credentials out of commands, logs, responses, and `SKILL.md`.
|
||||
|
||||
@@ -2,14 +2,40 @@
|
||||
set -euo pipefail
|
||||
|
||||
skill_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
password_file="${HIGHGO_PASSWORD_FILE:-$skill_dir/.password}"
|
||||
|
||||
ssh_host="root@124.243.245.42"
|
||||
psql_path="/opt/HighGo4.5.7-see/bin/psql"
|
||||
db_host="39.98.44.136"
|
||||
db_port="6023"
|
||||
db_name="highgo"
|
||||
db_user="sysdba"
|
||||
environment="online"
|
||||
if [[ "${1:-}" == "online" || "${1:-}" == "production" || "${1:-}" == "test" ]]; then
|
||||
environment="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
case "${environment}" in
|
||||
online|production)
|
||||
password_file="${HIGHGO_PASSWORD_FILE:-$skill_dir/.password}"
|
||||
ssh_host="${HIGHGO_ONLINE_SSH_HOST:-root@124.243.245.42}"
|
||||
ssh_port="${HIGHGO_ONLINE_SSH_PORT:-}"
|
||||
psql_path="${HIGHGO_ONLINE_PSQL_PATH:-/opt/HighGo4.5.7-see/bin/psql}"
|
||||
db_host="${HIGHGO_ONLINE_DB_HOST:-39.98.44.136}"
|
||||
db_port="${HIGHGO_ONLINE_DB_PORT:-6023}"
|
||||
db_name="${HIGHGO_ONLINE_DB_NAME:-highgo}"
|
||||
db_user="${HIGHGO_ONLINE_DB_USER:-sysdba}"
|
||||
;;
|
||||
test)
|
||||
password_file="${HIGHGO_TEST_PASSWORD_FILE:-${HIGHGO_PASSWORD_FILE:-$skill_dir/.password}}"
|
||||
ssh_host="${HIGHGO_TEST_SSH_HOST:-root@47.111.103.66}"
|
||||
ssh_port="${HIGHGO_TEST_SSH_PORT:-22}"
|
||||
psql_path="${HIGHGO_TEST_PSQL_PATH:-/opt/HighGo4.5.7-see/bin/psql}"
|
||||
db_host="${HIGHGO_TEST_DB_HOST:-127.0.0.1}"
|
||||
db_port="${HIGHGO_TEST_DB_PORT:-5866}"
|
||||
db_name="${HIGHGO_TEST_DB_NAME:-highgo}"
|
||||
db_user="${HIGHGO_TEST_DB_USER:-sysdba}"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown environment: ${environment}" >&2
|
||||
echo "Usage: $0 [online|production|test] 'SELECT ...'" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ! -r "$password_file" ]]; then
|
||||
echo "HighGo password file is missing or unreadable: $password_file" >&2
|
||||
@@ -17,7 +43,7 @@ if [[ ! -r "$password_file" ]]; then
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Usage: $0 'SELECT ...'" >&2
|
||||
echo "Usage: $0 [online|production|test] 'SELECT ...'" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
@@ -36,8 +62,19 @@ fi
|
||||
password="$(<"$password_file")"
|
||||
sql_base64="$(printf '%s' "$sql" | base64 | tr -d '\n')"
|
||||
|
||||
printf -v quoted_psql_path '%q' "$psql_path"
|
||||
printf -v quoted_db_host '%q' "$db_host"
|
||||
printf -v quoted_db_port '%q' "$db_port"
|
||||
printf -v quoted_db_user '%q' "$db_user"
|
||||
printf -v quoted_db_name '%q' "$db_name"
|
||||
|
||||
ssh_args=(-o BatchMode=yes -o ConnectTimeout=10)
|
||||
if [[ -n "${ssh_port}" ]]; then
|
||||
ssh_args+=(-p "${ssh_port}")
|
||||
fi
|
||||
|
||||
{
|
||||
printf '%s\n' "$password"
|
||||
printf '%s\n' "$sql_base64"
|
||||
} | ssh -o BatchMode=yes -o ConnectTimeout=10 "$ssh_host" \
|
||||
"read -r PGPASSWORD; read -r SQL_BASE64; export PGPASSWORD; export PGOPTIONS='-c default_transaction_read_only=on -c search_path=shz,public -c statement_timeout=30000'; SQL=\$(printf '%s' \"\$SQL_BASE64\" | base64 -d); exec '$psql_path' -X --no-psqlrc -h '$db_host' -p '$db_port' -U '$db_user' -d '$db_name' -v ON_ERROR_STOP=1 -P pager=off -c \"\$SQL\""
|
||||
} | ssh "${ssh_args[@]}" "$ssh_host" \
|
||||
"read -r PGPASSWORD; read -r SQL_BASE64; export PGPASSWORD; export PGOPTIONS='-c default_transaction_read_only=on -c search_path=shz,public -c statement_timeout=30000'; SQL=\$(printf '%s' \"\$SQL_BASE64\" | base64 -d); exec ${quoted_psql_path} -X --no-psqlrc -h ${quoted_db_host} -p ${quoted_db_port} -U ${quoted_db_user} -d ${quoted_db_name} -v ON_ERROR_STOP=1 -P pager=off -c \"\$SQL\""
|
||||
|
||||
Reference in New Issue
Block a user