Skip to content

Commit 3041561

Browse files
authored
chore(user-agent): add runtime info (#86)
1 parent a6194a5 commit 3041561

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/fds/sdk/utils/authentication/confidential.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,16 @@ def _init_auth_server_metadata(self) -> None:
187187
if self._ssl_ca_cert:
188188
verify = self._ssl_ca_cert
189189

190+
headers = {
191+
"User-Agent": CONSTS.USER_AGENT,
192+
**(self._proxy_headers if self._proxy_headers else {}),
193+
}
194+
190195
res = self._requests_session.get(
191196
url=self._config[CONSTS.CONFIG_WELL_KNOWN_URI],
192197
proxies=self._proxy,
193198
verify=verify,
194-
headers=self._proxy_headers,
199+
headers=headers,
195200
)
196201
log.debug("Request from well_known_uri completed with status: %s", res.status_code)
197202
log.debug("Response headers from well_known_uri were %s", res.headers)
@@ -281,6 +286,7 @@ def get_access_token(self) -> str:
281286
headers = {
282287
"Accept": "application/json",
283288
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
289+
"User-Agent": CONSTS.USER_AGENT,
284290
}
285291

286292
if self._proxy_headers:

src/fds/sdk/utils/authentication/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import platform
2+
3+
14
class CONSTS:
25
# confidential client assertion JWT
36
CC_JWT_NOT_BEFORE_SECS = 5
@@ -25,5 +28,7 @@ class CONSTS:
2528
# default values
2629
FACTSET_WELL_KNOWN_URI = "https://auth.factset.com/.well-known/openid-configuration"
2730

31+
USER_AGENT = f"fds-sdk/python/utils/2.0.1 ({platform.system()}; Python {platform.python_version()})"
32+
2833

2934
CONSTS = CONSTS()

tests/fds/sdk/utils/authentication/test_confidential.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import logging
3+
import platform
34
from unittest.mock import ANY, mock_open
45

56
import pytest
@@ -202,7 +203,7 @@ def json(self):
202203
url="https://auth.factset.com/.well-known/openid-configuration",
203204
proxies={"http": "http://my:pass@test.test.test", "https": "http://my:pass@test.test.test"},
204205
verify=False,
205-
headers={},
206+
headers={"User-Agent": f"fds-sdk/python/utils/2.0.1 ({platform.system()}; Python {platform.python_version()})"},
206207
)
207208

208209

@@ -228,7 +229,12 @@ def json(self):
228229

229230
client = ConfidentialClient(config=example_config)
230231

231-
get_mock.assert_called_with(url=auth_test, proxies=None, verify=True, headers=None)
232+
get_mock.assert_called_with(
233+
url=auth_test,
234+
proxies=None,
235+
verify=True,
236+
headers={"User-Agent": f"fds-sdk/python/utils/2.0.1 ({platform.system()}; Python {platform.python_version()})"},
237+
)
232238
assert client
233239

234240
assert "Attempting metadata retrieval from well_known_uri: https://auth.test" in caplog.text
@@ -372,6 +378,7 @@ def test_get_access_token_fetch(client, mocker):
372378
headers={
373379
"Accept": "application/json",
374380
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
381+
"User-Agent": f"fds-sdk/python/utils/2.0.1 ({platform.system()}; Python {platform.python_version()})",
375382
},
376383
)
377384

0 commit comments

Comments
 (0)