Skip to content

Commit 32af9a1

Browse files
authored
feat(spanner): support Private Service Connect (PSC) endpoint override (#443)
1 parent 7a9fb8a commit 32af9a1

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

spanner/src/apiv1/conn_pool.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,23 @@ impl ConnectionManager {
2121
domain: &str,
2222
conn_options: &ConnectionOptions,
2323
) -> Result<Self, Error> {
24+
// Support Private Service Connect (PSC) endpoints for Spanner.
25+
//
26+
// When `domain` is a full HTTPS URL (e.g. "https://spanner-nonprod.p.googleapis.com")
27+
// we use it as both the TLS SNI hostname and the gRPC connection target, mirroring
28+
// the Java SDK's `SpannerOptions.setHost("https://...")` behaviour.
29+
//
30+
// When `domain` is a plain hostname (default: "spanner.googleapis.com") the existing
31+
// behaviour is preserved: the public AUDIENCE constant is used as the target.
32+
let (sni_domain, audience): (String, &str) = if domain.starts_with("https://") {
33+
let host = domain.trim_start_matches("https://").trim_end_matches('/');
34+
(host.to_string(), domain)
35+
} else {
36+
(domain.to_string(), AUDIENCE)
37+
};
38+
2439
Ok(ConnectionManager {
25-
inner: GRPCConnectionManager::new(pool_size, domain, AUDIENCE, environment, conn_options).await?,
40+
inner: GRPCConnectionManager::new(pool_size, sni_domain, audience, environment, conn_options).await?,
2641
})
2742
}
2843

0 commit comments

Comments
 (0)