def delete(uuid: str, replica: str):
authenticated_user_email = request.token_info['email']
es_client = ElasticsearchClient.get(logger)
try:
response = es_client.get(index=Config.get_es_index_name(ESIndexType.subscriptions, Replica[replica]),
doc_type=ESDocType.subscription.name,
id=uuid)
except NotFoundError as ex:
raise DSSException(requests.codes.not_found, "not_found", "Cannot find subscription!")
stored_metadata = response['_source']
if stored_metadata['owner'] != authenticated_user_email:
# common_error_handler defaults code to capitalized 'Forbidden' for Werkzeug exception. Keeping consistent.
raise DSSException(requests.codes.forbidden, "Forbidden", "Your credentials can't access this subscription!")
# get all indexes that use current alias
alias_name = Config.get_es_alias_name(ESIndexType.docs, Replica[replica])
doc_indexes = _get_indexes_by_alias(es_client, alias_name)
_unregister_percolate(es_client, doc_indexes, uuid)
es_client.delete(index=Config.get_es_index_name(ESIndexType.subscriptions, Replica[replica]),
doc_type=ESDocType.subscription.name,
id=uuid)
timestamp = datetime.datetime.utcnow()
time_deleted = timestamp.strftime("%Y-%m-%dT%H%M%S.%fZ")
return jsonify({'timeDeleted': time_deleted}), requests.codes.okay
评论列表
文章目录