Skip to content

Commit 593f122

Browse files
author
Sam Stelle
committed
Added a handler for script names. As well as tests.
1 parent 8cca61c commit 593f122

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

splunklib/client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,13 @@ def __getitem__(self, key):
20182018
if isinstance(key, tuple) and len(key) == 2:
20192019
# Fetch a single kind
20202020
key, kind = key
2021+
if kind == "script":
2022+
keylist = key.split('/')
2023+
applist = [app.name for app in self.service.apps]
2024+
for i in range(len(keylist)):
2025+
if keylist[i] == "apps" and keylist[i+1] in applist:
2026+
newkey = [keylist[x] for x in range(i + 2, len(keylist))]
2027+
key = "./" + ('/').join(newkey)
20212028
key = UrlEncoded(key, encode_slash=True)
20222029
try:
20232030
response = self.get(self.kindpath(kind) + "/" + key)
@@ -2037,6 +2044,12 @@ def __getitem__(self, key):
20372044
# Iterate over all the kinds looking for matches.
20382045
kind = None
20392046
candidate = None
2047+
keylist = key.split('/')
2048+
applist = [app.name for app in self.service.apps]
2049+
for i in range(len(keylist)):
2050+
if keylist[i] == "apps" and keylist[i+1] in applist:
2051+
newkey = [keylist[x] for x in range(i + 2, len(keylist))]
2052+
key = "./" + ('/').join(newkey)
20402053
key = UrlEncoded(key, encode_slash=True)
20412054
for kind in self.kinds:
20422055
try:
@@ -2213,7 +2226,7 @@ def itemmeta(self, kind):
22132226
def _get_kind_list(self, subpath=None):
22142227
if subpath is None:
22152228
subpath = []
2216-
2229+
22172230
kinds = []
22182231
response = self.get('/'.join(subpath))
22192232
content = _load_atom_entries(response)

tests/test_collection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ def test_getitem_with_namespace_sample_in_changelog(self):
244244
ns = client.namespace(owner='nobody', app='search')
245245
result = self.service.saved_searches['Top five sourcetypes', ns]
246246

247+
def test_collection_search_get(self):
248+
for search in self.service.saved_searches:
249+
self.assertEqual(self.service.saved_searches[search.name].path, search.path)
250+
self.assertEqual(200, self.service.saved_searches.get(search.name).status)
251+
252+
def test_collection_inputs_getitem(self):
253+
for inp in self.service.inputs:
254+
self.assertTrue(self.service.inputs[inp.name])
255+
256+
257+
247258
if __name__ == "__main__":
248259
try:
249260
import unittest2 as unittest

0 commit comments

Comments
 (0)