Added version history to api keys. This needed a bit of change

to create history to handle foreign keys better. There may yet
be a better way of doing this that I have not found yet in sqlalchemy
docs.
This commit is contained in:
Adam Shimali
2016-04-20 17:25:20 +01:00
parent a3651c8398
commit 74ac5b5f30
10 changed files with 296 additions and 138 deletions

View File

@@ -1,19 +1,30 @@
import uuid
from flask import current_app
from itsdangerous import URLSafeSerializer
from app import db
from app.models import ApiKey
from app.dao.dao_utils import (
transactional,
versioned
)
@transactional
@versioned
def save_model_api_key(api_key, update_dict={}):
if update_dict:
if update_dict['id']:
if update_dict.get('id'):
del update_dict['id']
db.session.query(ApiKey).filter_by(id=api_key.id).update(update_dict)
for key, value in update_dict.items():
setattr(api_key, key, update_dict[key])
db.session.add(api_key)
else:
if not api_key.id:
api_key.id = uuid.uuid4() # must be set now so version history model can use same id
api_key.secret = _generate_secret()
db.session.add(api_key)
db.session.commit()
def get_model_api_keys(service_id, id=None):