-
Notifications
You must be signed in to change notification settings - Fork 1.1k
spanner-jdbc: Step 11 - CredentialService #5875
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
spanner-jdbc: Step 11 - CredentialService #5875
Conversation
|
@chingor13 can we please get your input here? Can we make use of existing stuff in the auth library, or can we contribute there? |
|
This seems to be adding convenience methods for creating credentials. It's pretty opinionated on the options available for obtaining the credentials so it probably doesn't make sense to put it into the auth library. I'm not familiar with the configuration options available to jdbc - i.e. are you only allowed to configure via a configuration file (thus only have a String uri as configuration options)? We normally prefer users to instantiate their |
|
@chingor13 JDBC only allows you to configure the connection through the connection URL or through a |
chingor13
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.
Could we have some way to mock out the default credentials fetching? It seems that we're testing the actual implementation of the application default credentials which is the job of the google-auth-library tests. It could also be flakey in depending on test environments and trying to modify environment variables looks fragile.
...oogle-cloud-spanner-jdbc/src/main/java/com/google/cloud/spanner/jdbc/CredentialsService.java
Outdated
Show resolved
Hide resolved
|
@chingor13 Fetching app default credentials is now mocked in the test case. |
|
LGTM, will merge later today unless I hear any objections from @chingor13 |
...oogle-cloud-spanner-jdbc/src/main/java/com/google/cloud/spanner/jdbc/CredentialsService.java
Outdated
Show resolved
Hide resolved
|
|
||
| @VisibleForTesting | ||
| Storage internalCreateStorage() { | ||
| return StorageOptions.newBuilder().build().getService(); |
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.
If we're defining our own HttpTransport/HttpTransportFactory then we should probably be using them here as well.
But, since we're not actually defining anything custom (at least for now), we could probably use the defaults across the board (i.e. GoogleCredentials.fromStream(InputStream) instead of GoogleCredentials.fromStream(InputStream, HttpTransportFactory) and drop the CloudSpannerOAuthUtil inner 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.
There was a reason why it was made that way, but I cannot remember why (it's 9 months ago). I've just tested without the custom HttpTransport and it seems to work, so I've removed it.
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.
Eventually, it could be possible that a user needs a custom HttpTransport (proxy or other rules).
|
|
||
| @VisibleForTesting | ||
| Storage internalCreateStorage() { | ||
| return StorageOptions.newBuilder().build().getService(); |
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.
Eventually, it could be possible that a user needs a custom HttpTransport (proxy or other rules).
* add CredentialService * updated CR year * remove public visibility * make getAppDefault overridable and mock this in the test * removed 'internal' from private method name * add error msg as constant * removed custom httptransport
Adds the
CredentialsServicehelper class for loading credentials that have been specified in the connection URL. Credential files can be loaded from both a local file as well as Cloud Storage.