Skip to content

Commit 79e5f7d

Browse files
authored
Merge pull request #170 from splunk/DVPL-11649
ACL properties update feature
2 parents e82b602 + 3d66ed0 commit 79e5f7d

File tree

7 files changed

+265
-49
lines changed

7 files changed

+265
-49
lines changed

client/browser_service.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,6 +3411,47 @@ describe("Service Tests ", function(){
34113411
assert.ok(err);
34123412
}
34133413
})
3414+
3415+
it("ACL update", async function() {
3416+
let name = "jssdk_savedsearch_test_acl1";
3417+
let originalSearch = "search * | head 1";
3418+
3419+
let searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection"});
3420+
let search = await searches.create({ search: originalSearch, name: name });
3421+
assert.ok(search);
3422+
let prop = search.acl();
3423+
assert.strictEqual(prop["sharing"], "user");
3424+
assert.strictEqual(prop["perms"], null);
3425+
3426+
search = await search.acl_update({sharing:"app",owner:"admin","perms.read":"admin"});
3427+
let updatedProp = search.acl();
3428+
assert.strictEqual(updatedProp["owner"], "admin");
3429+
assert.strictEqual(updatedProp["sharing"], "app");
3430+
assert.equal(updatedProp["perms"]["read"], "admin");
3431+
await search.remove();
3432+
})
3433+
3434+
it("ACL update fail without sharing", async function() {
3435+
let name = "jssdk_savedsearch_test_acl2";
3436+
let originalSearch = "search * | head 1";
3437+
3438+
let searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection"});
3439+
let search = await searches.create({ search: originalSearch, name: name });
3440+
assert.ok(search);
3441+
assert.throws(()=>{search.acl_update({owner:"admin"})}, "Required argument 'sharing' is missing.")
3442+
await search.remove();
3443+
})
3444+
3445+
it("ACL update fail without owner", async function() {
3446+
let name = "jssdk_savedsearch_test_acl3";
3447+
let originalSearch = "search * | head 1";
3448+
3449+
let searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection"});
3450+
let search = await searches.create({ search: originalSearch, name: name });
3451+
assert.ok(search);
3452+
assert.throws(()=>{search.acl_update({sharing:"app"})}, "Required argument 'owner' is missing.");
3453+
await search.remove();
3454+
})
34143455
});
34153456

