diff --git a/splunklib/binding.py b/splunklib/binding.py index ff0ae87e3..877c4f161 100644 --- a/splunklib/binding.py +++ b/splunklib/binding.py @@ -234,13 +234,15 @@ def fullpath(self, path, **kwargs): # If no app or owner are specified, then use the /services endpoint if ns.app is None and ns.owner is None: - return "/services/%s" % path + return "/services/%s" % urllib.quote(path) # At least one of app or owner is specified, so use the /serviceNS # endpoint and if only one is specified, then wildcard the other. oname = "-" if ns.owner is None else ns.owner aname = "-" if ns.app is None else ns.app - return "/servicesNS/%s/%s/%s" % (oname, aname, path) + return "/servicesNS/%s/%s/%s" % (urllib.quote(oname), + urllib.quote(aname), + urllib.quote(path)) # Convert the given path into a fully qualified URL by first qualifying # the given path with namespace segments if necessarry and then prefixing diff --git a/splunklib/client.py b/splunklib/client.py index 727480dba..3dc5074eb 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -391,7 +391,18 @@ def state(self): return self._state def update(self, **kwargs): - """Updates the entity with the arguments you provide.""" + """Updates the entity with the arguments you provide. + + Note that you cannot update the ``name`` field of an Entity, + due to a peculiarity of the REST API. + """ + # The peculiarity in question: the REST API creates a new + # Entity if we pass name in the dictionary, instead of the + # expected behavior of updating this Entity. Therefore we + # check for 'name' in kwargs and throw an error if it is + # there. + if 'name' in kwargs: + raise ValueError("Cannot update the name of an Entity via the REST API.") self.post(**kwargs) return self diff --git a/tests/test_saved_search.py b/tests/test_saved_search.py index 58193db2b..a30917419 100755 --- a/tests/test_saved_search.py +++ b/tests/test_saved_search.py @@ -88,6 +88,8 @@ def test_crud(self): saved_search.refresh() self.check_content(saved_search, is_visible=0) + self.assertRaises(ValueError, saved_search.update, saved_search, name="Anything") + saved_searches.delete('sdk-test1') self.assertFalse('sdk-test1' in saved_searches)