@admin_bp.route('/manage-keys', methods=['GET', 'POST'])
@login_required
@operator_role_required
def manage_keys():
    if (request.method == 'GET'):
        try:
            apikeys = ApiKey.query.all()
        except Exception as e:
            current_app.logger.error('Error: {0}'.format(e))
            abort(500)
        return render_template('admin_manage_keys.html', keys=apikeys)
    elif (request.method == 'POST'):
        jdata = request.json
        if (jdata['action'] == 'delete_key'):
            apikey = ApiKey.query.get(jdata['data'])
            try:
                history_apikey_id = apikey.id
                history_apikey_role = apikey.role.name
                history_apikey_description = apikey.description
                history_apikey_domains = [domain.name for domain in apikey.domains]
                apikey.delete()
            except Exception as e:
                current_app.logger.error('Error: {0}'.format(e))
            current_app.logger.info('Delete API key {0}'.format(apikey.id))
            history = History(msg='Delete API key {0}'.format(apikey.id), detail=json.dumps({'key': history_apikey_id, 'role': history_apikey_role, 'description': history_apikey_description, 'domains': history_apikey_domains}), created_by=current_user.username)
            history.add()
            return make_response(jsonify({'status': 'ok', 'msg': 'Key has been removed.'}), 200)
@admin_bp.route('/manage-keys', methods=['GET', 'POST'])
@login_required
@operator_role_required
def manage_keys():
    if (request.method == 'GET'):
        try:
            apikeys = ApiKey.query.all()
        except Exception as e:
            current_app.logger.error('Error: {0}'.format(e))
            abort(500)
        return render_template('admin_manage_keys.html', keys=apikeys)
    elif (request.method == 'POST'):
        jdata = request.json
        if (jdata['action'] == 'delete_key'):
            apikey = ApiKey.query.get(jdata['data'])
            try:
                history_apikey_id = apikey.id
                history_apikey_role = apikey.role.name
                history_apikey_description = apikey.description
                history_apikey_domains = [domain.name for domain in apikey.domains]
                apikey.delete()
            except Exception as e:
                current_app.logger.error('Error: {0}'.format(e))
            current_app.logger.info('Delete API key {0}'.format(apikey.id))
            history = History(msg='Delete API key {0}'.format(apikey.id), detail=json.dumps({'key': history_apikey_id, 'role': history_apikey_role, 'description': history_apikey_description, 'domains': history_apikey_domains}), created_by=current_user.username)
            history.add()
            return make_response(jsonify({'status': 'ok', 'msg': 'Key has been removed.'}), 200)