(ctx context.Context, connCfg db.ConnectionConfig)
| 19 | ) |
| 20 | |
| 21 | func GetAWSConnectionConfig(ctx context.Context, connCfg db.ConnectionConfig) (aws.Config, error) { |
| 22 | region := connCfg.DataSource.GetRegion() |
| 23 | |
| 24 | // Only use static credentials if access key is provided |
| 25 | // If awsCredential exists but AccessKeyId is empty, fall back to default credential chain |
| 26 | // (EC2 instance role, env vars, etc.) for cross-account role assumption |
| 27 | if awsCredential := connCfg.DataSource.GetAwsCredential(); awsCredential != nil && awsCredential.AccessKeyId != "" { |
| 28 | return config.LoadDefaultConfig(ctx, |
| 29 | config.WithRegion(region), |
| 30 | config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( |
| 31 | awsCredential.AccessKeyId, |
| 32 | awsCredential.SecretAccessKey, |
| 33 | awsCredential.SessionToken, |
| 34 | )), |
| 35 | ) |
| 36 | } |
| 37 | |
| 38 | // Use default credential chain when no static credentials provided |
| 39 | return config.LoadDefaultConfig(ctx, config.WithRegion(region)) |
| 40 | } |
| 41 | |
| 42 | func GetGCPConnectionConfig(ctx context.Context, connCfg db.ConnectionConfig) (*cloudsqlconn.Dialer, error) { |
| 43 | // WithIAMAuthN enables IAM database authentication. |
no test coverage detected