Add NASA FIRMS active-fire ingest + /api/fires; API keys management page
Coherent merge of two coordinated features on the shared working tree: FIRMS fire heatmap (backend, t_6e404c14): - app/fire_sources.py: fetch FIRMS VIIRS area CSV (free MAP_KEY) -> NATS events.fire - fires hypertable (TimescaleDB, 1-day chunks) with natural-key PK (latitude, longitude, acq_time, satellite); idempotent ON CONFLICT DO NOTHING - alembic/versions/002_fires.py; GET /api/fires?bbox=&since= (JSON only) - POST /api/ingest/fires; ~15 min poll loop (FIRMS_INTERVAL=900) in ingester - env-driven config (FIRMS_MAP_KEY/DATASET/BBOX/INTERVAL); docs/firms.md covers the zero-cost GIBS VIIRS_SNPP_Thermal_Anomalies_375m_All tile alternative - 18 tests (parser, mapping, idempotency, API contract) verified vs real TimescaleDB+PostGIS (localhost/osint-dashboard-pg image) API keys page (frontend, t_4433cff2): - app/keystore.py: api_keys table (self-creating), FIRMS/GEMINI/TELEGRAM registry with format validation, ****last4 masking, get_api_key() - GET/POST/DELETE /api/keys (never returns full values); Keys tab in index.html DB_NULL_POOL env switch in app/database.py enables a NullPool for tests / short-lived processes that open a fresh event loop per unit.
This commit is contained in:
parent
bce2d5c3bd
commit
627990efde
19 changed files with 1428 additions and 10 deletions
|
|
@ -40,6 +40,26 @@
|
|||
.sentiment-bar div { transition: width 0.3s; }
|
||||
.tab-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
|
||||
.tab-bar .btn.active { background: var(--accent); color: #0f172a; }
|
||||
.key-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
|
||||
.key-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; box-shadow: 0 0 18px rgba(56,189,248,0.06); transition: box-shadow .2s, border-color .2s; }
|
||||
.key-card:hover { box-shadow: 0 0 22px rgba(56,189,248,0.14); }
|
||||
.key-card.set { border-color: rgba(74,222,128,0.5); box-shadow: 0 0 18px rgba(74,222,128,0.14); }
|
||||
.key-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
|
||||
.key-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; font-weight: 600; color: var(--accent); word-break: break-all; }
|
||||
.key-status { font-size: 0.72rem; font-family: ui-monospace, monospace; padding: 0.2rem 0.55rem; border-radius: 9999px; white-space: nowrap; }
|
||||
.key-status.set { background: rgba(74,222,128,0.12); color: var(--green); box-shadow: 0 0 10px rgba(74,222,128,0.35); }
|
||||
.key-status.missing { background: rgba(248,113,113,0.12); color: var(--red); box-shadow: 0 0 10px rgba(248,113,113,0.25); }
|
||||
.key-desc { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.7rem; }
|
||||
.key-hint { font-size: 0.72rem; color: var(--muted); opacity: 0.8; margin-top: 0.15rem; }
|
||||
.key-form { display: flex; gap: 0.5rem; }
|
||||
.key-form input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.6rem; color: var(--text); font-size: 0.85rem; font-family: ui-monospace, monospace; }
|
||||
.key-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 8px rgba(56,189,248,0.35); }
|
||||
.key-form .btn { white-space: nowrap; }
|
||||
.key-form .btn-danger { border-color: var(--red); color: var(--red); }
|
||||
.key-form .btn-danger:hover { background: rgba(248,113,113,0.12); }
|
||||
.key-msg { margin-top: 0.5rem; font-size: 0.8rem; min-height: 1rem; }
|
||||
.key-msg.ok { color: var(--green); }
|
||||
.key-msg.err { color: var(--red); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -85,6 +105,7 @@
|
|||
<button class="btn" onclick="showTab('alerts')">Alerts</button>
|
||||
<button class="btn" onclick="showTab('entities')">Entities</button>
|
||||
<button class="btn" onclick="showTab('ingest')">Ingest</button>
|
||||
<button class="btn" onclick="showTab('keys')">Keys</button>
|
||||
</div>
|
||||
|
||||
<!-- Recent Events -->
|
||||
|
|
@ -144,6 +165,13 @@
|
|||
<div id="ingest-result" style="margin-top:1rem;color:var(--muted);font-size:0.9rem"></div>
|
||||
</div>
|
||||
|
||||
<!-- API Keys -->
|
||||
<div class="section" id="tab-keys" style="display:none">
|
||||
<h2>API Keys</h2>
|
||||
<p class="sub" style="margin-bottom:0.75rem">Keys used by ingest services (FIRMS, Gemini, Telegram, ...). Values are stored in Postgres and never shown again — only set/missing status and the last 4 chars are displayed.</p>
|
||||
<div class="key-grid" id="keys-grid"></div>
|
||||
</div>
|
||||
|
||||
<!-- Search Results -->
|
||||
<div class="section" id="search-results" style="display:none">
|
||||
<h2>Search Results (<span id="search-total">0</span>)</h2>
|
||||
|
|
@ -247,15 +275,83 @@ function sentimentBadge(label) {
|
|||
return `<span class="badge ${cls}">${label}</span>`;
|
||||
}
|
||||
|
||||
// ── API Keys ────────────────────────────────────────────────────────────
|
||||
// Mirrors the backend keystore registry for instant client-side format hints.
|
||||
const KEY_PATTERNS = {
|
||||
'FIRMS_MAP_KEY': /^[0-9a-fA-F]{32}$/,
|
||||
'GEMINI_API_KEY': /^AIza[0-9A-Za-z_-]{35}$/,
|
||||
'TELEGRAM_TOKEN': /^\d{8,10}:[0-9A-Za-z_-]{35}$/,
|
||||
};
|
||||
|
||||
async function loadKeys() {
|
||||
try {
|
||||
const r = await fetch(`${API}/api/keys`);
|
||||
const d = await r.json();
|
||||
const grid = document.getElementById('keys-grid');
|
||||
grid.innerHTML = d.map(k => {
|
||||
const hint = k.validated && k.example ? `<div class="key-hint">expected: ${k.example}</div>` : '';
|
||||
return `<div class="key-card ${k.set?'set':''}">
|
||||
<div class="key-head">
|
||||
<span class="key-name">${k.name}</span>
|
||||
<span class="key-status ${k.set?'set':'missing'}">${k.set?'●':'○'} ${k.set ? (k.masked||'set') : 'missing'}</span>
|
||||
</div>
|
||||
<div class="key-desc">${k.description || 'Custom key (not in registry).'}${hint}</div>
|
||||
<div class="key-form">
|
||||
<input type="password" id="key-in-${k.name}" placeholder="Paste new value…" autocomplete="off" spellcheck="false">
|
||||
<button class="btn" onclick="saveKey('${k.name}')">Save</button>
|
||||
${k.set ? `<button class="btn btn-danger" onclick="clearKey('${k.name}')">Clear</button>` : ''}
|
||||
</div>
|
||||
<div class="key-msg" id="key-msg-${k.name}"></div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
} catch(e) { console.error('Keys load failed', e); }
|
||||
}
|
||||
|
||||
function keyMsg(name, text, isErr) {
|
||||
const el = document.getElementById('key-msg-'+name);
|
||||
if (el) { el.textContent = text; el.className = 'key-msg ' + (isErr ? 'err' : 'ok'); }
|
||||
}
|
||||
|
||||
async function saveKey(name) {
|
||||
const input = document.getElementById('key-in-'+name);
|
||||
const value = (input.value||'').trim();
|
||||
if (!value) { keyMsg(name, 'Enter a value to save.', true); return; }
|
||||
const pat = KEY_PATTERNS[name];
|
||||
if (pat && !pat.test(value)) { keyMsg(name, 'Format check failed — see the expected format above.', true); return; }
|
||||
try {
|
||||
const r = await fetch(`${API}/api/keys/${encodeURIComponent(name)}`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({value})
|
||||
});
|
||||
const d = await r.json().catch(() => ({}));
|
||||
if (!r.ok) { keyMsg(name, d.detail || 'Save failed', true); return; }
|
||||
input.value = '';
|
||||
keyMsg(name, `Saved (${d.masked || 'set'}).`, false);
|
||||
loadKeys();
|
||||
} catch(e) { keyMsg(name, 'Network error.', true); }
|
||||
}
|
||||
|
||||
async function clearKey(name) {
|
||||
if (!confirm(`Delete ${name}? This cannot be undone.`)) return;
|
||||
try {
|
||||
const r = await fetch(`${API}/api/keys/${encodeURIComponent(name)}`, {method:'DELETE'});
|
||||
if (!r.ok) { keyMsg(name, 'Clear failed.', true); return; }
|
||||
keyMsg(name, 'Key removed.', false);
|
||||
loadKeys();
|
||||
} catch(e) { keyMsg(name, 'Network error.', true); }
|
||||
}
|
||||
|
||||
function showTab(name) {
|
||||
['recent','alerts','entities','ingest'].forEach(t => {
|
||||
['recent','alerts','entities','ingest','keys'].forEach(t => {
|
||||
document.getElementById('tab-'+t).style.display = t===name?'block':'none';
|
||||
});
|
||||
document.querySelectorAll('.tab-bar .btn').forEach((b,i) => {
|
||||
b.classList.toggle('active', ['recent','alerts','entities','ingest'][i]===name);
|
||||
b.classList.toggle('active', ['recent','alerts','entities','ingest','keys'][i]===name);
|
||||
});
|
||||
if (name==='alerts') loadAlerts();
|
||||
if (name==='entities') loadEntities();
|
||||
if (name==='keys') loadKeys();
|
||||
}
|
||||
|
||||
async function ingestRSS() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue