(ctx context.Context, connCfg db.ConnectionConfig)
| 40 | } |
| 41 | |
| 42 | func 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 |
no test coverage detected