MCPcopy Index your code
hub / github.com/coder/coder / AnalyzeOIDCLinks

Function AnalyzeOIDCLinks

coderd/authlink/authlink.go:37–59  ·  view source on GitHub ↗

AnalyzeOIDCLinks queries OIDC user links grouped by issuer prefix and categorizes them relative to expectedIssuer.

(ctx context.Context, db database.Store, expectedIssuer string)

Source from the content-addressed store, hash-verified

35// AnalyzeOIDCLinks queries OIDC user links grouped by issuer prefix and
36// categorizes them relative to expectedIssuer.
37func 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

Callers 3

TestAnalyzeOIDCLinksFunction · 0.92
oidcAuthLinksFunction · 0.92

Calls 2

ErrorfMethod · 0.45

Tested by 1

TestAnalyzeOIDCLinksFunction · 0.74