Skip to content

feat: allow user-specified default OkHttpClient instance - #174

Merged
padamstx merged 1 commit into
mainfrom
set-client
Apr 4, 2022
Merged

feat: allow user-specified default OkHttpClient instance#174
padamstx merged 1 commit into
mainfrom
set-client

Conversation

@padamstx

@padamstx padamstx commented Apr 1, 2022

Copy link
Copy Markdown
Contributor

This commit modifies the java core so that users can now
specify a fully-configured OkHttpClient instance to be
used by service and authenticator instances:

  1. The HttpClientSingleton class now has methods setHttpClient()
    and getHttpClient(). These methods can be used to set and get
    the default client configuration from which other OkHttpClient
    instances are created.
  2. The TokenRequestBasedAuthenticator base class now has methods
    setClient() and getClient(). These methods can be used to set
    and get the specific OkHttpClient instance that should be used
    by an authenticator when interacting with the token service.
    These new methods are inherited by each of the request-based
    authenticator implementation classes: ContainerAuthenticator,
    CloudPakForDataAuthenticator, CloudPakForDataServiceAuthenticator,
    CloudPakForDataServiceInstanceAuthenticator, IamAuthenticator, and
    VpcInstanceAuthenticator.

Note: I plan to update this PR slightly so that the HttpClientSingleton will create a default OkHttpClient instance that supports mutual TLS (if possible). First, I need to learn what those details are :) The PR can be reviewed in its current state as these follow-on changes should be fairly small and isolated to the HttpClientSingleton class.
Upon further review, I'm going to go ahead with this PR as-is. If additional research into the mTLS topic reveals a path where I can configure the default OkHttpClient instance such that mTLS works out of the box without affecting existing use-cases, then I will follow-up with a new PR to make those changes.

@padamstx
padamstx requested review from dpopp07 and pyrooka April 1, 2022 19:22
@padamstx

padamstx commented Apr 1, 2022

Copy link
Copy Markdown
Contributor Author

@ricellis just wanted to alert you to this PR in case you have any comments or concerns. Also, if you have any ideas about how an OkHttpClient instance needs to be configured to support mutual TLS authentication between the client and server, let me know.

@padamstx padamstx self-assigned this Apr 1, 2022

@pyrooka pyrooka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread src/main/java/com/ibm/cloud/sdk/core/security/TokenRequestBasedAuthenticator.java Outdated
This commit modifies the java core so that users can now
specify a fully-configured OkHttpClient instance to be
used by service and authenticator instances:
1. The HttpClientSingleton class now has methods setHttpClient()
   and getHttpClient().  These methods can be used to set and get
   the default client configuration from which other OkHttpClient
   instances are created.
2. The TokenRequestBasedAuthenticator base class now has methods
   setClient() and getClient().  These methods can be used to set
   and get the specific OkHttpClient instance that should be used
   by an authenticator when interacting with the token service.
   These new methods are inherited by each of the request-based
   authenticator implementation classes: ContainerAuthenticator,
   CloudPakForDataAuthenticator, CloudPakForDataServiceAuthenticator,
   CloudPakForDataServiceInstanceAuthenticator, IamAuthenticator, and
   VpcInstanceAuthenticator.

@dpopp07 dpopp07 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! 👍

@padamstx
padamstx marked this pull request as ready for review April 4, 2022 17:08
@padamstx
padamstx merged commit 0205641 into main Apr 4, 2022
@padamstx
padamstx deleted the set-client branch April 4, 2022 17:09
ibm-devx-sdk pushed a commit that referenced this pull request Apr 4, 2022
# [9.17.0](9.16.1...9.17.0) (2022-04-04)

### Features

* allow user-specified default OkHttpClient instance ([#174](#174)) ([0205641](0205641))
@ibm-devx-sdk

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 9.17.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants