Skip to content

Commit cdafc85

Browse files
committed
Add authority param support to DSN
Signed-off-by: Marco Pracucci <[email protected]>
1 parent 1eca441 commit cdafc85

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

connection_properties.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,17 @@ var propertyEndpoint = createConnectionProperty(
286286
connectionstate.ContextStartup,
287287
connectionstate.ConvertString,
288288
)
289+
var propertyAuthority = createConnectionProperty(
290+
"authority",
291+
"The expected server name in the TLS handshake. By default, the endpoint hostname is used. This option "+
292+
"is useful when connecting to Spanner via Google Private Connect or other custom endpoints where the "+
293+
"endpoint hostname does not match the server’s TLS certificate.",
294+
"",
295+
false,
296+
nil,
297+
connectionstate.ContextStartup,
298+
connectionstate.ConvertString,
299+
)
289300
var propertyCredentials = createConnectionProperty(
290301
"credentials",
291302
"The location of the credentials file to use for this connection. If neither this property or encoded "+

driver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ type ConnectorConfig struct {
372372
// Leave this empty to use the standard Spanner API endpoint.
373373
Host string
374374

375+
// The expected server name in the TLS handshake.
376+
// Leave this empty to use the endpoint hostname.
377+
Authority string
378+
375379
// Project, Instance, and Database identify the database that the connector
376380
// should create connections for.
377381
Project string
@@ -568,6 +572,10 @@ func createConnector(d *Driver, connectorConfig ConnectorConfig) (*connector, er
568572
if connectorConfig.Host != "" {
569573
opts = append(opts, option.WithEndpoint(connectorConfig.Host))
570574
}
575+
assignPropertyValueIfExists(state, propertyAuthority, &connectorConfig.Authority)
576+
if connectorConfig.Authority != "" {
577+
opts = append(opts, option.WithGRPCDialOption(grpc.WithAuthority(connectorConfig.Authority)))
578+
}
571579
if val := propertyCredentials.GetValueOrDefault(state); val != "" {
572580
opts = append(opts, option.WithCredentialsFile(val))
573581
}

0 commit comments

Comments
 (0)