Skip to content

Commit 0eb56f1

Browse files
committed
make user_agent_header part of public API
1 parent 2ab9a5f commit 0eb56f1

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

examples/set_user_agent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),
66
http_path=os.getenv("DATABRICKS_HTTP_PATH"),
77
access_token=os.getenv("DATABRICKS_TOKEN"),
8-
_user_agent_entry="ExamplePartnerTag",
8+
user_agent_entry="ExamplePartnerTag",
99
) as connection:
1010

1111
with connection.cursor() as cursor:

src/databricks/sql/client.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def __init__(
122122
port of the oauth redirect uri (localhost). This is required when custom oauth client_id
123123
`oauth_client_id` is set
124124
125+
user_agent_entry: `str`, optional
126+
Tag to add to User-Agent header. For use by partners. If not specified, it will use the default user agent PyDatabricksSqlConnector
127+
125128
experimental_oauth_persistence: configures preferred storage for persisting oauth tokens.
126129
This has to be a class implementing `OAuthPersistence`.
127130
When `auth_type` is set to `databricks-oauth` or `azure-oauth` without persisting the oauth token in a
@@ -176,7 +179,7 @@ def read(self) -> Optional[OAuthToken]:
176179
"""
177180

178181
# Internal arguments in **kwargs:
179-
# _user_agent_entry
182+
# user_agent_entry
180183
# Tag to add to User-Agent header. For use by partners.
181184
# _use_cert_as_auth
182185
# Use a TLS cert instead of a token
@@ -227,11 +230,11 @@ def read(self) -> Optional[OAuthToken]:
227230
server_hostname, **kwargs
228231
)
229232

230-
if not kwargs.get("_user_agent_entry"):
233+
if not kwargs.get("user_agent_entry"):
231234
useragent_header = "{}/{}".format(USER_AGENT_NAME, __version__)
232235
else:
233236
useragent_header = "{}/{} ({})".format(
234-
USER_AGENT_NAME, __version__, kwargs.get("_user_agent_entry")
237+
USER_AGENT_NAME, __version__, kwargs.get("user_agent_entry")
235238
)
236239

237240
base_headers = [("User-Agent", useragent_header)]

src/databricks/sql/thrift_backend.py

-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def __init__(
9595
**kwargs,
9696
):
9797
# Internal arguments in **kwargs:
98-
# _user_agent_entry
99-
# Tag to add to User-Agent header. For use by partners.
10098
# _username, _password
10199
# Username and password Basic authentication (no official support)
102100
# _connection_uri

tests/unit/test_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_useragent_header(self, mock_client_class):
157157
)
158158
self.assertIn(user_agent_header, http_headers)
159159

160-
databricks.sql.connect(**self.DUMMY_CONNECTION_ARGS, _user_agent_entry="foobar")
160+
databricks.sql.connect(**self.DUMMY_CONNECTION_ARGS, user_agent_entry="foobar")
161161
user_agent_header_with_entry = (
162162
"User-Agent",
163163
"{}/{} ({})".format(

0 commit comments

Comments
 (0)