feat: добавить скрипт сбора evidence с редактированием секретов
Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
#!/bin/sh
|
||||
# Collect evidence for lab3 report. Redacts secrets before writing.
|
||||
# Usage: sh scripts/collect-evidence.sh
|
||||
set -u
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p evidence
|
||||
|
||||
redact() {
|
||||
# Strip Authorization headers, tokens, passwords from stdin.
|
||||
sed -E \
|
||||
-e 's/(Authorization:[[:space:]]*)[^[:space:]]+/\1<redacted>/Ig' \
|
||||
-e 's/("token"[[:space:]]*:[[:space:]]*")[^"]+/\1<redacted>/g' \
|
||||
-e 's/("password"[[:space:]]*:[[:space:]]*")[^"]+/\1<redacted>/g' \
|
||||
-e 's/(POSTGRES_PASSWORD=)[^[:space:]]+/\1<redacted>/g'
|
||||
}
|
||||
|
||||
run_step() {
|
||||
name="$1"; shift
|
||||
out="evidence/$name"
|
||||
echo "# $name — $(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$out"
|
||||
echo "# cmd: $*" >> "$out"
|
||||
if "$@" 2>&1 | redact >> "$out"; then
|
||||
echo "# status: OK" >> "$out"
|
||||
else
|
||||
echo "# status: FAILED" >> "$out"
|
||||
fi
|
||||
}
|
||||
|
||||
BASE_URL="${BASE_URL:-http://localhost:8080}"
|
||||
|
||||
run_step smoke.txt make test BASE_URL="$BASE_URL"
|
||||
run_step persistence.txt make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
||||
run_step failover.txt make test-failover ACTION_SCRIPT=scripts/stop-one.sh
|
||||
run_step dependency.txt python3 tests/test_dependency_failure.py --base-url "$BASE_URL"
|
||||
|
||||
# Instances: 6 requests, extract X-Instance-Id.
|
||||
{
|
||||
echo "# instances — $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
echo "# cmd: 6x curl -sI $BASE_URL/health/live"
|
||||
i=0
|
||||
while [ $i -lt 6 ]; do
|
||||
curl -sI "$BASE_URL/health/live" | grep -i '^x-instance-id:' || echo "x-instance-id: <missing>"
|
||||
i=$((i+1))
|
||||
done
|
||||
} > evidence/instances.txt
|
||||
|
||||
# Health with headers.
|
||||
{
|
||||
echo "# health — $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
echo "## /health/live"
|
||||
curl -s -D - -o /dev/null "$BASE_URL/health/live" | redact
|
||||
echo "## /health/ready"
|
||||
curl -s -D - -o /dev/null "$BASE_URL/health/ready" | redact
|
||||
} > evidence/health.txt
|
||||
|
||||
# Compose config (redacted).
|
||||
{
|
||||
echo "# compose-config — $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
docker compose --env-file .env config 2>&1 | redact
|
||||
} > evidence/compose-config.txt
|
||||
|
||||
# Migrate logs.
|
||||
{
|
||||
echo "# migrate — $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
docker compose --env-file .env logs migrate 2>&1 | redact
|
||||
} > evidence/migrate.txt
|
||||
|
||||
# Load test.
|
||||
{
|
||||
echo "# load — $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
python3 tests/load.py --duration 30 --concurrency 4 --output evidence/load.json 2>&1 | redact
|
||||
} > evidence/load.txt
|
||||
|
||||
echo "Evidence collected in evidence/"
|
||||
Reference in New Issue
Block a user