Skip to content

Commit

Permalink
Support object as value in extra_credential
Browse files Browse the repository at this point in the history
  • Loading branch information
huw0 committed May 7, 2024
1 parent b8ce27d commit aa4fe16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,28 @@ def test_extra_credential_value_encoding(mock_get_and_post):
assert constants.HEADER_EXTRA_CREDENTIAL in headers
assert headers[constants.HEADER_EXTRA_CREDENTIAL] == "foo=bar+%E7%9A%84"

def test_extra_credential_value_object(mock_get_and_post):
_, post = mock_get_and_post

class TestCredential(object):
def __str__(self):
return "bar"

req = TrinoRequest(
host="coordinator",
port=constants.DEFAULT_TLS_PORT,
client_session=ClientSession(
user="test",
extra_credential=[("foo", TestCredential())]
)
)

req.post("SELECT 1")
_, post_kwargs = post.call_args
headers = post_kwargs["headers"]
assert constants.HEADER_EXTRA_CREDENTIAL in headers
assert headers[constants.HEADER_EXTRA_CREDENTIAL] == "foo=bar"


class RetryRecorder(object):
def __init__(self, error=None, result=None):
Expand Down
2 changes: 1 addition & 1 deletion trino/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def http_headers(self) -> Dict[str, str]:
# extra credential value is encoded per spec (application/x-www-form-urlencoded MIME format)
headers[constants.HEADER_EXTRA_CREDENTIAL] = \
", ".join(
[f"{tup[0]}={urllib.parse.quote_plus(tup[1])}" for tup in self._client_session.extra_credential])
[f"{tup[0]}={urllib.parse.quote_plus(str(tup[1]))}" for tup in self._client_session.extra_credential])

return headers

Expand Down

0 comments on commit aa4fe16

Please sign in to comment.