Skip to content

Commit affb72e

Browse files
Merge pull request splunk#490 from splunk/DVPL-11647
Added ACL properties update feature
2 parents 7585d0f + de0d56d commit affb72e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

splunklib/client.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,36 @@ def reload(self):
12161216
self.post("_reload")
12171217
return self
12181218

1219+
def acl_update(self, **kwargs):
1220+
"""To update Access Control List (ACL) properties for an endpoint.
1221+
1222+
:param kwargs: Additional entity-specific arguments (required).
1223+
1224+
- "owner" (``string``): The Splunk username, such as "admin". A value of "nobody" means no specific user (required).
1225+
1226+
- "sharing" (``string``): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required).
1227+
1228+
:type kwargs: ``dict``
1229+
1230+
**Example**::
1231+
1232+
import splunklib.client as client
1233+
service = client.connect(...)
1234+
saved_search = service.saved_searches["name"]
1235+
saved_search.acl_update(sharing="app", owner="nobody", app="search", **{"perms.read": "admin, nobody"})
1236+
"""
1237+
if "body" not in kwargs:
1238+
kwargs = {"body": kwargs}
1239+
1240+
if "sharing" not in kwargs["body"]:
1241+
raise ValueError("Required argument 'sharing' is missing.")
1242+
if "owner" not in kwargs["body"]:
1243+
raise ValueError("Required argument 'owner' is missing.")
1244+
1245+
self.post("acl", **kwargs)
1246+
self.refresh()
1247+
return self
1248+
12191249
@property
12201250
def state(self):
12211251
"""Returns the entity's state record.

tests/test_saved_search.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,30 @@ def test_suppress(self):
223223
self.saved_search.unsuppress()
224224
self.assertEqual(self.saved_search['suppressed'], 0)
225225

226+
def test_acl(self):
227+
self.assertEqual(self.saved_search.access["perms"], None)
228+
self.saved_search.acl_update(sharing="app", owner="admin", app="search", **{"perms.read": "admin, nobody"})
229+
self.assertEqual(self.saved_search.access["owner"], "admin")
230+
self.assertEqual(self.saved_search.access["app"], "search")
231+
self.assertEqual(self.saved_search.access["sharing"], "app")
232+
self.assertEqual(self.saved_search.access["perms"]["read"], ['admin', 'nobody'])
233+
234+
def test_acl_fails_without_sharing(self):
235+
self.assertRaisesRegex(
236+
ValueError,
237+
"Required argument 'sharing' is missing.",
238+
self.saved_search.acl_update,
239+
owner="admin", app="search", **{"perms.read": "admin, nobody"}
240+
)
241+
242+
def test_acl_fails_without_owner(self):
243+
self.assertRaisesRegex(
244+
ValueError,
245+
"Required argument 'owner' is missing.",
246+
self.saved_search.acl_update,
247+
sharing="app", app="search", **{"perms.read": "admin, nobody"}
248+
)
249+
226250
if __name__ == "__main__":
227251
try:
228252
import unittest2 as unittest

0 commit comments

Comments
 (0)