From 734da83abd97834a38205887e0f198e0ab5605de Mon Sep 17 00:00:00 2001 From: Jonathan Hess Date: Tue, 16 Jul 2024 16:48:39 -0600 Subject: [PATCH] chore: Expose the refresh strategy UseIAMAuthN() value to the dialer. Part of #842 --- dialer.go | 1 + internal/cloudsql/instance.go | 5 +++++ internal/cloudsql/lazy.go | 5 +++++ internal/mock/cloudsql.go | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dialer.go b/dialer.go index d5b0ff9b..16e329d2 100644 --- a/dialer.go +++ b/dialer.go @@ -107,6 +107,7 @@ type connectionInfoCache interface { ConnectionInfo(context.Context) (cloudsql.ConnectionInfo, error) UpdateRefresh(*bool) ForceRefresh() + UseIAMAuthN() bool io.Closer } diff --git a/internal/cloudsql/instance.go b/internal/cloudsql/instance.go index f8e44b3b..caabc43a 100644 --- a/internal/cloudsql/instance.go +++ b/internal/cloudsql/instance.go @@ -165,6 +165,11 @@ func (i *RefreshAheadCache) Close() error { return nil } +// UseIAMAuthN returns true if this dialer is using IAM AuthN +func (i *RefreshAheadCache) UseIAMAuthN() bool { + return i.useIAMAuthNDial +} + // ConnectionInfo contains all necessary information to connect securely to the // server-side Proxy running on a Cloud SQL instance. type ConnectionInfo struct { diff --git a/internal/cloudsql/lazy.go b/internal/cloudsql/lazy.go index 5b65b3b9..ef490c27 100644 --- a/internal/cloudsql/lazy.go +++ b/internal/cloudsql/lazy.go @@ -141,3 +141,8 @@ func (c *LazyRefreshCache) ForceRefresh() { func (c *LazyRefreshCache) Close() error { return nil } + +// UseIAMAuthN returns true if this dialer is using IAM AuthN +func (c *LazyRefreshCache) UseIAMAuthN() bool { + return c.useIAMAuthNDial +} diff --git a/internal/mock/cloudsql.go b/internal/mock/cloudsql.go index 27fc80a3..dc341240 100644 --- a/internal/mock/cloudsql.go +++ b/internal/mock/cloudsql.go @@ -325,7 +325,7 @@ func StartServerProxy(t *testing.T, i FakeCSQLInstance) func() { if err != nil { t.Fatalf("failed to create X.509 Key Pair: %v", err) } - ln, err := tls.Listen("tcp", ":3307", &tls.Config{ + ln, err := tls.Listen("tcp", fmt.Sprintf(":3307"), &tls.Config{ Certificates: []tls.Certificate{serverCert}, }) if err != nil {