-
Notifications
You must be signed in to change notification settings - Fork 132
feat: default authentication support for external hosts #3655
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
@@ -967,6 +990,7 @@ public static class Builder | |||
private boolean enableBuiltInMetrics = SpannerOptions.environment.isEnableBuiltInMetrics(); | |||
private String monitoringHost = SpannerOptions.environment.getMonitoringHost(); | |||
private SslContext mTLSContext = null; | |||
private boolean isExternalHost = false; |
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 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.
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.
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
@@ -799,6 +810,18 @@ protected SpannerOptions(Builder builder) { | |||
enableBuiltInMetrics = builder.enableBuiltInMetrics; | |||
enableEndToEndTracing = builder.enableEndToEndTracing; | |||
monitoringHost = builder.monitoringHost; | |||
String externalHostTokenPath = System.getenv("SPANNER_EXTERNAL_HOST_AUTH_TOKEN"); | |||
if (builder.isExternalHost && builder.emulatorHost == null && externalHostTokenPath != null) { |
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.
- Prefer
!Strings.isNullOrEmpty(externalHostTokenPath)
over a null check. - This check should also include
&& builder.credentials == null
to prevent the default credentials to override specific credentials that have been set for this builder.
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.
Done
#3656
@@ -407,6 +407,9 @@ Spanner createSpanner(SpannerPoolKey key, ConnectionOptions options) { | |||
if (options.getConfigurator() != null) { | |||
options.getConfigurator().configure(builder); | |||
} | |||
if (options.usesEmulator()) { |
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 need this now?
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.
Removed
#3656
} catch (IOException e) { | ||
throw SpannerExceptionFactory.newSpannerException(e); | ||
} | ||
credentials = new GoogleCredentials(new AccessToken(token, null)); |
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 constructor is deprecated. Use the static create
method instead.
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.
Done
#3656
Default authentication support for external hosts by using auth token path mentioned in env variable