34163457
describe("Fired alerts tests", () => {

client/splunk.js

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,19 +2796,20 @@ var __exportName = 'splunkjs';
27962796
this._super(service, path, namespace);
27972797

27982798
// We perform the bindings so that every function works properly
2799-
this._load = utils.bind(this, this._load);
2800-
this.fetch = utils.bind(this, this.fetch);
2801-
this.remove = utils.bind(this, this.remove);
2802-
this.update = utils.bind(this, this.update);
2803-
this.fields = utils.bind(this, this.fields);
2804-
this.links = utils.bind(this, this.links);
2805-
this.acl = utils.bind(this, this.acl);
2806-
this.author = utils.bind(this, this.author);
2807-
this.updated = utils.bind(this, this.updated);
2808-
this.published = utils.bind(this, this.published);
2809-
this.enable = utils.bind(this, this.enable);
2810-
this.disable = utils.bind(this, this.disable);
2811-
this.reload = utils.bind(this, this.reload);
2799+
this._load = utils.bind(this, this._load);
2800+
this.fetch = utils.bind(this, this.fetch);
2801+
this.remove = utils.bind(this, this.remove);
2802+
this.update = utils.bind(this, this.update);
2803+
this.fields = utils.bind(this, this.fields);
2804+
this.links = utils.bind(this, this.links);
2805+
this.acl = utils.bind(this, this.acl);
2806+
this.acl_update = utils.bind(this, this.acl_update);
2807+
this.author = utils.bind(this, this.author);
2808+
this.updated = utils.bind(this, this.updated);
2809+
this.published = utils.bind(this, this.published);
2810+
this.enable = utils.bind(this, this.enable);
2811+
this.disable = utils.bind(this, this.disable);
2812+
this.reload = utils.bind(this, this.reload);
28122813

28132814
// Initial values
28142815
this._properties = {};
@@ -2873,6 +2874,36 @@ var __exportName = 'splunkjs';
28732874
return this._acl;
28742875
},
28752876

2877+
/**
2878+
* Update the access control list (ACL) information for this entity,
2879+
* which contains the permissions for accessing the entity.
2880+
*
2881+
* @example
2882+
*
2883+
* let savedSearches = svc.savedSearches({ owner: "owner-name", app: "app-name"});
2884+
* let search = await searches.create({ search: "search * | head 1", name: "acl_test" });
2885+
* search = await search.acl_update({sharing:"app",owner:"admin","perms.read":"admin"});
2886+
*
2887+
* @param {Object} options Additional entity-specific arguments (required):
2888+
* - `owner` (_string_): The Splunk username, such as "admin". A value of "nobody" means no specific user (required).
2889+
* - `sharing` (_string_): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required).
2890+
* @param {Number} response_timeout A timeout period for aborting a request in milisecs (0 means no timeout).
2891+
*
2892+
* @method splunkjs.Service.Entity
2893+
*/
2894+
acl_update: function(options, response_timeout) {
2895+
if(!options.hasOwnProperty("sharing")) {
2896+
throw new Error("Required argument 'sharing' is missing.");
2897+
}
2898+
if(!options.hasOwnProperty("owner")) {
2899+
throw new Error("Required argument 'owner' is missing.");
2900+
}
2901+
2902+
return this.post("acl", options, response_timeout).then((res)=>{
2903+
return this.fetch({});
2904+
});
2905+
},
2906+
28762907
/**
28772908
* Retrieves the links information for this entity, which is the URI of
28782909
* the entity relative to the management port of a Splunk instance.
@@ -28960,7 +28991,7 @@ module.exports={
2896028991
"_args": [
2896128992
[
2896228993
"elliptic@6.5.4",
28963-
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
28994+
"/Users/abhis/Documents/JS/splunk-sdk-javascript"
2896428995
]
2896528996
],
2896628997
"_development": true,
@@ -28986,7 +29017,7 @@ module.exports={
2898629017
],
2898729018
"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
2898829019
"_spec": "6.5.4",
28989-
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
29020+
"_where": "/Users/abhis/Documents/JS/splunk-sdk-javascript",
2899029021
"author": {
2899129022
"name": "Fedor Indutny",
2899229023
"email": "fedor@indutny.com"
@@ -39453,7 +39484,7 @@ module.exports={
3945339484
"_args": [
3945439485
[
3945539486
"needle@3.0.0",
39456-
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
39487+
"/Users/abhis/Documents/JS/splunk-sdk-javascript"
3945739488
]
3945839489
],
3945939490
"_from": "needle@3.0.0",
@@ -39479,7 +39510,7 @@ module.exports={
3947939510
],
3948039511
"_resolved": "https://registry.npmjs.org/needle/-/needle-3.0.0.tgz",
3948139512
"_spec": "3.0.0",
39482-
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
39513+
"_where": "/Users/abhis/Documents/JS/splunk-sdk-javascript",
3948339514
"author": {
3948439515
"name": "Tomás Pollak",
3948539516
"email": "tomas@forkhq.com"

client/splunk.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/splunk.test.js

Lines changed: 89 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,19 +3486,20 @@ window.SplunkTest = {
34863486
this._super(service, path, namespace);
34873487

34883488
// We perform the bindings so that every function works properly
3489-
this._load = utils.bind(this, this._load);
3490-
this.fetch = utils.bind(this, this.fetch);
3491-
this.remove = utils.bind(this, this.remove);
3492-
this.update = utils.bind(this, this.update);
3493-
this.fields = utils.bind(this, this.fields);
3494-
this.links = utils.bind(this, this.links);
3495-
this.acl = utils.bind(this, this.acl);
3496-
this.author = utils.bind(this, this.author);
3497-
this.updated = utils.bind(this, this.updated);
3498-
this.published = utils.bind(this, this.published);
3499-
this.enable = utils.bind(this, this.enable);
3500-
this.disable = utils.bind(this, this.disable);
3501-
this.reload = utils.bind(this, this.reload);
3489+
this._load = utils.bind(this, this._load);
3490+
this.fetch = utils.bind(this, this.fetch);
3491+
this.remove = utils.bind(this, this.remove);
3492+
this.update = utils.bind(this, this.update);
3493+
this.fields = utils.bind(this, this.fields);
3494+
this.links = utils.bind(this, this.links);
3495+
this.acl = utils.bind(this, this.acl);
3496+
this.acl_update = utils.bind(this, this.acl_update);
3497+
this.author = utils.bind(this, this.author);
3498+
this.updated = utils.bind(this, this.updated);
3499+
this.published = utils.bind(this, this.published);
3500+
this.enable = utils.bind(this, this.enable);
3501+
this.disable = utils.bind(this, this.disable);
3502+
this.reload = utils.bind(this, this.reload);
35023503

35033504
// Initial values
35043505
this._properties = {};
@@ -3563,6 +3564,36 @@ window.SplunkTest = {
35633564
return this._acl;
35643565
},
35653566

3567+
/**
3568+
* Update the access control list (ACL) information for this entity,
3569+
* which contains the permissions for accessing the entity.
3570+
*
3571+
* @example
3572+
*
3573+
* let savedSearches = svc.savedSearches({ owner: "owner-name", app: "app-name"});
3574+
* let search = await searches.create({ search: "search * | head 1", name: "acl_test" });
3575+
* search = await search.acl_update({sharing:"app",owner:"admin","perms.read":"admin"});
3576+
*
3577+
* @param {Object} options Additional entity-specific arguments (required):
3578+
* - `owner` (_string_): The Splunk username, such as "admin". A value of "nobody" means no specific user (required).
3579+
* - `sharing` (_string_): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required).
3580+
* @param {Number} response_timeout A timeout period for aborting a request in milisecs (0 means no timeout).
3581+
*
3582+
* @method splunkjs.Service.Entity
3583+
*/
3584+
acl_update: function(options, response_timeout) {
3585+
if(!options.hasOwnProperty("sharing")) {
3586+
throw new Error("Required argument 'sharing' is missing.");
3587+
}
3588+
if(!options.hasOwnProperty("owner")) {
3589+
throw new Error("Required argument 'owner' is missing.");
3590+
}
3591+
3592+
return this.post("acl", options, response_timeout).then((res)=>{
3593+
return this.fetch({});
3594+
});
3595+
},
3596+
35663597
/**
35673598
* Retrieves the links information for this entity, which is the URI of
35683599
* the entity relative to the management port of a Splunk instance.
@@ -39524,7 +39555,7 @@ module.exports={
3952439555
"_args": [
3952539556
[
3952639557
"elliptic@6.5.4",
39527-
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
39558+
"/Users/abhis/Documents/JS/splunk-sdk-javascript"
3952839559
]
3952939560
],
3953039561
"_development": true,
@@ -39550,7 +39581,7 @@ module.exports={
3955039581
],
3955139582
"_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz",
3955239583
"_spec": "6.5.4",
39553-
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
39584+
"_where": "/Users/abhis/Documents/JS/splunk-sdk-javascript",
3955439585
"author": {
3955539586
"name": "Fedor Indutny",
3955639587
"email": "fedor@indutny.com"
@@ -50919,7 +50950,7 @@ module.exports={
5091950950
"_args": [
5092050951
[
5092150952
"needle@3.0.0",
50922-
"/Users/abhis/Documents/GitHub/splunk-sdk-javascript"
50953+
"/Users/abhis/Documents/JS/splunk-sdk-javascript"
5092350954
]
5092450955
],
5092550956
"_from": "needle@3.0.0",
@@ -50945,7 +50976,7 @@ module.exports={
5094550976
],
5094650977
"_resolved": "https://registry.npmjs.org/needle/-/needle-3.0.0.tgz",
5094750978
"_spec": "3.0.0",
50948-
"_where": "/Users/abhis/Documents/GitHub/splunk-sdk-javascript",
50979+
"_where": "/Users/abhis/Documents/JS/splunk-sdk-javascript",
5094950980
"author": {
5095050981
"name": "Tomás Pollak",
5095150982
"email": "tomas@forkhq.com"
@@ -72622,6 +72653,47 @@ exports.setup = function (svc, loggedOutSvc) {
7262272653
assert.ok(err);
7262372654
}
7262472655
})
72656+
72657+
it("ACL update", async function() {
72658+
let name = "jssdk_savedsearch_test_acl1";
72659+
let originalSearch = "search * | head 1";
72660+
72661+
let searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection"});
72662+
let search = await searches.create({ search: originalSearch, name: name });
72663+
assert.ok(search);
72664+
let prop = search.acl();
72665+
assert.strictEqual(prop["sharing"], "user");
72666+
assert.strictEqual(prop["perms"], null);
72667+
72668+
search = await search.acl_update({sharing:"app",owner:"admin","perms.read":"admin"});
72669+
let updatedProp = search.acl();
72670+
assert.strictEqual(updatedProp["owner"], "admin");
72671+
assert.strictEqual(updatedProp["sharing"], "app");
72672+
assert.equal(updatedProp["perms"]["read"], "admin");
72673+
await search.remove();
72674+
})
72675+
72676+
it("ACL update fail without sharing", async function() {
72677+
let name = "jssdk_savedsearch_test_acl2";
72678+
let originalSearch = "search * | head 1";
72679+
72680+
let searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection"});
72681+
let search = await searches.create({ search: originalSearch, name: name });
72682+
assert.ok(search);
72683+
assert.throws(()=>{search.acl_update({owner:"admin"})}, "Required argument 'sharing' is missing.")
72684+
await search.remove();
72685+
})
72686+
72687+
it("ACL update fail without owner", async function() {
72688+
let name = "jssdk_savedsearch_test_acl3";
72689+
let originalSearch = "search * | head 1";
72690+
72691+
let searches = this.service.savedSearches({ owner: this.service.username, app: "sdkappcollection"});
72692+
let search = await searches.create({ search: originalSearch, name: name });
72693+
assert.ok(search);
72694+
assert.throws(()=>{search.acl_update({sharing:"app"})}, "Required argument 'owner' is missing.");
72695+
await search.remove();
72696+
})
7262572697
})
7262672698
);
7262772699
};

client/splunk.test.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/service.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -964,19 +964,20 @@
964964
this._super(service, path, namespace);
965965

966966
// We perform the bindings so that every function works properly
967-
this._load = utils.bind(this, this._load);
968-
this.fetch = utils.bind(this, this.fetch);
969-
this.remove = utils.bind(this, this.remove);
970-
this.update = utils.bind(this, this.update);
971-
this.fields = utils.bind(this, this.fields);
972-
this.links = utils.bind(this, this.links);
973-
this.acl = utils.bind(this, this.acl);
974-
this.author = utils.bind(this, this.author);
975-
this.updated = utils.bind(this, this.updated);
976-
this.published = utils.bind(this, this.published);
977-
this.enable = utils.bind(this, this.enable);
978-
this.disable = utils.bind(this, this.disable);
979-
this.reload = utils.bind(this, this.reload);
967+
this._load = utils.bind(this, this._load);
968+
this.fetch = utils.bind(this, this.fetch);
969+
this.remove = utils.bind(this, this.remove);
970+
this.update = utils.bind(this, this.update);
971+
this.fields = utils.bind(this, this.fields);
972+
this.links = utils.bind(this, this.links);
973+
this.acl = utils.bind(this, this.acl);
974+
this.acl_update = utils.bind(this, this.acl_update);
975+
this.author = utils.bind(this, this.author);
976+
this.updated = utils.bind(this, this.updated);
977+
this.published = utils.bind(this, this.published);
978+
this.enable = utils.bind(this, this.enable);
979+
this.disable = utils.bind(this, this.disable);
980+
this.reload = utils.bind(this, this.reload);
980981

981982
// Initial values
982983
this._properties = {};
@@ -1041,6 +1042,36 @@
10411042
return this._acl;
10421043
},
10431044

1045+
/**
1046+
* Update the access control list (ACL) information for this entity,
1047+
* which contains the permissions for accessing the entity.
1048+
*
1049+
* @example
1050+
*
1051+
* let savedSearches = svc.savedSearches({ owner: "owner-name", app: "app-name"});
1052+
* let search = await searches.create({ search: "search * | head 1", name: "acl_test" });
1053+
* search = await search.acl_update({sharing:"app",owner:"admin","perms.read":"admin"});
1054+
*
1055+
* @param {Object} options Additional entity-specific arguments (required):
1056+
* - `owner` (_string_): The Splunk username, such as "admin". A value of "nobody" means no specific user (required).
1057+
* - `sharing` (_string_): A mode that indicates how the resource is shared. The sharing mode can be "user", "app", "global", or "system" (required).
1058+
* @param {Number} response_timeout A timeout period for aborting a request in milisecs (0 means no timeout).
1059+
*
1060+
* @method splunkjs.Service.Entity
1061+
*/
1062+
acl_update: function(options, response_timeout) {
1063+
if(!options.hasOwnProperty("sharing")) {
1064+
throw new Error("Required argument 'sharing' is missing.");
1065+
}
1066+
if(!options.hasOwnProperty("owner")) {
1067+
throw new Error("Required argument 'owner' is missing.");
1068+
}
1069+
1070+
return this.post("acl", options, response_timeout).then((res)=>{
1071+
return this.fetch({});
1072+
});
1073+
},
1074+
10441075
/**
10451076
* Retrieves the links information for this entity, which is the URI of
10461077
* the entity relative to the management port of a Splunk instance.

0 commit comments

Comments
 (0)