mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 08:13:16 +08:00
Add description, date column to Hibp model
This commit is contained in:
parent
dc83c3dd9e
commit
5aef6cceb2
3 changed files with 37 additions and 1 deletions
|
@ -173,6 +173,9 @@ class Hibp(db.Model, ModelMixin):
|
|||
name = db.Column(db.String(), nullable=False, unique=True, index=True)
|
||||
breached_aliases = db.relationship("Alias", secondary="alias_hibp")
|
||||
|
||||
description = db.Column(db.Text)
|
||||
date = db.Column(ArrowType, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<HIBP Breach {self.id} {self.name}>"
|
||||
|
||||
|
|
4
cron.py
4
cron.py
|
@ -729,7 +729,9 @@ async def check_hibp():
|
|||
LOG.d("Updating list of known breaches")
|
||||
r = requests.get("https://haveibeenpwned.com/api/v3/breaches")
|
||||
for entry in r.json():
|
||||
Hibp.get_or_create(name=entry["Name"])
|
||||
hibp_entry = Hibp.get_or_create(name=entry["Name"])
|
||||
hibp_entry.date = arrow.get(entry["BreachDate"])
|
||||
hibp_entry.description = entry["Description"]
|
||||
|
||||
db.session.commit()
|
||||
LOG.d("Updated list of known breaches")
|
||||
|
|
31
migrations/versions/2021_072908_05e3af59929a_.py
Normal file
31
migrations/versions/2021_072908_05e3af59929a_.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 05e3af59929a
|
||||
Revises: dfee471558bd
|
||||
Create Date: 2021-07-29 08:50:42.388094
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '05e3af59929a'
|
||||
down_revision = 'dfee471558bd'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('hibp', sa.Column('date', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True))
|
||||
op.add_column('hibp', sa.Column('description', sa.Text(), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('hibp', 'description')
|
||||
op.drop_column('hibp', 'date')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue