Skip to content

Commit 9f5aeb5

Browse files
committed
refactor: Use new ConnectSettings.DnsNames field to validate the server TLS certificate.
1 parent fb8c21c commit 9f5aeb5

File tree

8 files changed

+93
-2
lines changed

8 files changed

+93
-2
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/google-java-format.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jj-python-connector.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

google/cloud/sql/connector/client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,17 @@ async def _get_metadata(
157157
# Note that we have to check for PSC enablement also because CAS
158158
# instances also set the dnsName field.
159159
# Remove trailing period from DNS name. Required for SSL in Python
160-
dns_name = ret_dict.get("dnsName", "").rstrip(".")
161-
if dns_name and ret_dict.get("pscEnabled"):
160+
if ret_dict.get("pscEnabled"):
161+
psc_dns_names = [
162+
d["name"]
163+
for d in ret_dict.get("dnsNames", [])
164+
if d["connectionType"] == "PRIVATE_SERVICE_CONNECT" and d["dnsScope"] == "INSTANCE"]
165+
166+
dns_name = psc_dns_names[0] if psc_dns_names else None
167+
168+
if dns_name is None:
169+
dns_name = ret_dict.get("dnsName", "").rstrip(".")
170+
162171
ip_addresses["PSC"] = dns_name
163172

164173
return {

tests/unit/mocks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ async def connect_settings(self, request: Any) -> web.Response:
256256
"expirationTime": str(self.cert_expiration),
257257
},
258258
"dnsName": "abcde.12345.us-central1.sql.goog",
259+
"dnsNames":[{
260+
"name":"abcde.12345.us-central1.sql.goog",
261+
"connectionType":"PRIVATE_SERVICE_CONNECT",
262+
"dnsScope":"INSTANCE",
263+
}],
259264
"pscEnabled": self.psc_enabled,
260265
"ipAddresses": ip_addrs,
261266
"region": self.region,

0 commit comments

Comments
 (0)