Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param port: (optional) The port number, default is None.
:type port: ``integer``
:param context: Other configurations for Splunk rest client.
:type context: ``dict``
:returns: Current user name.
:rtype: ``string``
:raises InvalidSessionKeyException: If `session_key` is invalid.
Usage::
>>> from solnlib import user_access
>>> user_name = user_access.get_current_username(session_key)
'''
_rest_client = rest_client.SplunkRestClient(
session_key,
'-',
scheme=scheme,
host=host,
port=port,
**context)
try:
response = _rest_client.get('/services/authentication/current-context',
output_mode='json').body.read()
except binding.HTTPError as e:
if e.status != 401:
raise
raise InvalidSessionKeyException('Invalid session key.')
return json.loads(response)['entry'][0]['content']['username']
def _get_collection_data(collection_name, session_key, app, owner,
scheme, host, port, **context):
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
kvstore.create(collection_name)
def __init__(self, session_key, app, owner='nobody',
scheme=None, host=None, port=None, **context):
self._rest_client = rest_client.SplunkRestClient(session_key,
app,
owner=owner,
scheme=scheme,
host=host,
port=port,
**context)
:param context: Other configurations for Splunk rest client.
:type context: ``dict``
:raises CredentialException: If username/password are Invalid.
Usage::
>>> credentials.get_session_key('user', 'password')
'''
if any([scheme is None, host is None, port is None]):
scheme, host, port = get_splunkd_access_info()
uri = '{scheme}://{host}:{port}/{endpoint}'.format(
scheme=scheme, host=host, port=port, endpoint='services/auth/login')
_rest_client = rest_client.SplunkRestClient(
None, '-', 'nobody', scheme, host, port, **context)
try:
response = _rest_client.http.post(
uri, username=username, password=password, output_mode='json')
except binding.HTTPError as e:
if e.status != 401:
raise
raise CredentialException('Invalid username/password.')
return json.loads(response.body.read())['sessionKey']
def __init__(self, session_key, scheme=None,
host=None, port=None, **context):
self._rest_client = rest_client.SplunkRestClient(
session_key,
'splunk_httpinput',
scheme=scheme,
host=host,
port=port,
**context)
def __init__(self, session_key,
scheme=None, host=None, port=None, **context):
self._rest_client = rest_client.SplunkRestClient(session_key,
'-',
scheme=scheme,
host=host,
port=port,
**context)
def __init__(self, session_key,
scheme=None, host=None, port=None, **context):
self._rest_client = rest_client.SplunkRestClient(
session_key,
'-',
scheme=scheme,
host=host,
port=port,
**context)
def __init__(self, session_key, app, owner='nobody', realm=None,
scheme=None, host=None, port=None, **context):
self._realm = realm
self._storage_passwords = rest_client.SplunkRestClient(
session_key,
app,
owner=owner,
scheme=scheme,
host=host,
port=port,
**context).storage_passwords
scheme, host, port = get_splunkd_access_info()
if hec_uri and hec_token:
scheme, host, hec_port = utils.extract_http_scheme_host_port(
hec_uri)
else:
hec_port, hec_token = self._get_hec_config(
hec_input_name, session_key, scheme, host, port, **context)
if not context.get('pool_connections'):
context['pool_connections'] = 10
if not context.get('pool_maxsize'):
context['pool_maxsize'] = 10
self._rest_client = rest_client.SplunkRestClient(hec_token,
app='-',
scheme=scheme,
host=host,
port=hec_port,
**context)
def __init__(self, session_key, app, owner='nobody',
scheme=None, host=None, port=None, **context):
self._session_key = session_key
self._app = app
self._owner = owner
self._scheme = scheme
self._host = host
self._port = port
self._context = context
self._rest_client = rest_client.SplunkRestClient(
self._session_key,
self._app,
owner=self._owner,
scheme=self._scheme,
host=self._host,
port=self._port,
**self._context)
self._confs = None