Security: remove hardcoded credentials, fix db_init for non-owner users #1

Merged
dom merged 2 commits from security/remove-hardcoded-secrets into main 2026-07-14 09:44:23 +00:00
Showing only changes of commit 94bfc60fc4 - Show all commits

51
main.py
View File

@@ -411,28 +411,37 @@ def db_init(cur):
updated_ts timestamptz NOT NULL DEFAULT now() updated_ts timestamptz NOT NULL DEFAULT now()
); );
""") """)
cur.execute(""" for col, typedef in [
ALTER TABLE remote_cam.import_job ("needs_ocr_backfill", "boolean NOT NULL DEFAULT false"),
ADD COLUMN IF NOT EXISTS needs_ocr_backfill boolean NOT NULL DEFAULT false; ("needs_exif_backfill", "boolean NOT NULL DEFAULT false"),
""") ]:
cur.execute(""" cur.execute("""
ALTER TABLE remote_cam.import_job SELECT 1 FROM information_schema.columns
ADD COLUMN IF NOT EXISTS needs_exif_backfill boolean NOT NULL DEFAULT false; WHERE table_schema='remote_cam' AND table_name='import_job' AND column_name=%s
""") """, (col,))
cur.execute("CREATE INDEX IF NOT EXISTS import_job_needs_ocr_idx ON remote_cam.import_job(needs_ocr_backfill);") if not cur.fetchone():
cur.execute("CREATE INDEX IF NOT EXISTS import_job_needs_exif_idx ON remote_cam.import_job(needs_exif_backfill);") cur.execute(f"ALTER TABLE remote_cam.import_job ADD COLUMN {col} {typedef};")
cur.execute("CREATE INDEX IF NOT EXISTS import_job_status_idx ON remote_cam.import_job(status);") for idx, col in [
cur.execute("CREATE INDEX IF NOT EXISTS import_job_updated_idx ON remote_cam.import_job(updated_ts);") ("import_job_needs_ocr_idx", "needs_ocr_backfill"),
("import_job_needs_exif_idx", "needs_exif_backfill"),
("import_job_status_idx", "status"),
("import_job_updated_idx", "updated_ts"),
]:
cur.execute("SELECT 1 FROM pg_indexes WHERE schemaname='remote_cam' AND indexname=%s", (idx,))
if not cur.fetchone():
cur.execute(f"CREATE INDEX {idx} ON remote_cam.import_job({col});")
cur.execute(""" cur.execute("SELECT 1 FROM pg_proc JOIN pg_namespace ON pg_proc.pronamespace=pg_namespace.oid WHERE nspname='remote_cam' AND proname='set_updated_ts'")
CREATE OR REPLACE FUNCTION remote_cam.set_updated_ts() if not cur.fetchone():
RETURNS trigger AS $$ cur.execute("""
BEGIN CREATE FUNCTION remote_cam.set_updated_ts()
NEW.updated_ts = now(); RETURNS trigger AS $$
RETURN NEW; BEGIN
END; NEW.updated_ts = now();
$$ LANGUAGE plpgsql; RETURN NEW;
""") END;
$$ LANGUAGE plpgsql;
""")
cur.execute(""" cur.execute("""
DO $$ DO $$
BEGIN BEGIN