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,14 +1,13 @@
import uuid
from datetime import datetime
from app import db
from app import db, encryption
from app.models import ApiKey
from app.dao.dao_utils import (
transactional,
version_class
)
from app.authentication.utils import generate_secret
@transactional
@@ -16,7 +15,7 @@ from app.authentication.utils import generate_secret
def save_model_api_key(api_key):
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(uuid.uuid4())
api_key.secret = uuid.uuid4()
db.session.add(api_key)
@@ -39,7 +38,7 @@ def get_unsigned_secrets(service_id):
This method can only be exposed to the Authentication of the api calls.
"""
api_keys = ApiKey.query.filter_by(service_id=service_id, expiry_date=None).all()
keys = [x.unsigned_secret for x in api_keys]
keys = [x.secret for x in api_keys]
return keys
@@ -48,4 +47,4 @@ def get_unsigned_secret(key_id):
This method can only be exposed to the Authentication of the api calls.
"""
api_key = ApiKey.query.filter_by(id=key_id, expiry_date=None).one()
return api_key.unsigned_secret
return api_key.secret