Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, splunkd_uri, session_key, schema):
"""
Global Config.
:param splunkd_uri:
:param session_key:
:param schema:
:type schema: GlobalConfigSchema
"""
self._splunkd_uri = splunkd_uri
self._session_key = session_key
self._schema = schema
splunkd_info = urlparse(self._splunkd_uri)
self._client = SplunkRestClient(
self._session_key,
self._schema.product,
scheme=splunkd_info.scheme,
host=splunkd_info.hostname,
port=splunkd_info.port,
)
self._configuration = Configuration(self._client, self._schema)
self._inputs = Inputs(self._client, self._schema)
self._configs = Configs(self._client, self._schema)
self._settings = Settings(self._client, self._schema)
:type port: ``integer``
:param context: Other configurations for Splunk rest client.
:type context: ``dict``
:returns: User capabilities.
:rtype: ``list``
:raises UserNotExistException: If `username` does not exist.
Usage::
>>> from solnlib import user_access
>>> user_capabilities = user_access.get_user_capabilities(
>>> session_key, 'test_user')
'''
_rest_client = rest_client.SplunkRestClient(
session_key,
'-',
scheme=scheme,
host=host,
port=port,
**context)
url = '/services/authentication/users/{username}'.format(username=username)
try:
response = _rest_client.get(url, output_mode='json').body.read()
except binding.HTTPError as e:
if e.status != 404:
raise
raise UserNotExistException('User: %s does not exist.' % username)
return json.loads(response)['entry'][0]['content']['capabilities']
:param port: (optional) The port number, default is None.
:type port: ``integer``
:param context: Other configurations for Splunk rest client.
:type context: ``dict``
:returns: User roles.
:rtype: ``list``
:raises UserNotExistException: If `username` does not exist.
Usage::
>>> from solnlib import user_access
>>> user_roles = user_access.get_user_roles(session_key, 'test_user')
'''
_rest_client = rest_client.SplunkRestClient(
session_key,
'-',
scheme=scheme,
host=host,
port=port,
**context)
url = '/services/authentication/users/{username}'.format(username=username)
try:
response = _rest_client.get(url, output_mode='json').body.read()
except binding.HTTPError as e:
if e.status != 404:
raise
raise UserNotExistException('User: %s does not exist.' % username)
return json.loads(response)['entry'][0]['content']['roles']
def _get_collection_data(self, collection_name, session_key, app, owner,
scheme, host, port, **context):
if not context.get('pool_connections'):
context['pool_connections'] = 5
if not context.get('pool_maxsize'):
context['pool_maxsize'] = 5
kvstore = rest_client.SplunkRestClient(session_key,
app,
owner=owner,
scheme=scheme,
host=host,
port=port,
**context).kvstore
collection_name = re.sub(r'[^\w]+', '_', collection_name)
try:
kvstore.get(name=collection_name)
except binding.HTTPError as e:
if e.status != 404:
raise
fields = {'state': 'string'}
kvstore.create(collection_name, fields=fields)