Skip to content

Conversation

sagnghos
Copy link
Contributor

@sagnghos sagnghos commented Feb 22, 2025

Default authentication support for external hosts by using auth token path mentioned in env variable

@sagnghos sagnghos requested review from a team as code owners February 22, 2025 18:53
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/java-spanner API. labels Feb 22, 2025
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics();
private String monitoringHost = SpannerOptions.environment.getMonitoringHost();
private SslContext mTLSContext = null;
private boolean isExternalHost = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this a method instead of a field. This now gives the impression of being in sync with the current settings, but it isn't if you do weird stuff (like first setting an emulator host and then overriding that by setting a host). By implementing it as a method, you can just calculate it based on the values at that time, instead of trying to set the correct value when setHost / setEmulatorHost is being set.

Copy link
Contributor Author

@sagnghos sagnghos Feb 25, 2025

Choose a reason for hiding this comment

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

removed the need to check emulatorHost. But had to keep isExternalHost calculation in setHost. Can't convert it to a method to do a on demand calculation since host is a private member in the parent builder class
#3656

enableEndToEndTracing = builder.enableEndToEndTracing;
monitoringHost = builder.monitoringHost;
String externalHostTokenPath = System.getenv("SPANNER_EXTERNAL_HOST_AUTH_TOKEN");
if (builder.isExternalHost && builder.emulatorHost == null && externalHostTokenPath != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Prefer !Strings.isNullOrEmpty(externalHostTokenPath) over a null check.
  2. This check should also include && builder.credentials == null to prevent the default credentials to override specific credentials that have been set for this builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done
#3656

if (options.getConfigurator() != null) {
options.getConfigurator().configure(builder);
}
if (options.usesEmulator()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed
#3656

} catch (IOException e) {
throw SpannerExceptionFactory.newSpannerException(e);
}
credentials = new GoogleCredentials(new AccessToken(token, null));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This constructor is deprecated. Use the static create method instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done
#3656

@sagnghos
Copy link
Contributor Author

Closing this PR as its not able to upload the latest commit and stuck in this state for 10hrs

Screenshot 2025-02-25 at 8 32 15 AM

@sagnghos sagnghos closed this Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants