|
5 | 5 | from typing import Optional |
6 | 6 |
|
7 | 7 | from pyatlan.client.common import AsyncApiCaller |
8 | | -from pyatlan.client.constants import CONTRACT_INIT_API |
| 8 | +from pyatlan.client.constants import CONTRACT_INIT_API, DELETE_ENTITIES_BY_GUIDS |
9 | 9 | from pyatlan.errors import ErrorCode |
| 10 | +from pyatlan_v9.client.asset import _parse_mutation_response |
10 | 11 | from pyatlan_v9.model.assets import Asset |
11 | 12 | from pyatlan_v9.model.contract import InitRequest |
| 13 | +from pyatlan_v9.model.enums import AtlanDeleteType |
| 14 | +from pyatlan_v9.model.response import AssetMutationResponse |
12 | 15 | from pyatlan_v9.validate import validate_arguments |
13 | 16 |
|
| 17 | +CONTRACT_DELETE_SCOPE_HEADER = "x-atlan-contract-delete-scope" |
| 18 | + |
14 | 19 |
|
15 | 20 | class V9AsyncContractClient: |
16 | 21 | """ |
@@ -48,3 +53,47 @@ async def generate_initial_spec( |
48 | 53 | CONTRACT_INIT_API, request_obj=request_obj |
49 | 54 | ) |
50 | 55 | return response.get("contract") |
| 56 | + |
| 57 | + @validate_arguments |
| 58 | + async def delete(self, guid: str) -> AssetMutationResponse: |
| 59 | + """ |
| 60 | + Hard-delete (purge) a data contract and all its versions (async version). |
| 61 | + This deletes every version of the contract associated with the same asset |
| 62 | + and cleans up the asset's contract attributes (hasContract, dataContractLatest, |
| 63 | + dataContractLatestCertified). |
| 64 | +
|
| 65 | + :param guid: unique identifier (GUID) of any version of the contract to delete |
| 66 | + :returns: details of the deleted contract version(s) |
| 67 | + :raises AtlanError: on any API communication issue |
| 68 | +
|
| 69 | + .. warning:: |
| 70 | + This is an irreversible operation. All versions of the contract will be permanently removed. |
| 71 | + """ |
| 72 | + query_params = {"deleteType": AtlanDeleteType.PURGE.value, "guid": [guid]} |
| 73 | + raw_json = await self._client._call_api( |
| 74 | + DELETE_ENTITIES_BY_GUIDS, query_params=query_params |
| 75 | + ) |
| 76 | + return _parse_mutation_response(raw_json) |
| 77 | + |
| 78 | + @validate_arguments |
| 79 | + async def delete_latest_version(self, guid: str) -> AssetMutationResponse: |
| 80 | + """ |
| 81 | + Hard-delete (purge) only the latest version of a data contract (async version). |
| 82 | + The previous version (if any) becomes the new latest, and the asset's |
| 83 | + contract pointers are updated accordingly. |
| 84 | +
|
| 85 | + :param guid: unique identifier (GUID) of the latest contract version to delete |
| 86 | + :returns: details of the deleted contract version |
| 87 | + :raises AtlanError: on any API communication issue |
| 88 | + :raises ApiError: if the specified GUID is not the latest version |
| 89 | +
|
| 90 | + .. warning:: |
| 91 | + This is an irreversible operation. Only the latest version will be removed. |
| 92 | + """ |
| 93 | + query_params = {"deleteType": AtlanDeleteType.PURGE.value, "guid": [guid]} |
| 94 | + raw_json = await self._client._call_api( |
| 95 | + DELETE_ENTITIES_BY_GUIDS, |
| 96 | + query_params=query_params, |
| 97 | + extra_headers={CONTRACT_DELETE_SCOPE_HEADER: "single"}, |
| 98 | + ) |
| 99 | + return _parse_mutation_response(raw_json) |
0 commit comments