Skip to content

Commit

Permalink
fix: avoid unchecked casts from IdentityPool to PrivilegedIdentityPool
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Feb 7, 2023
1 parent 989c99d commit 71d35dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ type deleteIdentity struct {
// 404: errorGeneric
// default: errorGeneric
func (h *Handler) delete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if err := h.r.IdentityPool().(PrivilegedPool).DeleteIdentity(r.Context(), x.ParseUUID(ps.ByName("id"))); err != nil {
if err := h.r.PrivilegedIdentityPool().DeleteIdentity(r.Context(), x.ParseUUID(ps.ByName("id"))); err != nil {
h.r.Writer().WriteError(w, r, err)
return
}
Expand Down
15 changes: 8 additions & 7 deletions identity/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type (
managerDependencies interface {
config.Provider
PoolProvider
PrivilegedPoolProvider
x.TracingProvider
courier.Provider
ValidationProvider
Expand Down Expand Up @@ -84,7 +85,7 @@ func (m *Manager) Create(ctx context.Context, i *Identity, opts ...ManagerOption
return err
}

return m.r.IdentityPool().(PrivilegedPool).CreateIdentity(ctx, i)
return m.r.PrivilegedIdentityPool().CreateIdentity(ctx, i)
}

func (m *Manager) requiresPrivilegedAccess(ctx context.Context, original, updated *Identity, o *ManagerOptions) (err error) {
Expand Down Expand Up @@ -118,7 +119,7 @@ func (m *Manager) Update(ctx context.Context, updated *Identity, opts ...Manager
return err
}

original, err := m.r.IdentityPool().(PrivilegedPool).GetIdentityConfidential(ctx, updated.ID)
original, err := m.r.PrivilegedIdentityPool().GetIdentityConfidential(ctx, updated.ID)
if err != nil {
return err
}
Expand All @@ -127,15 +128,15 @@ func (m *Manager) Update(ctx context.Context, updated *Identity, opts ...Manager
return err
}

return m.r.IdentityPool().(PrivilegedPool).UpdateIdentity(ctx, updated)
return m.r.PrivilegedIdentityPool().UpdateIdentity(ctx, updated)
}

func (m *Manager) UpdateSchemaID(ctx context.Context, id uuid.UUID, schemaID string, opts ...ManagerOption) (err error) {
ctx, span := m.r.Tracer(ctx).Tracer().Start(ctx, "identity.Manager.UpdateSchemaID")
defer otelx.End(span, &err)

o := newManagerOptions(opts)
original, err := m.r.IdentityPool().(PrivilegedPool).GetIdentityConfidential(ctx, id)
original, err := m.r.PrivilegedIdentityPool().GetIdentityConfidential(ctx, id)
if err != nil {
return err
}
Expand All @@ -149,15 +150,15 @@ func (m *Manager) UpdateSchemaID(ctx context.Context, id uuid.UUID, schemaID str
return err
}

return m.r.IdentityPool().(PrivilegedPool).UpdateIdentity(ctx, original)
return m.r.PrivilegedIdentityPool().UpdateIdentity(ctx, original)
}

func (m *Manager) SetTraits(ctx context.Context, id uuid.UUID, traits Traits, opts ...ManagerOption) (_ *Identity, err error) {
ctx, span := m.r.Tracer(ctx).Tracer().Start(ctx, "identity.Manager.SetTraits")
defer otelx.End(span, &err)

o := newManagerOptions(opts)
original, err := m.r.IdentityPool().(PrivilegedPool).GetIdentityConfidential(ctx, id)
original, err := m.r.PrivilegedIdentityPool().GetIdentityConfidential(ctx, id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -185,7 +186,7 @@ func (m *Manager) UpdateTraits(ctx context.Context, id uuid.UUID, traits Traits,
return err
}

return m.r.IdentityPool().(PrivilegedPool).UpdateIdentity(ctx, updated)
return m.r.PrivilegedIdentityPool().UpdateIdentity(ctx, updated)
}

func (m *Manager) ValidateIdentity(ctx context.Context, i *Identity, o *ManagerOptions) (err error) {
Expand Down

0 comments on commit 71d35dd

Please sign in to comment.