Skip to content

Commit 5473fd7

Browse files
committed
Change macros endpoint from configs/conf-macros to data/macros
1 parent 6a131b7 commit 5473fd7

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

splunklib/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
PATH_JOBS = "search/jobs/"
109109
PATH_JOBS_V2 = "search/v2/jobs/"
110110
PATH_LOGGER = "/services/server/logger/"
111-
PATH_MACROS = "configs/conf-macros/"
111+
PATH_MACROS = "data/macros/"
112112
PATH_MESSAGES = "messages/"
113113
PATH_MODULAR_INPUTS = "data/modular-inputs"
114114
PATH_ROLES = "authorization/roles/"

tests/integration/test_macro.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# under the License.
1616

1717
from __future__ import absolute_import
18-
from splunklib.binding import HTTPError
18+
from splunklib.binding import HTTPError, namespace
1919
from tests import testlib
2020
import logging
2121

@@ -264,7 +264,7 @@ def query():
264264
self.assertRaisesRegex(HTTPError, "value must be smaller that value2", query)
265265

266266

267-
# This test makes sure that the endpoint we use for macros (configs/conf-macros)
267+
# This test makes sure that the endpoint we use for macros (data/macros/)
268268
# does not require admin privileges and can be used by normal users.
269269
class TestPrivileges(testlib.SDKTestCase):
270270
macro_name = "SDKTestMacro"
@@ -318,6 +318,67 @@ def test_create_macro_no_admin(self):
318318
self.assertEqual(out[0]["test"], "123")
319319

320320

321+
# This test makes sure that the endpoint we use for macros (data/macros/)
322+
# does not require admin privileges and can be used by normal users.
323+
class TestPrivilegesWithNamespace(testlib.SDKTestCase):
324+
macro_name = "SDKTestMacro"
325+
username = "SDKTestMacroUser".lower()
326+
password = "SDKTestMacroUserPassword!"
327+
328+
# TODO: Would be nice to create app on-demand here and control the
329+
# permissions, so that we are not dependent on default settings.
330+
namespace = namespace(owner="nobody", app="launcher")
331+
332+
def setUp(self):
333+
testlib.SDKTestCase.setUp(self)
334+
self.cleanUsers()
335+
336+
self.service.users.create(
337+
username=self.username, password=self.password, roles=["power"]
338+
)
339+
340+
self.service.logout()
341+
kwargs = self.opts.kwargs.copy()
342+
kwargs["username"] = self.username
343+
kwargs["password"] = self.password
344+
self.service = client.connect(**kwargs)
345+
346+
self.cleanMacros()
347+
348+
def tearDown(self):
349+
testlib.SDKTestCase.tearDown(self)
350+
self.cleanMacros()
351+
self.service = client.connect(**self.opts.kwargs)
352+
self.cleanUsers()
353+
354+
def cleanUsers(self):
355+
for user in self.service.users:
356+
if user.name == self.username:
357+
self.service.users.delete(self.username)
358+
359+
def cleanMacros(self):
360+
for macro in self.service.macros:
361+
if macro.name == self.macro_name:
362+
self.service.macros.delete(self.macro_name, namespace=self.namespace)
363+
364+
def test_create_macro_no_admin(self):
365+
self.service.macros.create(
366+
self.macro_name, 'eval test="123"', namespace=self.namespace
367+
)
368+
369+
stream = self.service.jobs.oneshot(
370+
f"| makeresults count=1 | `{self.macro_name}`",
371+
output_mode="json",
372+
namespace=self.namespace,
373+
)
374+
375+
result = results.JSONResultsReader(stream)
376+
out = list(result)
377+
378+
self.assertTrue(len(out) == 1)
379+
self.assertEqual(out[0]["test"], "123")
380+
381+
321382
if __name__ == "__main__":
322383
try:
323384
import unittest2 as unittest

0 commit comments

Comments
 (0)