Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support object as value in extra_credential #462

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

huw0
Copy link
Member

@huw0 huw0 commented May 7, 2024

Description

I want extra_credential to accept an object as a value. This is helpful because it allows pass through of short lived tokens (JWT or otherwise) that can be refreshed by the client without having to generate a new engine/client object.

Presently this is not possible because parse_quote does a check on the object type.

Therefore it is necessary to call str() on the extra_credential value during serialisation.

Non-technical explanation

Support object as value in extra_credential to support refreshing tokens.

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text:

* Support object as value in `extra_credential` to support refreshing tokens.

@cla-bot cla-bot bot added the cla-signed label May 7, 2024
@huw0 huw0 force-pushed the support-extra-credential-object branch 3 times, most recently from 15dc44c to 47acd94 Compare May 7, 2024 08:25
@huw0
Copy link
Member Author

huw0 commented May 25, 2024

Thanks for approving.

@hovaesco, @hashhar is this good to merge?

port=constants.DEFAULT_TLS_PORT,
client_session=ClientSession(
user="test",
extra_credential=[("foo", TestCredential())]
Copy link
Member

@hashhar hashhar Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get why you made this change, makes it easier to use object as cred values. But how is this different from below? Just want to understand what problem it actually solves.

extra_credential=[("foo"), str(TestCredential())]

i.e. how do other users of this API learn that the object's __str__ implementation is actually meaningful and is what will be transported.

Copy link
Member Author

@huw0 huw0 Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TestCredential() provides a time limited credential (JWT or otherwise) then the object can refresh the underlying credential. This has two benefits:

  1. No need to regenerate TrinoClient object to refresh the credential.
  2. If the time-limited credential expiry is hit, the automatic retry should include the refreshed credential in the next API call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow I missed that your comment was on the test! I've added a second assertion which hopefully is both a more thorough test and shows the difference clearly.

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good, just had a question.

@huw0 huw0 force-pushed the support-extra-credential-object branch 7 times, most recently from c540f50 to a309986 Compare June 12, 2024 17:47
@huw0 huw0 force-pushed the support-extra-credential-object branch from a309986 to 37680dd Compare June 12, 2024 17:52
@huw0
Copy link
Member Author

huw0 commented Jun 12, 2024

I've rebased the branch and improved the unit test.

@huw0
Copy link
Member Author

huw0 commented Jun 18, 2024

@hashhar @hovaesco - is this ok to merge? :)

@hashhar
Copy link
Member

hashhar commented Jun 24, 2024

Sorry for the delay here. Thanks for the contribution.

@hashhar hashhar merged commit 856d8e9 into trinodb:master Jun 24, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants