Skip to content

Commit b069211

Browse files
committed
breaking change: replace btool with splunk rest
1 parent ae2b3ab commit b069211

File tree

17 files changed

+360
-2283
lines changed

17 files changed

+360
-2283
lines changed

solnlib/_settings.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright 2025 Splunk Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
"""This module provide settings that can be used to disable/switch features."""
17+
18+
use_btool = False

solnlib/credentials.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,19 @@
1616

1717
"""This module contains Splunk credential related interfaces."""
1818

19-
import json
2019
import re
2120
import warnings
2221
from typing import Dict, List
2322

2423
from splunklib import binding, client
2524

2625
from . import splunk_rest_client as rest_client
27-
from .net_utils import validate_scheme_host_port
28-
from .splunkenv import get_splunkd_access_info
2926
from .utils import retry
3027

3128
__all__ = [
3229
"CredentialException",
3330
"CredentialNotExistException",
3431
"CredentialManager",
35-
"get_session_key",
3632
]
3733

3834

@@ -339,56 +335,3 @@ def _get_all_passwords(self) -> List[Dict[str, str]]:
339335
)
340336
passwords = self._storage_passwords.list(count=-1)
341337
return self._get_clear_passwords(passwords)
342-
343-
344-
@retry(exceptions=[binding.HTTPError])
345-
def get_session_key(
346-
username: str,
347-
password: str,
348-
scheme: str = None,
349-
host: str = None,
350-
port: int = None,
351-
**context: dict,
352-
) -> str:
353-
"""Get splunkd access token.
354-
355-
Arguments:
356-
username: The Splunk account username, which is used to authenticate the Splunk instance.
357-
password: The Splunk account password.
358-
scheme: (optional) The access scheme, default is None.
359-
host: (optional) The host name, default is None.
360-
port: (optional) The port number, default is None.
361-
context: Other configurations for Splunk rest client.
362-
363-
Returns:
364-
Splunk session key.
365-
366-
Raises:
367-
CredentialException: If username/password are invalid.
368-
ValueError: if scheme, host or port are invalid.
369-
370-
Examples:
371-
>>> get_session_key('user', 'password')
372-
"""
373-
validate_scheme_host_port(scheme, host, port)
374-
375-
if any([scheme is None, host is None, port is None]):
376-
scheme, host, port = get_splunkd_access_info(use_btool=True)
377-
378-
uri = "{scheme}://{host}:{port}/{endpoint}".format(
379-
scheme=scheme, host=host, port=port, endpoint="services/auth/login"
380-
)
381-
_rest_client = rest_client.SplunkRestClient(
382-
None, "-", "nobody", scheme, host, port, **context
383-
)
384-
try:
385-
response = _rest_client.http.post(
386-
uri, username=username, password=password, output_mode="json"
387-
)
388-
except binding.HTTPError as e:
389-
if e.status != 401:
390-
raise
391-
392-
raise CredentialException("Invalid username/password.")
393-
394-
return json.loads(response.body.read())["sessionKey"]

solnlib/modular_input/event_writer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,13 @@ def __init__(
233233
scheme, host, hec_port = utils.extract_http_scheme_host_port(hec_uri)
234234
else:
235235
if not all([scheme, host, port]):
236-
scheme, host, port = get_splunkd_access_info(
237-
session_key=self._session_key
238-
)
236+
scheme, host, port = get_splunkd_access_info(self._session_key)
239237
hec_port, hec_token = self._get_hec_config(
240238
hec_input_name, session_key, scheme, host, port, **context
241239
)
242240

243241
if global_settings_schema:
244-
scheme = get_scheme_from_hec_settings(session_key=self._session_key)
242+
scheme = get_scheme_from_hec_settings(self._session_key)
245243

246244
if not context.get("pool_connections"):
247245
context["pool_connections"] = 10

solnlib/server_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(
7878
"""
7979
is_localhost = False
8080
if not all([scheme, host, port]) and os.environ.get("SPLUNK_HOME"):
81-
scheme, host, port = get_splunkd_access_info(session_key=session_key)
81+
scheme, host, port = get_splunkd_access_info(session_key)
8282
is_localhost = (
8383
host == "localhost" or host == "127.0.0.1" or host in ("::1", "[::1]")
8484
)

solnlib/splunk_rest_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def __init__(
221221
"""
222222
# Only do splunkd URI discovery in SPLUNK env (SPLUNK_HOME is set).
223223
if not all([scheme, host, port]) and os.environ.get("SPLUNK_HOME"):
224-
scheme, host, port = get_splunkd_access_info(session_key=session_key)
224+
scheme, host, port = get_splunkd_access_info(session_key)
225225
if os.environ.get("SPLUNK_HOME") is None:
226226
if not all([scheme, host, port]):
227227
raise ValueError(

0 commit comments

Comments
 (0)