#!/bin/bash # Setup JetStream stream and consumer for NATS set -euo pipefail echo "🚀 Setting up NATS JetStream..." # scripts/ is a sibling of shfiles/, both under the repo root - cd there so # the relative path below resolves regardless of where this is invoked from. cd "$(dirname "$0")/.." # Check if Python is available if ! command -v python3 &> /dev/null; then echo "❌ Python3 not found. Please install Python3." exit 1 fi # Check if nats-py is installed if ! python3 -c "import nats" 2>/dev/null; then echo "📦 Installing nats-py..." pip3 install nats-py fi # Pull live credentials from the cluster's Secret instead of hardcoding them # here - avoids yet another copy of the password to keep in sync if rotated. if command -v kubectl &> /dev/null && kubectl get secret nats-credentials -n core &> /dev/null 2>&1; then export NATS_USER NATS_USER=$(kubectl get secret nats-credentials -n core -o jsonpath='{.data.username}' | base64 -d) export NATS_PASSWORD NATS_PASSWORD=$(kubectl get secret nats-credentials -n core -o jsonpath='{.data.password}' | base64 -d) else echo "⚠️ Could not read nats-credentials Secret from the cluster (kubectl not available or not connected)." echo " Set NATS_USER / NATS_PASSWORD yourself before running this script." fi export NATS_URL="${NATS_URL:-nats://66.116.226.161:4222}" # Run the setup script python3 scripts/setup_jetstream.py