cacert-webdb/scripts/check_db_certificates.py

28 lines
785 B
Python
Raw Normal View History

2024-05-13 20:33:10 +00:00
#!/usr/bin/env python3
from sqlalchemy import create_engine, select, MetaData, Table
from pprint import pprint
import os
db_user = os.getenv("db_user", default="cacert")
db_password = os.getenv("db_password", default="cacert")
db_host = os.getenv("db_host", "localhost")
db_port = os.getenv("db_port", "3306")
db_name = os.getenv("db_name", "cacert")
dsn = (
f"mariadb+mariadbconnector://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"
)
engine = create_engine(dsn)
metadata_obj = MetaData()
for table in ("emailcerts", "domaincerts", "orgemailcerts", "orgdomaincerts"):
certs_table = Table(table, metadata_obj, autoload_with=engine)
stmt = select(certs_table)
with engine.connect() as conn:
for row in conn.execute(stmt):
pprint(row)