2019-07-10 17:17:50 +02:00
|
|
|
import yaml
|
|
|
|
from passlib.hash import bcrypt
|
|
|
|
|
2019-07-20 16:27:56 +02:00
|
|
|
from lambdas.create_keys import create_key_pair
|
2019-07-10 17:17:50 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-07-20 16:27:56 +02:00
|
|
|
keypair = create_key_pair(key_size=2048)
|
|
|
|
with open("public_key.pem", "w") as f:
|
|
|
|
f.write(keypair["public"])
|
|
|
|
|
|
|
|
with open("private_key.pem", "w") as f:
|
|
|
|
f.write(keypair["private"])
|
|
|
|
|
|
|
|
from accounts import db
|
|
|
|
from accounts.models import Account, User, AccountUserAssociation
|
|
|
|
|
2019-07-10 17:17:50 +02:00
|
|
|
db.drop_all()
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
with open("./bootstrap.yml", "r") as stream:
|
|
|
|
data = yaml.safe_load(stream)
|
|
|
|
|
|
|
|
for account in data["accounts"]:
|
|
|
|
record = Account(
|
|
|
|
name=account["name"],
|
|
|
|
account_id=account["id"],
|
|
|
|
)
|
|
|
|
db.session.add(record)
|
|
|
|
|
2019-07-13 22:04:12 +02:00
|
|
|
for user in data["users"]:
|
|
|
|
record = User(
|
|
|
|
email=user["email"],
|
|
|
|
hashed_password=bcrypt.hash(user["password"]),
|
|
|
|
)
|
|
|
|
for account_id in user["accounts"]:
|
|
|
|
record.accounts.append(AccountUserAssociation(account_id=account_id))
|
|
|
|
db.session.add(record)
|
|
|
|
|
2019-07-10 17:17:50 +02:00
|
|
|
db.session.commit()
|
|
|
|
|
2019-07-20 16:27:56 +02:00
|
|
|
print("Successfully bootstrapped accounts database and created key pair")
|