Skip to content

Commit

Permalink
Added delete_watchlist_item method (#682)
Browse files Browse the repository at this point in the history
* Added delete_watchlist_item method

* Black format sentinel_watchlists.py

---------

Co-authored-by: Ian Hellen <[email protected]>
Co-authored-by: Pete Bryan <[email protected]>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent f76650d commit d854d9e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions msticpy/context/azure/sentinel_watchlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,45 @@ def delete_watchlist(
raise CloudError(response=response)
print(f"Watchlist {watchlist_name} deleted")

def delete_watchlist_item(self, watchlist_name: str, watchlist_item_id: str):
"""
Delete a Watchlist item.
Parameters
----------
watchlist_name : str
The name of the watchlist with the item to be deleted
watchlist_item_id : str
The watchlist item ID to delete
Raises
------
MsticpyUserError
If the specified Watchlist does not exist.
CloudError
If the API returns an error.
"""
self.check_connected() # type: ignore
# Check requested watchlist actually exists
if not self._check_watchlist_exists(watchlist_name):
raise MsticpyUserError(f"Watchlist {watchlist_name} does not exist.")

watchlist_url = (
self.sent_urls["watchlists"] # type: ignore
+ f"/{watchlist_name}/watchlistItems/{watchlist_item_id}"
)
response = httpx.delete(
watchlist_url,
headers=get_api_headers(self.token), # type: ignore
params={"api-version": "2023-02-01"},
timeout=get_http_timeout(),
)
if response.status_code != 200:
raise CloudError(response=response)

print(f"Item deleted from {watchlist_name}")

def _check_watchlist_exists(
self,
watchlist_name: str,
Expand Down

0 comments on commit d854d9e

Please sign in to comment.