def delete_secrets(secrets, access_token): """Delete a list of secrets. :param secrets: list of secret names to be deleted. :param access_token: access token of the current user. """ try: (response, http_response) = current_rs_api_client.api.delete_secrets( secrets=secrets, access_token=access_token).result() if http_response.status_code == 200: return response else: raise Exception( "Expected status code 200 but replied with " "{status_code}".format(status_code=http_response.status_code)) except HTTPError as e: if e.response.status_code == 404: raise REANASecretDoesNotExist(e.response.json()) else: logging.debug("Secrets could not be deleted: " "\nStatus: {}\nReason: {}\n" "Message: {}".format( e.response.status_code, e.response.reason, e.response.json()["message"], )) raise Exception(e.response.json()["message"]) except Exception as e: raise e
def delete_secrets(self, secrets): """Delete one or more of users secrets. :param secrets: List of secret names to be deleted form the store. :returns: List with the names of the deleted secrets. """ try: k8s_user_secrets = self._get_k8s_user_secrets_store() deleted = [] missing_secrets_list = [] for secret_name in secrets: try: secrets_types = self._load_json_annotation_from_k8s_object( k8s_user_secrets, "secrets_types") del secrets_types[secret_name] self._dump_json_annotation_to_k8s_object( k8s_user_secrets, "secrets_types", secrets_types) del k8s_user_secrets.data[secret_name] deleted.append(secret_name) except KeyError: missing_secrets_list.append(secret_name) if missing_secrets_list: raise REANASecretDoesNotExist( missing_secrets_list=missing_secrets_list) self._update_store(k8s_user_secrets) return deleted except ApiException: log.error( "Something went wrong while deleting secrets from " "Kubernetes secret for user {0}.".format( str(self.user_secret_store_id)), exc_info=True, )