From a24bad04daa868f0b21ccf117b1b791bc389c734 Mon Sep 17 00:00:00 2001 From: akaila-splunk Date: Thu, 6 Oct 2022 15:35:25 +0530 Subject: [PATCH 1/3] added acl_update method - added acl_update method to update ACL properties of an entity --- splunklib/client.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/splunklib/client.py b/splunklib/client.py index cde39e95c..d595b82c9 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -1216,6 +1216,36 @@ def reload(self): self.post("_reload") return self + def acl_update(self, **kwargs): + """To update Access Control List (ACL) properties for an endpoint. + + :param kwargs: Additional entity-specific arguments (required). + + - "owner" (``string``): The Splunk username, such as "admin". A value of "nobody" means no specific user (required). + + - "sharing" (``string``): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required). + + :type kwargs: ``dict`` + + **Example**:: + + import splunklib.client as client + service = client.connect(...) + saved_search = service.saved_searches["name"] + saved_search.acl_update(sharing="app", owner="nobody", app="search", **{"perms.read": "admin, nobody"}) + """ + if "body" not in kwargs: + kwargs = {"body": {**kwargs}} + + if "sharing" not in kwargs["body"]: + raise ValueError("Required argument 'sharing' is missing.") + if "owner" not in kwargs["body"]: + raise ValueError("Required argument 'owner' is missing.") + + self.post("acl", **kwargs) + self.refresh() + return self + @property def state(self): """Returns the entity's state record. From 03a0b75227c830e15638090157188bf319d30ad2 Mon Sep 17 00:00:00 2001 From: akaila-splunk Date: Thu, 6 Oct 2022 15:35:59 +0530 Subject: [PATCH 2/3] added test cases for acl_update method --- tests/test_saved_search.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_saved_search.py b/tests/test_saved_search.py index c15921c0c..d1f8f57c2 100755 --- a/tests/test_saved_search.py +++ b/tests/test_saved_search.py @@ -223,6 +223,30 @@ def test_suppress(self): self.saved_search.unsuppress() self.assertEqual(self.saved_search['suppressed'], 0) + def test_acl(self): + self.assertEqual(self.saved_search.access["perms"], None) + self.saved_search.acl_update(sharing="app", owner="admin", app="search", **{"perms.read": "admin, nobody"}) + self.assertEqual(self.saved_search.access["owner"], "admin") + self.assertEqual(self.saved_search.access["app"], "search") + self.assertEqual(self.saved_search.access["sharing"], "app") + self.assertEqual(self.saved_search.access["perms"]["read"], ['admin', 'nobody']) + + def test_acl_fails_without_sharing(self): + self.assertRaisesRegex( + ValueError, + "Required argument 'sharing' is missing.", + self.saved_search.acl_update, + owner="admin", app="search", **{"perms.read": "admin, nobody"} + ) + + def test_acl_fails_without_owner(self): + self.assertRaisesRegex( + ValueError, + "Required argument 'owner' is missing.", + self.saved_search.acl_update, + sharing="app", app="search", **{"perms.read": "admin, nobody"} + ) + if __name__ == "__main__": try: import unittest2 as unittest From de0d56d5d8a1899a5f07872c3ca0e4e478b0f8ac Mon Sep 17 00:00:00 2001 From: akaila-splunk Date: Thu, 6 Oct 2022 15:59:25 +0530 Subject: [PATCH 3/3] Update client.py --- splunklib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/splunklib/client.py b/splunklib/client.py index d595b82c9..564a40f66 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -1235,7 +1235,7 @@ def acl_update(self, **kwargs): saved_search.acl_update(sharing="app", owner="nobody", app="search", **{"perms.read": "admin, nobody"}) """ if "body" not in kwargs: - kwargs = {"body": {**kwargs}} + kwargs = {"body": kwargs} if "sharing" not in kwargs["body"]: raise ValueError("Required argument 'sharing' is missing.")