This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
141 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_sqlalchemy.model import Model | ||
from werkzeug.utils import import_string | ||
|
||
import os | ||
|
||
# Flask Settings | ||
|
||
app = Flask(__name__) | ||
|
||
cfg = import_string(os.environ.get('FLASK_APPSETTINGS'))() | ||
app.config.from_object(cfg) | ||
|
||
db = SQLAlchemy(app) | ||
# SQLAlchemy settings | ||
|
||
class BaseModel(Model): | ||
def save(self): | ||
db.session.add(self) | ||
db.session.commit() | ||
|
||
db = SQLAlchemy(app, model_class=BaseModel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .customer_personal_info import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
from flask.globals import session | ||
from sqlalchemy_utils.types.encrypted.encrypted_type import AesEngine, FernetEngine | ||
from sqlalchemy_utils import EncryptedType | ||
from cryptography.fernet import Fernet | ||
|
||
from app import db | ||
from models.customers import Customers | ||
|
||
|
||
def _get_customer_personal_info(model, ColumnType, engine, key): | ||
|
||
AnonymizedColumnsMixin = type('AnonymizedColumnsMixin', (), { | ||
column.name: db.Column(ColumnType(column.type, key, engine)) | ||
for column in model.__table__.columns | ||
if column.info.get('anonymize') | ||
}) | ||
|
||
class CustomerPersonalInfo(AnonymizedColumnsMixin, db.Model): | ||
""" | ||
Class writes deleted customer's personal info encrypted | ||
on the isolated database | ||
""" | ||
__bind_key__ = 'db_isolated' | ||
__tablename__ = 'customers_personal_info' | ||
|
||
customerid = db.Column('customerid', db.Integer, primary_key=True) | ||
|
||
@classmethod | ||
def from_customer(cls, customer): | ||
self = cls() | ||
for column in self.__table__.columns: | ||
setattr(self, column.name, getattr(customer, column.name)) | ||
return self | ||
|
||
return CustomerPersonalInfo | ||
|
||
|
||
def _get_key(): | ||
session['cryptkey'] = session.get('cryptkey', Fernet.generate_key()) | ||
return session['cryptkey'] | ||
|
||
class CustomerPersonalInfo(db.Model): | ||
__bind_key__ = 'db_isolated' | ||
|
||
CustomerPersonalInfo = _get_customer_personal_info( | ||
Customers, EncryptedType, FernetEngine, _get_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters