Files
errors.bitreport.pt/scripts/offboard-project.sh
David SantosandCursor 8773f12b25
CI / Validate Docker build (pull_request) Failing after 12m46s
CI / Lint and typecheck admin-ui (pull_request) Failing after 13m16s
CI / Test api (pull_request) Failing after 13m20s
CI / Test ingest-api (pull_request) Successful in 15m35s
feat(hub): retire WDMI projects from error reporting (BIT-24704)
Block ingest for retired WDMI slugs, purge project data via migration,
remove WDMI runbooks, and add offboard-project helper for future retirements.

Co-authored-by: Cursor <[email protected]>
2026-06-08 14:26:06 +00:00

68 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# offboard-project.sh — revoke keys, disable collectors, and delete a project from error_reporting.
#
# Usage:
# offboard-project.sh <slug>
#
# Example:
# ./scripts/offboard-project.sh wdmi-store
#
# Environment:
# DATABASE_URL If set and mysql client available, applies SQL directly.
# Otherwise prints SQL to stdout.
set -euo pipefail
_die() { echo "error: $*" >&2; exit 1; }
[[ $# -eq 1 ]] || _die "Usage: offboard-project.sh <slug>"
SLUG="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
[[ "${SLUG}" =~ ^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$ ]] \
|| _die "slug must be 2-64 lowercase alphanumeric/hyphens: ${SLUG}"
SQL="$(cat <<EOSQL
-- Offboard project: ${SLUG}
BEGIN;
UPDATE er_ingest_keys k
INNER JOIN er_projects p ON p.id = k.project_id
SET k.status = 'revoked',
k.revoked_at = NOW(6)
WHERE LOWER(p.slug) = '${SLUG}';
UPDATE er_collector_sources cs
INNER JOIN er_projects p ON p.id = cs.project_id
SET cs.is_active = FALSE
WHERE LOWER(p.slug) = '${SLUG}';
DELETE FROM er_projects WHERE LOWER(slug) = '${SLUG}';
COMMIT;
EOSQL
)"
echo "================================================================"
echo " Offboard project slug: ${SLUG}"
echo "================================================================"
echo ""
echo "--- SQL (apply to error_reporting database) ---"
echo "${SQL}"
echo ""
if [[ -n "${DATABASE_URL:-}" ]] && command -v mysql >/dev/null 2>&1; then
echo "DATABASE_URL is set. Applying SQL..."
DB_URL="${DATABASE_URL#mysql://}"
DB_USER="${DB_URL%%:*}"
DB_REST="${DB_URL#*:}"
DB_PASS="${DB_REST%%@*}"
DB_REST="${DB_REST#*@}"
DB_HOST="${DB_REST%%:*}"
DB_REST="${DB_REST#*:}"
DB_PORT="${DB_REST%%/*}"
DB_NAME="${DB_REST#*/}"
echo "${SQL}" | mysql -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASS}" "${DB_NAME}"
echo "Applied successfully."
fi