owner in KVStoreCollection should default owner to 'nobody'
Attempts to use client for kvstore access fails with user context of 'nobody' error.
import splunklib.client as client
HOST = "localhost"
PORT = "8089"
'''
### BROKEN ###
service = client.connect(
host=HOST,
port=PORT,
username='admin',
password='changeme')
kv_client = service.kvstore
for kv in kv_client:
print(kv)
# HTTPError: HTTP 400 Bad Request -- Must use user context of 'nobody' when interacting with collection configurations (used user='admin')
Manually this can be solved:
### Solution By Modifying Owner ###
service = client.connect(
host=HOST,
port=PORT,
username='admin',
password='changeme')
print(service.namespace)
#{'owner': None, 'app': None, 'sharing': None}
service.namespace['owner'] = 'Nobody' #<- change namespace owner to Nobody
kv_client = service.kvstore
for kv in kv_client:
print(kv)
# <splunklib.client.KVStoreCollection object at 0x...>
# <splunklib.client.KVStoreCollection object at 0x...>
Since all interactions with kvstores must be done with an owner of Nobody, this should be set by default in client.py. I haven't spent much time with this library, but possibly:
class KVStoreCollectionData(object):
"""This class represents the data endpoint for a KVStoreCollection.
Retrieve using :meth:`KVStoreCollection.data`
"""
JSON_HEADER = [('Content-Type', 'application/json')]
def __init__(self, collection):
self.service = collection.service
self.collection = collection
#self.owner, self.app, self.sharing = collection._proper_namespace() # replace this line
self.owner = 'Nobody' # <- add default
self.app, self.sharing = collection._proper_namespace()
Hi @SyraD - thanks for the report! I appreciate all your investigation into this issue. We're tracking this internally and will work on getting a fix out.
Hi,
This has been opened for over a year, any updates?
Thanks
Hi @SyraD , @tr4cefl0w , The change have been made and they will be available in the next SDK release. Refer the change in the test cases. Reference for the code changes :- https://github.com/splunk/splunk-sdk-python/pull/413/files