Skip to content

Commit

Permalink
Change the default permission
Browse files Browse the repository at this point in the history
  • Loading branch information
kkedziak-splunk committed Dec 11, 2024
1 parent 3519ff7 commit 408bc18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions solnlib/alerts_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ class AlertComparator(Enum):
class AlertsRestClient:
"""REST client for handling alerts."""

ENDPOINT = "/services/saved/searches"
ENDPOINT = "/servicesNS/{owner}/{app}/saved/searches"
headers = [("Content-Type", "application/json")]

def __init__(
self,
session_key: str,
app: str,
owner: str = "nobody",
**context: dict,
):
"""Initializes AlertsRestClient.
Expand All @@ -69,9 +70,14 @@ def __init__(
self.app = app

self._rest_client = rest_client.SplunkRestClient(
self.session_key, app=self.app, **context
self.session_key,
app=self.app,
owner=owner,
**context,
)

self.endpoint = self.ENDPOINT.format(owner=owner, app=app)

def create_search_alert(
self,
name: str,
Expand Down Expand Up @@ -130,15 +136,15 @@ def create_search_alert(

params.update(kwargs)

self._rest_client.post(self.ENDPOINT, body=params, headers=self.headers)
self._rest_client.post(self.endpoint, body=params, headers=self.headers)

def delete_search_alert(self, name: str):
"""Deletes a search alert in Splunk.
Arguments:
name: Name of the alert to delete.
"""
self._rest_client.delete(f"{self.ENDPOINT}/{name}")
self._rest_client.delete(f"{self.endpoint}/{name}")

def get_search_alert(self, name: str):
"""Retrieves a specific search alert from Splunk.
Expand All @@ -150,7 +156,7 @@ def get_search_alert(self, name: str):
A dictionary containing the alert details.
"""
response = (
self._rest_client.get(f"{self.ENDPOINT}/{name}", output_mode="json")
self._rest_client.get(f"{self.endpoint}/{name}", output_mode="json")
.body.read()
.decode("utf-8")
)
Expand All @@ -164,7 +170,7 @@ def get_all_search_alerts(self):
A dictionary containing all search alerts.
"""
response = (
self._rest_client.get(self.ENDPOINT, output_mode="json")
self._rest_client.get(self.endpoint, output_mode="json")
.body.read()
.decode("utf-8")
)
Expand Down Expand Up @@ -248,5 +254,5 @@ def update_search_alert(
params.update(kwargs)

self._rest_client.post(
f"{self.ENDPOINT}/{name}", body=params, headers=self.headers
f"{self.endpoint}/{name}", body=params, headers=self.headers
)
3 changes: 3 additions & 0 deletions tests/integration/test_alerts_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def assert_alert_not_found():
assert alert["name"] == example_name
assert alert["content"]["search"] == search

# Check default permissions
assert alert["acl"]["sharing"] == "app"

# Get all alerts
alerts = get_alert_names_set()
assert alerts - initial_alerts == {example_name}
Expand Down

0 comments on commit 408bc18

Please sign in to comment.