-
Notifications
You must be signed in to change notification settings - Fork 33
Support for parsing custom scopes in config file #581
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
base: main
Are you sure you want to change the base?
Conversation
54ffcc4 to
782d3c9
Compare
782d3c9 to
f1b8d08
Compare
f1b8d08 to
42aef75
Compare
|
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. |
| @ConfigAttribute(env = "DATABRICKS_CLIENT_SECRET", auth = "oauth", sensitive = true) | ||
| private String clientSecret; | ||
|
|
||
| @ConfigAttribute(env = "DATABRICKS_SCOPES", auth = "oauth") |
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 actually wasn't possible to pass scopes through environment variable because Lists weren't parsed correctly, so removing this is not a breaking change.
Removing the environment variable attribute for consistency with the other SDKs where we are not supporting setting scopes via environment variables.
|
|
||
| @ConfigAttribute(env = "DATABRICKS_SCOPES", auth = "oauth") | ||
| @ConfigAttribute(auth = "oauth") | ||
| private List<String> scopes; |
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 is a backward-incompatible change. What's the rationale for removing this environment variable?
| ParameterizedType paramType = (ParameterizedType) field.getGenericType(); | ||
| if (paramType.getActualTypeArguments().length > 0 | ||
| && paramType.getActualTypeArguments()[0] == String.class) { | ||
| // Split by commas and/or whitespace and filter out empty strings |
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.
Why do we have two delimiters? Shouldn't we only have a single delimiter, preferably a comma?
|
|
||
| public String getAsString(Object value) { | ||
| if (value instanceof List) { | ||
| return String.join(" ", (List<String>) value); |
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.
You check the instanceof with just List, however, you typecast the variable to List , I think it can lead to unexpected behaviors.
|
|
||
| public String getAsString(Object value) { | ||
| if (value instanceof List) { | ||
| return String.join(" ", (List<String>) value); |
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.
Also, why did you choose a space as a delimiter instead of a comma?
| field.set(cfg, ProxyConfig.ProxyAuthType.valueOf(value)); | ||
| } else if (List.class.isAssignableFrom(field.getType())) { | ||
| // Handle List<String> fields (e.g., scopes) | ||
| // Parse comma and/or whitespace separated values from environment variable or config file |
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.
| // Parse comma and/or whitespace separated values from environment variable or config file | |
| // Parse comma and/or whitespace separated values from environment variable or config file. |
| /** Sort scopes in-place for better de-duplication in the refresh token cache. */ | ||
| private void sortScopes() { |
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 is a private function, so according to Java convention. We shouldn't have the comments in the javadoc format.
| /** Sort scopes in-place for better de-duplication in the refresh token cache. */ | |
| private void sortScopes() { | |
| // Sort scopes in-place for better de-duplication in the refresh token cache. | |
| private void sortScopes() { |
| // Config File Scope Parsing Tests | ||
|
|
||
| private static Stream<Arguments> provideConfigFileScopesTestCases() { |
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.
| // Config File Scope Parsing Tests | |
| private static Stream<Arguments> provideConfigFileScopesTestCases() { | |
| // Config File Scope Parsing Tests. | |
| private static Stream<Arguments> provideConfigFileScopesTestCases() { |
| assertEquals(expectedScopes.size(), scopes.size()); | ||
| for (int i = 0; i < expectedScopes.size(); i++) { | ||
| assertEquals(expectedScopes.get(i), scopes.get(i)); | ||
| } |
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 use a direct comparison, like: assertEquals(expectedScopes, config.getScopes())? Instead of the comparison, you are doing? It seems a bit verbose.
| field.set(cfg, seconds > 0 ? Duration.ofSeconds(seconds) : null); | ||
| } else if (field.getType() == ProxyConfig.ProxyAuthType.class) { | ||
| field.set(cfg, ProxyConfig.ProxyAuthType.valueOf(value)); | ||
| } else if (List.class.isAssignableFrom(field.getType())) { | ||
| // Handle List<String> fields (e.g., scopes) |
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 have a question about this big if-else block. This block doesn't have a default else, which throws an error when an unexpected type appears in the config. So is the current code simply ignoring those types?
Summary
The Java SDK already had support for custom scopes in all three OAuth flows. It only lacked support for configuring scopes in a config file. This PR covers that gap.
Testing
Tested by loading configurations from a test config file and resolving them.
NO_CHANGELOG=true