Skip to content

Commit 70c23a2

Browse files
feat: improve information in the user-agent param (#427)
**Issue number:** [ADDON-76041](https://splunk.atlassian.net/browse/ADDON-76041) ### PR Type **What kind of change does this PR introduce?** * [ ] Feature * [ ] Bug Fix * [x] Refactoring (no functional or API changes) * [ ] Documentation Update * [ ] Maintenance (dependency updates, CI, etc.) ## Summary ### Changes Changed "User-Agent" header parameter from `Curl` to `solnlib/<version> rest-client <os platform>` ### User experience The user will see more detailed "User-Agent" information in the logs regarding requests made using the rest client. ## Checklist If an item doesn't apply to your changes, leave it unchecked. * [x] I have performed a self-review of this change according to the [development guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines) * [x] Tests have been added/modified to cover the changes [(testing doc)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test) * [ ] Changes are documented * [x] PR title and description follows the [contributing principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests)
1 parent 9de7326 commit 70c23a2

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

solnlib/splunk_rest_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
import logging
2525
import os
26+
import sys
2627
import traceback
28+
import solnlib
29+
2730
from io import BytesIO
2831
from urllib.parse import quote
2932
from urllib3.util.retry import Retry
30-
3133
from splunklib import binding, client
3234

3335
from .net_utils import validate_scheme_host_port
@@ -134,7 +136,7 @@ def request(url, message, **kwargs):
134136

135137
body = message.get("body")
136138
headers = {
137-
"User-Agent": "curl",
139+
"User-Agent": f"solnlib/{solnlib.__version__} rest-client {sys.platform}",
138140
"Accept": "*/*",
139141
"Connection": "Keep-Alive",
140142
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
17+
import context
18+
import pytest
19+
import solnlib
20+
from time import sleep
21+
from splunklib import binding
22+
from solnlib import splunk_rest_client as rest_client
23+
24+
from _search import search
25+
26+
27+
def test_rest_client_user_agent():
28+
test_url = r'search index = _internal uri_path="*/servicesNS/nobody/test_app/some/unexisting/url"'
29+
user_agent = f"solnlib/{solnlib.__version__} rest-client linux"
30+
session_key = context.get_session_key()
31+
wrong_url = r"some/unexisting/url"
32+
rc = rest_client.SplunkRestClient(
33+
session_key,
34+
app="test_app",
35+
owner=context.owner,
36+
scheme=context.scheme,
37+
host=context.host,
38+
port=context.port,
39+
)
40+
with pytest.raises(binding.HTTPError):
41+
rc.get(wrong_url)
42+
43+
for i in range(50):
44+
search_results = search(session_key, test_url)
45+
if len(search_results) > 0:
46+
break
47+
sleep(0.5)
48+
49+
assert user_agent in search_results[0]["_raw"]

0 commit comments

Comments
 (0)