MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetGCPConnectionConfig

Function GetGCPConnectionConfig

backend/plugin/db/util/connection.go:42–51  ·  view source on GitHub ↗
(ctx context.Context, connCfg db.ConnectionConfig)

Source from the content-addressed store, hash-verified

40}
41
42func GetGCPConnectionConfig(ctx context.Context, connCfg db.ConnectionConfig) (*cloudsqlconn.Dialer, error) {
43 // WithIAMAuthN enables IAM database authentication.
44 opts := []cloudsqlconn.Option{cloudsqlconn.WithIAMAuthN()}
45 // WithCredentialsJSON provides Cloud SQL Admin API access when a service account key is set.
46 if gcpCredential := connCfg.DataSource.GetGcpCredential(); gcpCredential != nil && len(gcpCredential.Content) > 0 {
47 opts = append(opts, cloudsqlconn.WithCredentialsJSON([]byte(gcpCredential.Content)))
48 }
49 opts = append(opts, cloudSQLDialOptions(connCfg.DataSource)...)
50 return cloudsqlconn.NewDialer(ctx, opts...)
51}
52
53// cloudSQLDialOptions selects the Cloud SQL IP type (private or PSC) for Google
54// Cloud SQL IAM connections. Public IP is the cloudsqlconn default, so no option

Callers 2

getCloudSQLConnectionFunction · 0.92

Calls 2

cloudSQLDialOptionsFunction · 0.85
GetGcpCredentialMethod · 0.45

Tested by

no test coverage detected