-
Notifications
You must be signed in to change notification settings - Fork 33
Add DatabricksOAuthTokenSource #439
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
Conversation
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
|
|
||
| OAuthResponse response; | ||
| try { | ||
| response = new ObjectMapper().readValue(rawResponse.getBody(), OAuthResponse.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ObjectMapper is created for each token request. Can we define this as a static final field for this class? Is this readvalue() method thread safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, calls to this method are not frequent, and soon will be done async.
Specially if readvalue() is not thread safe, I would not bother.
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
| private String audience; | ||
|
|
||
| /** | ||
| * Validates that a value is non-empty and non-null for required fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is not correct. We don't have a non-empty check for all the objects. It is only for the Strings. So, we can clarify it here.
| if (testCase.expectError) { | ||
| if (testCase.statusCode == 0) { | ||
| when(mockHttpClient.execute(any())).thenThrow(new IOException("Network error")); | ||
| } else { | ||
| when(mockHttpClient.execute(any())) | ||
| .thenReturn( | ||
| new Response( | ||
| testCase.responseBody, testCase.statusCode, "Bad Request", new URL(TEST_HOST))); | ||
| } | ||
| } else { | ||
| when(mockHttpClient.execute(any())) | ||
| .thenReturn(new Response(testCase.responseBody, new URL(TEST_HOST))); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include the mock HTTP client's request and response in the test case itself?
renaudhartert-db
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, deferring final approval to @parthban-db and @hectorcast-db.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM bar the JavaDocs note from Parth
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Show resolved
Hide resolved
| OpenIDConnectEndpoints endpoints, | ||
| IDTokenSource idTokenSource, | ||
| HttpClient httpClient) { | ||
| validate(clientId, "ClientID"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent, we need to validate this on Token(), not when creating the TokenSource.
In other providers, we only check if the fields are set when calling an endpoint/need a token. If we check it earlier, the client construction may fail.
| @Override | ||
| public Token getToken() { | ||
| // Validate all required parameters | ||
| if (!validate(clientId, "ClientID") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be more helpful to the user if they see which parameter is missing. Shall we hvae validate itself throw the exception with the field name in it?
Also note that validate takes the field name, but it does not use it.
| * required fields cause getToken() to throw IllegalArgumentException. | ||
| */ | ||
| @Test | ||
| void testParameterValidation() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be written as a parameterized test?
parthban-db
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
What changes are proposed in this pull request?
How is this tested?
The implementation is tested through unit tests that:
NO_CHANGELOG=true