From 6c6ab42fa34561956e2766060c0c8b9435982a3d Mon Sep 17 00:00:00 2001 From: Socorro DominguezVidana Date: Tue, 18 Aug 2026 14:55:39 -0700 Subject: [PATCH] NCC-28 make sure that we are loading the tank when choosing the dev stack --- entrypoint.sh | 10 ++++++++++ ndbdoi.py | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index e325612..91d5544 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -28,6 +28,16 @@ for arg in "$@"; do esac done +# The dev stack reaches the holding tank through DBAUTH rather than through the +# `-t` flag, so the loop above cannot see it. Without this, `environment: dev` +# combined with `mode: full` would publish tank records as permanent 10.21233 +# DOIs. Defaulting to `prod` when unset means a missing variable still mints +# rather than silently disabling production. +if [ "${NEOTOMA_ENVIRONMENT:-prod}" = "dev" ]; then + echo "Dev environment; forcing GATE_ONLY so tank data cannot reach production DataCite." + GATE_ONLY=1 +fi + RUN_ID="$(date -u +%Y-%m-%dT%H-%M-%SZ)" LOG_DIR=/tmp/minting-logs mkdir -p "$LOG_DIR" diff --git a/ndbdoi.py b/ndbdoi.py index 02d387d..9bfaa2f 100644 --- a/ndbdoi.py +++ b/ndbdoi.py @@ -27,7 +27,7 @@ import psycopg2 import psycopg2.extras -from dotenv import load_dotenv +from dotenv import dotenv_values, load_dotenv import neotomadoi @@ -77,11 +77,27 @@ def parse_args(): parser.error("-f/--force can only be used with -d/--datasets.") return args +def _database_name(args): + """Name the database this run will actually connect to. + + `-t/--tank` selects which connection string is read, but the database itself + is whatever that string names. In the deployed dev stack DBAUTH points at + the holding tank, so reporting the flag alone would print "Production" for a + run against `neotomatank`. Read the same value `neo_connect()` does. + """ + key = "DBAUTH_TEST" if args.tank else "DBAUTH" + secrets = {**dotenv_values(), **os.environ} + try: + conn = json.loads(secrets[key]) + return f"{conn.get('database', '?')} on {conn.get('host', '?')}" + except (KeyError, ValueError, TypeError): + return f"unknown ({key} missing or unreadable)" + def printargs(args, datasetids): runstart = datetime.now(UTC).isoformat() print("*** Neotoma DOI Generator ***") print(f"Run: {runstart}") - print(f"Database: {'Tank' if args.tank else 'Production'}") + print(f"Database: {_database_name(args)}") print(f"DataCite: {'Production' if args.mint else 'Sandbox'}") print(f"Datasets: {len(datasetids)} to process") print("-" * 50)