From b4fc25ff6b136719981f9b553f7ed7d6cc72fbb0 Mon Sep 17 00:00:00 2001 From: Fred Ross Date: Thu, 3 May 2012 12:53:12 -0700 Subject: [PATCH 1/2] =?UTF-8?q?Entity.update(name=3D=E2=80=A6)=20throws=20?= =?UTF-8?q?an=20error.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- splunklib/client.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 From d5dd4b23c3515be5021720090be3a20aa1536cb2 Mon Sep 17 00:00:00 2001 From: Fred Ross Date: Thu, 3 May 2012 12:53:50 -0700 Subject: [PATCH 2/2] Added URL forbidden character encoding for owner, app, etc. --- splunklib/binding.py | 6 ++++-- tests/test_saved_search.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) 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/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)