mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
reformat
This commit is contained in:
@@ -14,51 +14,59 @@ from app.webauthn.webauthn_schema import (
|
||||
post_update_webauthn_credential_schema,
|
||||
)
|
||||
|
||||
webauthn_blueprint = Blueprint('webauthn', __name__, url_prefix='/user/<uuid:user_id>/webauthn')
|
||||
webauthn_blueprint = Blueprint(
|
||||
"webauthn", __name__, url_prefix="/user/<uuid:user_id>/webauthn"
|
||||
)
|
||||
register_errors(webauthn_blueprint)
|
||||
|
||||
|
||||
@webauthn_blueprint.route('', methods=['GET'])
|
||||
@webauthn_blueprint.route("", methods=["GET"])
|
||||
def get_webauthn_credentials(user_id):
|
||||
user = get_user_by_id(user_id)
|
||||
return jsonify(data=[cred.serialize() for cred in user.webauthn_credentials]), 200
|
||||
|
||||
|
||||
@webauthn_blueprint.route('', methods=['POST'])
|
||||
@webauthn_blueprint.route("", methods=["POST"])
|
||||
def create_webauthn_credential(user_id):
|
||||
data = request.get_json()
|
||||
validate(data, post_create_webauthn_credential_schema)
|
||||
webauthn_credential = dao_create_webauthn_credential(
|
||||
user_id=user_id,
|
||||
name=data['name'],
|
||||
credential_data=data['credential_data'],
|
||||
registration_response=data['registration_response']
|
||||
name=data["name"],
|
||||
credential_data=data["credential_data"],
|
||||
registration_response=data["registration_response"],
|
||||
)
|
||||
|
||||
return jsonify(data=webauthn_credential.serialize()), 201
|
||||
|
||||
|
||||
@webauthn_blueprint.route('/<uuid:webauthn_credential_id>', methods=['POST'])
|
||||
@webauthn_blueprint.route("/<uuid:webauthn_credential_id>", methods=["POST"])
|
||||
def update_webauthn_credential(user_id, webauthn_credential_id):
|
||||
data = request.get_json()
|
||||
validate(data, post_update_webauthn_credential_schema)
|
||||
|
||||
webauthn_credential = dao_get_webauthn_credential_by_user_and_id(user_id, webauthn_credential_id)
|
||||
webauthn_credential = dao_get_webauthn_credential_by_user_and_id(
|
||||
user_id, webauthn_credential_id
|
||||
)
|
||||
|
||||
dao_update_webauthn_credential_name(webauthn_credential, data['name'])
|
||||
dao_update_webauthn_credential_name(webauthn_credential, data["name"])
|
||||
|
||||
return jsonify(data=webauthn_credential.serialize()), 200
|
||||
|
||||
|
||||
@webauthn_blueprint.route('/<uuid:webauthn_credential_id>', methods=['DELETE'])
|
||||
@webauthn_blueprint.route("/<uuid:webauthn_credential_id>", methods=["DELETE"])
|
||||
def delete_webauthn_credential(user_id, webauthn_credential_id):
|
||||
webauthn_credential = dao_get_webauthn_credential_by_user_and_id(user_id, webauthn_credential_id)
|
||||
webauthn_credential = dao_get_webauthn_credential_by_user_and_id(
|
||||
user_id, webauthn_credential_id
|
||||
)
|
||||
user = get_user_by_id(user_id)
|
||||
|
||||
if len(user.webauthn_credentials) == 1:
|
||||
# TODO: Only raise an error if user has auth type webauthn_auth
|
||||
raise InvalidRequest('Cannot delete last remaining webauthn credential for user', status_code=400)
|
||||
raise InvalidRequest(
|
||||
"Cannot delete last remaining webauthn credential for user", status_code=400
|
||||
)
|
||||
|
||||
dao_delete_webauthn_credential(webauthn_credential)
|
||||
|
||||
return '', 204
|
||||
return "", 204
|
||||
|
||||
@@ -8,7 +8,7 @@ post_create_webauthn_credential_schema = {
|
||||
"registration_response": {"type": "string", "minLength": 1},
|
||||
},
|
||||
"required": ["name", "credential_data", "registration_response"],
|
||||
"additionalProperties": False
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
post_update_webauthn_credential_schema = {
|
||||
@@ -19,5 +19,5 @@ post_update_webauthn_credential_schema = {
|
||||
"name": {"type": "string", "minLength": 1},
|
||||
},
|
||||
"required": ["name"],
|
||||
"additionalProperties": False
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user