resolveTenant picks the single tenant to act on: the only active one, or the CQ_PLATFORM_TENANT_ID match when several are active. Returns errNoActiveTenant when there are none, and an errAmbiguousTenant-wrapped error (carrying an actionable Hint) when several are active without a matching override.
(tenants []cloudquery_api.PlatformTenantSummary)
| 470 | // actionable Hint) when several are active without a matching override. Pure (no |
| 471 | // logging) so every call site shares one decision. |
| 472 | func resolveTenant(tenants []cloudquery_api.PlatformTenantSummary) (cloudquery_api.PlatformTenantSummary, error) { |
| 473 | switch len(tenants) { |
| 474 | case 0: |
| 475 | return cloudquery_api.PlatformTenantSummary{}, errNoActiveTenant |
| 476 | case 1: |
| 477 | return tenants[0], nil |
| 478 | } |
| 479 | want := os.Getenv(envTenantID) |
| 480 | if want == "" { |
| 481 | return cloudquery_api.PlatformTenantSummary{}, fmt.Errorf("%w. Hint: set %s to the tenant id you want to sync to", errAmbiguousTenant, envTenantID) |
| 482 | } |
| 483 | for _, t := range tenants { |
| 484 | if t.TenantId.String() == want { |
| 485 | return t, nil |
| 486 | } |
| 487 | } |
| 488 | return cloudquery_api.PlatformTenantSummary{}, fmt.Errorf("%w: %s=%s matches none of them. Hint: set it to one of the team's active tenant ids", errAmbiguousTenant, envTenantID, want) |
| 489 | } |
| 490 | |
| 491 | // YYYYMMDDhhmmssfff — same shape platform/syncs-transformer uses, so |
| 492 | // external-sync rows share the keyspace. |
no test coverage detected