Refactor the api_key_dao.

The only update we should be doing to an api key is to expire/revoke the api key.
Removed the update_dict from the the save method.
Added an expire_api_key method that only updates the api key with an expiry date.
This commit is contained in:
Rebecca Law
2016-06-22 15:27:28 +01:00
parent 1659b64f9e
commit acee87fc63
5 changed files with 39 additions and 45 deletions

View File

@@ -14,8 +14,8 @@ from sqlalchemy.orm.exc import NoResultFound
from app.dao.api_key_dao import (
save_model_api_key,
get_model_api_keys,
get_unsigned_secret
)
get_unsigned_secret,
expire_api_key)
from app.dao.services_dao import (
dao_fetch_service_by_id_and_user,
dao_fetch_service_by_id,
@@ -95,6 +95,7 @@ def update_service(service_id):
return jsonify(data=service_schema.dump(fetched_service).data), 200
# is this used.
@service.route('/<uuid:service_id>/api-key', methods=['POST'])
def renew_api_key(service_id=None):
fetched_service = dao_fetch_service_by_id(service_id=service_id)
@@ -107,8 +108,7 @@ def renew_api_key(service_id=None):
@service.route('/<uuid:service_id>/api-key/revoke/<uuid:api_key_id>', methods=['POST'])
def revoke_api_key(service_id, api_key_id):
service_api_key = get_model_api_keys(service_id=service_id, id=api_key_id)
save_model_api_key(service_api_key, update_dict={'expiry_date': datetime.utcnow()})
expire_api_key(service_id=service_id, api_key_id=api_key_id)
return jsonify(), 202