From b97e5c34e7dd7b332a38cb823c23a825cf63591a Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Thu, 6 Oct 2022 15:54:38 +0530 Subject: [PATCH] ACL update feature added ACL Update method along with the corresponding test-cases --- splunk/src/main/java/com/splunk/Entity.java | 22 +++++++++++++ .../test/java/com/splunk/SavedSearchTest.java | 32 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/splunk/src/main/java/com/splunk/Entity.java b/splunk/src/main/java/com/splunk/Entity.java index 831b9852..a4856e2a 100644 --- a/splunk/src/main/java/com/splunk/Entity.java +++ b/splunk/src/main/java/com/splunk/Entity.java @@ -50,6 +50,8 @@ protected String actionPath(String action) { return path + "/enable"; if (action.equals("remove")) return path; + if (action.equals("acl")) + return path + "/acl"; throw new IllegalArgumentException("Invalid action: " + action); } @@ -450,6 +452,26 @@ public void update() { update(Collections.EMPTY_MAP); } + + /** + * Update the access control list (ACL) properties for this entity, + * + * @param args: Properties to update for this entity. + * Required Properties in 'args' + * - `owner`: The Splunk username, such as "admin". A value of "nobody" means no specific user. + * - `sharing`: A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system". + */ + public void aclUpdate(Map args){ + if(!args.containsKey("sharing")){ + throw new IllegalArgumentException("Required argument 'sharing' is missing."); + } + if(!args.containsKey("owner")){ + throw new IllegalArgumentException("Required argument 'owner' is missing."); + } + service.post(actionPath("acl"), args); + invalidate(); + } + /** * Removes this entity from its corresponding collection. */ diff --git a/splunk/src/test/java/com/splunk/SavedSearchTest.java b/splunk/src/test/java/com/splunk/SavedSearchTest.java index dc45caa1..e62a6294 100644 --- a/splunk/src/test/java/com/splunk/SavedSearchTest.java +++ b/splunk/src/test/java/com/splunk/SavedSearchTest.java @@ -360,6 +360,38 @@ public void testCannotUpdateName() { } catch (Exception e) {} } + @Test + public void testACLUpdates(){ + Record aclInfo = savedSearch.getMetadata().getEaiAcl(); + Assert.assertNotEquals(aclInfo.getString("sharing"), "app"); + Assert.assertNotEquals(aclInfo.getString("owner"), "nobody"); + Assert.assertNull(aclInfo.get("perms")); + Args args = new Args(); + args.add("sharing","app"); + args.add("owner","nobody"); + args.add("app","search"); + args.add("perms.read","admin, nobody"); + savedSearch.aclUpdate(args); + aclInfo = savedSearch.getMetadata().getEaiAcl(); + Assert.assertEquals(aclInfo.getString("sharing"), "app"); + Assert.assertEquals(aclInfo.getString("owner"), "nobody"); + Assert.assertNotNull(aclInfo.get("perms")); + } + + @Test + public void testACLUpdateWithoutSharing(){ + Args args = new Args(); + args.add("owner","nobody"); + args.add("app","search"); + Assert.assertThrows("Required argument 'sharing' is missing.", IllegalArgumentException.class, () -> {savedSearch.aclUpdate(args);}); + } + + @Test + public void testACLUpdateWithoutOwner(){ + Args args = new Args(); + Assert.assertThrows("Required argument 'owner' is missing.", IllegalArgumentException.class, () -> {savedSearch.aclUpdate(args);}); + } + @Test public void testDispatch() { final JobCollection jobs = service.getJobs();