Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ACL properties update feature #490

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions splunklib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions tests/test_saved_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down