dialOptions interprets appropriate dial options for a particular instance configuration
(c Config, i InstanceConnConfig)
| 284 | // dialOptions interprets appropriate dial options for a particular instance |
| 285 | // configuration |
| 286 | func dialOptions(c Config, i InstanceConnConfig) []cloudsqlconn.DialOption { |
| 287 | var opts []cloudsqlconn.DialOption |
| 288 | |
| 289 | if i.IAMAuthN != nil { |
| 290 | opts = append(opts, cloudsqlconn.WithDialIAMAuthN(*i.IAMAuthN)) |
| 291 | } |
| 292 | if i.SQLDataEnabled != nil && *i.SQLDataEnabled || c.SQLDataEnabled { |
| 293 | opts = append(opts, cloudsqlconn.WithSQLData()) |
| 294 | } |
| 295 | |
| 296 | switch { |
| 297 | // If private IP is enabled at the instance level, or private IP is enabled globally |
| 298 | // add the option. |
| 299 | case i.PrivateIP != nil && *i.PrivateIP || i.PrivateIP == nil && c.PrivateIP: |
| 300 | opts = append(opts, cloudsqlconn.WithPrivateIP()) |
| 301 | // If PSC is enabled at the instance level, or PSC is enabled globally |
| 302 | // add the option. |
| 303 | case i.PSC != nil && *i.PSC || i.PSC == nil && c.PSC: |
| 304 | opts = append(opts, cloudsqlconn.WithPSC()) |
| 305 | case c.AutoIP: |
| 306 | opts = append(opts, cloudsqlconn.WithAutoIP()) |
| 307 | default: |
| 308 | // assume public IP by default |
| 309 | } |
| 310 | if networkType(&c, i) == "unix" { |
| 311 | opts = append(opts, cloudsqlconn.WithMdxClientProtocolType("uds")) |
| 312 | } else { |
| 313 | opts = append(opts, cloudsqlconn.WithMdxClientProtocolType("tcp")) |
| 314 | } |
| 315 | |
| 316 | return opts |
| 317 | } |
| 318 | |
| 319 | func parseImpersonationChain(chain string) (string, []string) { |
| 320 | accts := strings.Split(chain, ",") |
no test coverage detected