splunk / splunk-sdk-javascript

Splunk Software Development Kit for JavaScript

Home Page:http://dev.splunk.com/javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

namespace matching in Collection.item function

niyue opened this issue · comments

commented

For Collection.item(id, namespace) function, it has a parameter called namespace used to filter the collection items according to owner/app/sharing information. And '-' can be used as wildcard character for owner and app in namespace according to documentation.

However, I found the real matching implementation made me some surprised.
For example, if I would like to retrieve saved searches collection, and get a saved search called 'my_saved_search' in app 'myapp'. I tried to used the following code snippet:

var savedSearchesColl = splunkService.savedSearches({ owner: '-', app: '-' });
...
var savedSearch = savedSearchesColl.item('my_saved_search', { owner: '-', app: 'myapp' });

I expect the savedSearchesColl.item returning me one saved search because I do have a saved search called 'my_saved_search' in 'myapp' and I don't care who is the owner of this saved search so I use the wildcard '-' as the owner. However, it doesn't return the expected saved search and instead it returns null in this case.

After some investigation, I found this is caused by https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/service.js#L1378-L1388.
During namespace matching, the item function will compare the qualifiedPath of this item with the one constructed from namespace provided, character by character, and because '/servicesNS/-/myapp/saved/searches/my_saved_search' is not equal to '/servicesNS/myuser/myapp/saved/searches/my_saved_search', the namespace matching fails. And it means I have to specify a concrete owner instead of using the owner wildcard to make them matched.

I am not sure if this is a bug, but at least by reading documentation for this function, I expect wildcard to work for me in this case, and it seems counter intuitive for me that a concrete value can match the item while the wildcard does not match the item during namespace matching. Any idea on this? Thanks.

Thanks for the heads up. Turns out this was an error in documentation. Using a custom namespace to find an entity is used when there may be multiple entities with the same ID. Therefore, when using the custom namespace, the wildcard filter wouldn't be much use.

I've made a change that throws an error when using the wildcard for owner or app.