Skip to content

Commit 9202f91

Browse files
authored
Merge pull request #196 from splunk/acl-update
Added ACL properties update feature
2 parents 06e819f + b97e5c3 commit 9202f91

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

splunk/src/main/java/com/splunk/Entity.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ protected String actionPath(String action) {
5050
return path + "/enable";
5151
if (action.equals("remove"))
5252
return path;
53+
if (action.equals("acl"))
54+
return path + "/acl";
5355
throw new IllegalArgumentException("Invalid action: " + action);
5456
}
5557

@@ -450,6 +452,26 @@ public void update() {
450452
update(Collections.EMPTY_MAP);
451453
}
452454

455+
456+
/**
457+
* Update the access control list (ACL) properties for this entity,
458+
*
459+
* @param args: Properties to update for this entity.
460+
* Required Properties in 'args'
461+
* - `owner`: The Splunk username, such as "admin". A value of "nobody" means no specific user.
462+
* - `sharing`: A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system".
463+
*/
464+
public void aclUpdate(Map<String, Object> args){
465+
if(!args.containsKey("sharing")){
466+
throw new IllegalArgumentException("Required argument 'sharing' is missing.");
467+
}
468+
if(!args.containsKey("owner")){
469+
throw new IllegalArgumentException("Required argument 'owner' is missing.");
470+
}
471+
service.post(actionPath("acl"), args);
472+
invalidate();
473+
}
474+
453475
/**
454476
* Removes this entity from its corresponding collection.
455477
*/

splunk/src/test/java/com/splunk/SavedSearchTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,38 @@ public void testCannotUpdateName() {
360360
} catch (Exception e) {}
361361
}
362362

363+
@Test
364+
public void testACLUpdates(){
365+
Record aclInfo = savedSearch.getMetadata().getEaiAcl();
366+
Assert.assertNotEquals(aclInfo.getString("sharing"), "app");
367+
Assert.assertNotEquals(aclInfo.getString("owner"), "nobody");
368+
Assert.assertNull(aclInfo.get("perms"));
369+
Args args = new Args();
370+
args.add("sharing","app");
371+
args.add("owner","nobody");
372+
args.add("app","search");
373+
args.add("perms.read","admin, nobody");
374+
savedSearch.aclUpdate(args);
375+
aclInfo = savedSearch.getMetadata().getEaiAcl();
376+
Assert.assertEquals(aclInfo.getString("sharing"), "app");
377+
Assert.assertEquals(aclInfo.getString("owner"), "nobody");
378+
Assert.assertNotNull(aclInfo.get("perms"));
379+
}
380+
381+
@Test
382+
public void testACLUpdateWithoutSharing(){
383+
Args args = new Args();
384+
args.add("owner","nobody");
385+
args.add("app","search");
386+
Assert.assertThrows("Required argument 'sharing' is missing.", IllegalArgumentException.class, () -> {savedSearch.aclUpdate(args);});
387+
}
388+
389+
@Test
390+
public void testACLUpdateWithoutOwner(){
391+
Args args = new Args();
392+
Assert.assertThrows("Required argument 'owner' is missing.", IllegalArgumentException.class, () -> {savedSearch.aclUpdate(args);});
393+
}
394+
363395
@Test
364396
public void testDispatch() {
365397
final JobCollection jobs = service.getJobs();

0 commit comments

Comments
 (0)