Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions ndbdoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import psycopg2
import psycopg2.extras
from dotenv import load_dotenv
from dotenv import dotenv_values, load_dotenv

import neotomadoi

Expand Down Expand Up @@ -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)
Expand Down