AnalyzeOIDCLinks queries OIDC user links grouped by issuer prefix and categorizes them relative to expectedIssuer.
(ctx context.Context, db database.Store, expectedIssuer string)
| 35 | // AnalyzeOIDCLinks queries OIDC user links grouped by issuer prefix and |
| 36 | // categorizes them relative to expectedIssuer. |
| 37 | func AnalyzeOIDCLinks(ctx context.Context, db database.Store, expectedIssuer string) (OIDCLinkAnalysis, error) { |
| 38 | rows, err := db.CountOIDCLinkedIDsByIssuer(ctx) |
| 39 | if err != nil { |
| 40 | return OIDCLinkAnalysis{}, xerrors.Errorf("count OIDC linked IDs by issuer: %w", err) |
| 41 | } |
| 42 | |
| 43 | analysis := OIDCLinkAnalysis{ |
| 44 | MismatchedCounts: make(map[string]int), |
| 45 | } |
| 46 | for _, row := range rows { |
| 47 | count := int(row.Count) |
| 48 | analysis.Total += count |
| 49 | switch { |
| 50 | case row.IssuerPrefix == "": |
| 51 | analysis.Unlinked += count |
| 52 | case row.IssuerPrefix == expectedIssuer: |
| 53 | analysis.CorrectIssuer += count |
| 54 | default: |
| 55 | analysis.MismatchedCounts[row.IssuerPrefix] += count |
| 56 | } |
| 57 | } |
| 58 | return analysis, nil |
| 59 | } |
| 60 | |
| 61 | // ResetMismatchedOIDCLinks resets linked_id to empty for all OIDC links whose |
| 62 | // issuer prefix does not match expectedIssuer. Returns the number of rows |