Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit851d23b

Browse files
authored
[ES-1372353] make user_agent_header part of public API (#530)
* make user_agent_header part of public API* removed user_agent_entry from list of internal params* add backward compatibility
1 parent0013ba4 commit851d23b

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

‎examples/set_user_agent.py‎

Lines changed: 1 addition & 1 deletion
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
)asconnection:
1010

1111
withconnection.cursor()ascursor:

‎src/databricks/sql/client.py‎

Lines changed: 16 additions & 6 deletions
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+
A custom tag to append to the User-Agent header. This is typically used by partners to identify their applications.. 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,8 +179,6 @@ def read(self) -> Optional[OAuthToken]:
176179
"""
177180

178181
# Internal arguments in **kwargs:
179-
# _user_agent_entry
180-
# Tag to add to User-Agent header. For use by partners.
181182
# _use_cert_as_auth
182183
# Use a TLS cert instead of a token
183184
# _enable_ssl
@@ -227,12 +228,21 @@ def read(self) -> Optional[OAuthToken]:
227228
server_hostname,**kwargs
228229
)
229230

230-
ifnotkwargs.get("_user_agent_entry"):
231-
useragent_header="{}/{}".format(USER_AGENT_NAME,__version__)
232-
else:
231+
user_agent_entry=kwargs.get("user_agent_entry")
232+
ifuser_agent_entryisNone:
233+
user_agent_entry=kwargs.get("_user_agent_entry")
234+
ifuser_agent_entryisnotNone:
235+
logger.warning(
236+
"[WARN] Parameter '_user_agent_entry' is deprecated; use 'user_agent_entry' instead. "
237+
"This parameter will be removed in the upcoming releases."
238+
)
239+
240+
ifuser_agent_entry:
233241
useragent_header="{}/{} ({})".format(
234-
USER_AGENT_NAME,__version__,kwargs.get("_user_agent_entry")
242+
USER_AGENT_NAME,__version__,user_agent_entry
235243
)
244+
else:
245+
useragent_header="{}/{}".format(USER_AGENT_NAME,__version__)
236246

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

‎src/databricks/sql/thrift_backend.py‎

Lines changed: 0 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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)

[8]ページ先頭

©2009-2025 Movatter.jp