Skip to content

Commit

Permalink
Merge pull request #196 from splunk/acl-update
Browse files Browse the repository at this point in the history
Added ACL properties update feature
  • Loading branch information
ashah-splunk authored Oct 12, 2022
2 parents 06e819f + b97e5c3 commit 9202f91
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
22 changes: 22 additions & 0 deletions splunk/src/main/java/com/splunk/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<String, Object> 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.
*/
Expand Down
32 changes: 32 additions & 0 deletions splunk/src/test/java/com/splunk/SavedSearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9202f91

Please sign in to comment.