Refactor ApiKeys.secret and ServiceInboundApi.bearer_token to use the same encryption method and get rid of the duplicate code.

This commit is contained in:
Rebecca Law
2017-06-19 14:32:22 +01:00
parent 6202da7dea
commit 3a66027d6a
15 changed files with 55 additions and 79 deletions

View File

@@ -1,7 +1,6 @@
from datetime import datetime
from app import db, create_uuid
from app.authentication.utils import generate_secret
from app.dao.dao_utils import transactional, version_class
from app.models import ServiceInboundApi
@@ -11,7 +10,7 @@ from app.models import ServiceInboundApi
def save_service_inbound_api(service_inbound_api):
service_inbound_api.id = create_uuid()
service_inbound_api.created_at == datetime.utcnow()
service_inbound_api.bearer_token = generate_secret(service_inbound_api.bearer_token)
service_inbound_api.bearer_token = service_inbound_api.bearer_token
db.session.add(service_inbound_api)
@@ -21,7 +20,7 @@ def reset_service_inbound_api(service_inbound_api, updated_by_id, url=None, bear
if url:
service_inbound_api.url = url
if bearer_token:
service_inbound_api.bearer_token = generate_secret(bearer_token)
service_inbound_api.bearer_token = bearer_token
service_inbound_api.updated_by_id = updated_by_id
service_inbound_api.updated_at = datetime.utcnow()