From 465a56b33cdf4a642396f62529235e0295926aa6 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 1 Nov 2021 10:58:54 +0530 Subject: [PATCH 1/6] Update client.py default value for owner set to "nobody" --- splunklib/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/splunklib/client.py b/splunklib/client.py index a9ae396a4..8c695ea63 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -756,6 +756,8 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query): # self.path to the Endpoint is relative in the SDK, so passing # owner, app, sharing, etc. along will produce the correct # namespace in the final request. + if owner is None: + owner = "nobody" if path_segment.startswith('/'): path = path_segment else: From 8dea5eb3971fd168ea318e843c9ec7ee7b45b6dc Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 1 Nov 2021 14:41:32 +0530 Subject: [PATCH 2/6] Update client.py --- splunklib/client.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/splunklib/client.py b/splunklib/client.py index 8c695ea63..87e9ed7c8 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -403,6 +403,7 @@ class Service(_BaseService): def __init__(self, **kwargs): super(Service, self).__init__(**kwargs) self._splunk_version = None + self._kvstore_owner = None @property def apps(self): @@ -675,12 +676,27 @@ def splunk_version(self): self._splunk_version = tuple([int(p) for p in self.info['version'].split('.')]) return self._splunk_version + @property + def kvstore_owner(self): + if self._kvstore_owner is None: + self._kvstore_owner = "nobody" + #self.namespace['owner'] = "nobody" + return self._kvstore_owner + + @kvstore_owner.setter + def kvstore_owner(self, value): + self._kvstore_owner = value + #self.namespace['owner'] = value + @property def kvstore(self): """Returns the collection of KV Store collections. :return: A :class:`KVStoreCollections` collection of :class:`KVStoreCollection` entities. """ + self.namespace['owner'] = self.kvstore_owner + # if self.namespace['owner'] is None: + # self.namespace['owner'] = "nobody" return KVStoreCollections(self) @property @@ -756,8 +772,6 @@ def get(self, path_segment="", owner=None, app=None, sharing=None, **query): # self.path to the Endpoint is relative in the SDK, so passing # owner, app, sharing, etc. along will produce the correct # namespace in the final request. - if owner is None: - owner = "nobody" if path_segment.startswith('/'): path = path_segment else: From d6fc1a3ca6bfee513e1d7cfa8d937c162d2a0352 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 8 Nov 2021 14:34:58 +0530 Subject: [PATCH 3/6] adding kvstore_owner as new property commenting the need to set kvstore owner to default value of "nobody" as new property is created for the kvstore owner with default to "nobody" --- splunklib/client.py | 11 +++++++---- tests/test_kvstore_batch.py | 2 +- tests/test_kvstore_conf.py | 6 +++--- tests/test_kvstore_data.py | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/splunklib/client.py b/splunklib/client.py index 87e9ed7c8..5c48f0510 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -678,25 +678,28 @@ def splunk_version(self): @property def kvstore_owner(self): + """Returns the KVStore owner for this instance of Splunk. + + By default is the kvstore owner is not set, it will return "nobody" + :return: A string with the KVStore owner. + """ if self._kvstore_owner is None: self._kvstore_owner = "nobody" - #self.namespace['owner'] = "nobody" return self._kvstore_owner @kvstore_owner.setter def kvstore_owner(self, value): self._kvstore_owner = value - #self.namespace['owner'] = value @property def kvstore(self): """Returns the collection of KV Store collections. + sets the owner for the namespace, before retrieving the KVStore Collection + :return: A :class:`KVStoreCollections` collection of :class:`KVStoreCollection` entities. """ self.namespace['owner'] = self.kvstore_owner - # if self.namespace['owner'] is None: - # self.namespace['owner'] = "nobody" return KVStoreCollections(self) @property diff --git a/tests/test_kvstore_batch.py b/tests/test_kvstore_batch.py index 14806a699..d32b665e6 100755 --- a/tests/test_kvstore_batch.py +++ b/tests/test_kvstore_batch.py @@ -26,7 +26,7 @@ class KVStoreBatchTestCase(testlib.SDKTestCase): def setUp(self): super(KVStoreBatchTestCase, self).setUp() - self.service.namespace['owner'] = 'nobody' + #self.service.namespace['owner'] = 'nobody' self.service.namespace['app'] = 'search' confs = self.service.kvstore if ('test' in confs): diff --git a/tests/test_kvstore_conf.py b/tests/test_kvstore_conf.py index a587712e4..a24537288 100755 --- a/tests/test_kvstore_conf.py +++ b/tests/test_kvstore_conf.py @@ -25,16 +25,16 @@ class KVStoreConfTestCase(testlib.SDKTestCase): def setUp(self): super(KVStoreConfTestCase, self).setUp() - self.service.namespace['owner'] = 'nobody' + #self.service.namespace['owner'] = 'nobody' self.service.namespace['app'] = 'search' self.confs = self.service.kvstore if ('test' in self.confs): self.confs['test'].delete() def test_owner_restriction(self): - self.service.namespace['owner'] = 'admin' + self.service.kvstore_owner = 'admin' self.assertRaises(client.HTTPError, lambda: self.confs.list()) - self.service.namespace['owner'] = 'nobody' + self.service.kvstore_owner = 'nobody' def test_create_delete_collection(self): self.confs.create('test') diff --git a/tests/test_kvstore_data.py b/tests/test_kvstore_data.py index 1551f1c69..6ddeae688 100755 --- a/tests/test_kvstore_data.py +++ b/tests/test_kvstore_data.py @@ -27,7 +27,7 @@ class KVStoreDataTestCase(testlib.SDKTestCase): def setUp(self): super(KVStoreDataTestCase, self).setUp() - self.service.namespace['owner'] = 'nobody' + #self.service.namespace['owner'] = 'nobody' self.service.namespace['app'] = 'search' self.confs = self.service.kvstore if ('test' in self.confs): From f958a9c7b2f069967563befb28577dd32555b423 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 8 Nov 2021 17:13:26 +0530 Subject: [PATCH 4/6] Update test_kvstore_conf.py --- tests/test_kvstore_conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_kvstore_conf.py b/tests/test_kvstore_conf.py index a24537288..f16a8da87 100755 --- a/tests/test_kvstore_conf.py +++ b/tests/test_kvstore_conf.py @@ -33,6 +33,7 @@ def setUp(self): def test_owner_restriction(self): self.service.kvstore_owner = 'admin' + self.confs = self.service.kvstore self.assertRaises(client.HTTPError, lambda: self.confs.list()) self.service.kvstore_owner = 'nobody' From ee65a75db3044f5a1a214af8570f3f05807fa21f Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 8 Nov 2021 18:08:21 +0530 Subject: [PATCH 5/6] reload the kvstore once owner is changed --- splunklib/client.py | 1 + tests/test_kvstore_conf.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/splunklib/client.py b/splunklib/client.py index 5c48f0510..ce1906a96 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -690,6 +690,7 @@ def kvstore_owner(self): @kvstore_owner.setter def kvstore_owner(self, value): self._kvstore_owner = value + self.kvstore @property def kvstore(self): diff --git a/tests/test_kvstore_conf.py b/tests/test_kvstore_conf.py index f16a8da87..a24537288 100755 --- a/tests/test_kvstore_conf.py +++ b/tests/test_kvstore_conf.py @@ -33,7 +33,6 @@ def setUp(self): def test_owner_restriction(self): self.service.kvstore_owner = 'admin' - self.confs = self.service.kvstore self.assertRaises(client.HTTPError, lambda: self.confs.list()) self.service.kvstore_owner = 'nobody' From bc20898e75bf7c962be757cfa813063b4f4e0d30 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 8 Nov 2021 18:24:57 +0530 Subject: [PATCH 6/6] Update client.py --- splunklib/client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/splunklib/client.py b/splunklib/client.py index ce1906a96..21d27a6e0 100644 --- a/splunklib/client.py +++ b/splunklib/client.py @@ -689,6 +689,9 @@ def kvstore_owner(self): @kvstore_owner.setter def kvstore_owner(self, value): + """ + kvstore is refreshed, when the owner value is changed + """ self._kvstore_owner = value self.kvstore