Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@olavloite
Copy link

Adds the CredentialsService helper 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.

@olavloite olavloite requested a review from kolea2 July 25, 2019 11:50
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 25, 2019
@olavloite olavloite changed the title spanner-jdbc: Step 10 - CredentialService spanner-jdbc: Step 11 - CredentialService Jul 25, 2019
@kolea2
Copy link
Contributor

kolea2 commented Jul 25, 2019

@chingor13 can we please get your input here? Can we make use of existing stuff in the auth library, or can we contribute there?

@kolea2 kolea2 requested a review from chingor13 July 25, 2019 14:50
@chingor13
Copy link
Contributor

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 GoogleCredentials themselves and provide that instance to our clients - this allows users to use all credential methods, rather than a curated subset of them.

@olavloite
Copy link
Author

@chingor13 JDBC only allows you to configure the connection through the connection URL or through a Properties object containing only String values. So yes, only String configuration is possible.

Copy link
Contributor

@chingor13 chingor13 left a 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.

@olavloite
Copy link
Author

@chingor13 Fetching app default credentials is now mocked in the test case.

@olavloite olavloite requested a review from chingor13 July 26, 2019 06:16
@kolea2
Copy link
Contributor

kolea2 commented Jul 26, 2019

LGTM, will merge later today unless I hear any objections from @chingor13


@VisibleForTesting
Storage internalCreateStorage() {
return StorageOptions.newBuilder().build().getService();
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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).

@chingor13 chingor13 self-requested a review July 26, 2019 16:44
@chingor13 chingor13 dismissed their stale review July 26, 2019 16:45

outdated


@VisibleForTesting
Storage internalCreateStorage() {
return StorageOptions.newBuilder().build().getService();
Copy link
Contributor

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).

@olavloite olavloite merged commit 774d1ad into googleapis:spanner-jdbc Jul 26, 2019
olavloite added a commit to olavloite/google-cloud-java that referenced this pull request Aug 5, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants