101 lines
5.1 KiB
Python
101 lines
5.1 KiB
Python
import sys
|
|
import sqlalchemy
|
|
from sqlalchemy.sql import insert
|
|
|
|
def define_db_schema():
|
|
meta = sqlalchemy.MetaData()
|
|
|
|
lacre_keys = sqlalchemy.Table('lacre_keys', meta,
|
|
sqlalchemy.Column('id', sqlalchemy.Integer, primary_key=True),
|
|
sqlalchemy.Column('email', sqlalchemy.String(256)),
|
|
sqlalchemy.Column('publickey', sqlalchemy.Text),
|
|
sqlalchemy.Column('confirm', sqlalchemy.String(32)),
|
|
sqlalchemy.Column('status', sqlalchemy.Integer),
|
|
sqlalchemy.Column('time', sqlalchemy.DateTime))
|
|
|
|
identities = sqlalchemy.Table('lacre_identities', meta,
|
|
sqlalchemy.Column('email', sqlalchemy.String(256), index=True),
|
|
sqlalchemy.Column('fingerprint', sqlalchemy.String(64), index=True))
|
|
|
|
return (meta, lacre_keys, identities)
|
|
|
|
if len(sys.argv) != 2:
|
|
print("ERROR: output database missing")
|
|
sys.exit(1)
|
|
|
|
(meta, lacre_keys, identities) = define_db_schema()
|
|
|
|
dbname = sys.argv[1]
|
|
test_db = sqlalchemy.create_engine(f"sqlite:///{dbname}")
|
|
|
|
# Initialise the schema
|
|
meta.create_all(test_db)
|
|
|
|
conn = test_db.connect()
|
|
|
|
# Populate the database with dummy data
|
|
conn.execute(lacre_keys.insert(), [
|
|
{"id": 1, "email": "alice@disposlab", "publickey": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\
|
|
\n\
|
|
mQGNBGDYY5oBDAC+HAVjA05jsIpHfQ2KQ9m2olo1Qnlk+dkjD+Gagxj1ACezyiGL\n\
|
|
cfZfoE/MJYLCH9yPcX1fUIAPwdAyfJKlvkVcz+MhEpgl3aP3NM2L2unSx3v9ZFwT\n\
|
|
/qyMo9Zst5VSD04TVx2ySQB1vucd2ppgp66X7hlCxs+P8d0FV7VcdrNYol2oOtYP\n\
|
|
yEFXkdyXLI/INI6jrqNkBF87ej+dlTQZAm3zoj61Xwq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dLiGbin/wxiG1CkXGRDN5/r0m/1IoNz\n\
|
|
I4m2SLsB/a89WACQ//CKJyNn4xPOEQoix35tXjdjTLAVyTrX502vHGieZ3HJU2tb\n\
|
|
nmmMf/H0kReMtNYFwHxoTpBJ8vk+xcZ+6ETzH8nk6av+zZ/5T5Y0aD5zO89PcQk6\n\
|
|
pw==\n\
|
|
=Tbwz\n\
|
|
-----END PGP PUBLIC KEY BLOCK-----\
|
|
", "status": 0, "confirm": "", "time": None},
|
|
{"id": 2, "email": "bob@disposlab", "publickey": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\
|
|
\n\
|
|
mDMEYdTFkRYJKwYBBAHaRw8BAQdA2tgdP1pMt3cv3XAW7ov5AFn74mMZvyTksp9Q\n\
|
|
eO1PkpK0GkJvYiBGb29iYXIgPGJvYkBkaXNwb3NsYWI+iJYEExYIAD4WIQQZz0tH\n\
|
|
7MnEevqE1L2W85/aDjG7ZwUCYdTFkQIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgID\n\
|
|
AQIeAQIXgAAKCRCW85/aDjG7ZxVnAP49t7BU2H+/WCpa3fCAlMEcik82sU4p+U9D\n\
|
|
pMsbjawwYgEA1SbA5CF835cMjoEufy1h+2M4T9gI/0X2lk8OAtwwggm4OARh1MXg\n\
|
|
EgorBgEEAZdVAQUBAQdAUVNKx2OsGtNdRsnl3J/uv6obkUC0KcO4ikdRs+iejlMD\n\
|
|
AQgHiHgEGBYIACAWIQQZz0tH7MnEevqE1L2W85/aDjG7ZwUCYdTF4AIbDAAKCRCW\n\
|
|
85/aDjG7Z039APwLGP5ibqCC9yIr4YVbdWff1Ch+2C91MR2ObF93Up9+ogD8D2zd\n\
|
|
OjjB6xRD0Q2FN+alsNGCtdutAs18AZ5l33RMzws=\n\
|
|
=wWoq\n\
|
|
-----END PGP PUBLIC KEY BLOCK-----\
|
|
", "status": 0, "confirm": "", "time": None},
|
|
{"id": 3, "email": "cecil@lacre.io", "publickey": "RUBBISH", "status": 0, "confirm": "", "time": None}
|
|
])
|
|
|
|
conn.execute(identities.insert(), [
|
|
{'fingerprint': '1CD245308F0963D038E88357973CF4D9387C44D7', 'email': 'alice@disposlab'},
|
|
{'fingerprint': '19CF4B47ECC9C47AFA84D4BD96F39FDA0E31BB67', 'email': 'bob@disposlab'},
|
|
{'fingerprint': '530B1BB2D0CC7971648198BBA4774E507D3AF5BC', 'email': 'evan@disposlab'}
|
|
])
|