From 088580668a93a01bc7bc3f40fc15e9b1c9b63158 Mon Sep 17 00:00:00 2001 From: Trent Clarke Date: Mon, 2 Dec 2024 13:11:46 +1100 Subject: [PATCH] Expose Account Assignmnets via cache (#49567) Extends cache to allow consumers to fetch a specific Identity Center account assignment, rather than just listing them. --- lib/auth/authclient/api.go | 3 +++ lib/cache/cache.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/auth/authclient/api.go b/lib/auth/authclient/api.go index 932d78a383505..d2e206fd8dd51 100644 --- a/lib/auth/authclient/api.go +++ b/lib/auth/authclient/api.go @@ -1237,6 +1237,9 @@ type Cache interface { // GetProvisioningState gets a specific provisioning state GetProvisioningState(context.Context, services.DownstreamID, services.ProvisioningStateID) (*provisioningv1.PrincipalState, error) + // GetAccountAssignment fetches specific IdentityCenter Account Assignment + GetAccountAssignment(context.Context, services.IdentityCenterAccountAssignmentID) (services.IdentityCenterAccountAssignment, error) + // ListAccountAssignments fetches a paginated list of IdentityCenter Account Assignments ListAccountAssignments(context.Context, int, *pagination.PageRequestToken) ([]services.IdentityCenterAccountAssignment, pagination.NextPageToken, error) } diff --git a/lib/cache/cache.go b/lib/cache/cache.go index 2ba3dbebfbbf5..d0e8408e07d0b 100644 --- a/lib/cache/cache.go +++ b/lib/cache/cache.go @@ -3560,6 +3560,19 @@ func (c *Cache) GetProvisioningState(ctx context.Context, downstream services.Do return rg.reader.GetProvisioningState(ctx, downstream, id) } +func (c *Cache) GetAccountAssignment(ctx context.Context, id services.IdentityCenterAccountAssignmentID) (services.IdentityCenterAccountAssignment, error) { + ctx, span := c.Tracer.Start(ctx, "cache/GetAccountAssignment") + defer span.End() + + rg, err := readCollectionCache(c, c.collections.identityCenterAccountAssignments) + if err != nil { + return services.IdentityCenterAccountAssignment{}, trace.Wrap(err) + } + defer rg.Release() + + return rg.reader.GetAccountAssignment(ctx, id) +} + // ListAccountAssignments fetches a paginated list of IdentityCenter Account Assignments func (c *Cache) ListAccountAssignments(ctx context.Context, pageSize int, pageToken *pagination.PageRequestToken) ([]services.IdentityCenterAccountAssignment, pagination.NextPageToken, error) { ctx, span := c.Tracer.Start(ctx, "cache/ListAccountAssignments")