Chore: Fix error handling in postDashboard, remove UserDisplayDTO, fix live redis client initialization (#87206)

* clean up error handling in postDashboard and remove UserDisplayDTO

* replace GetUserUID with GetUID and GetNamespacedUID, enforce namespace constant type

* lint fix

* lint fix

* more lint fixes
This commit is contained in:
Dan Cech
2024-05-06 14:17:34 -04:00
committed by GitHub
parent ba8b4bde3a
commit 41bee274fd
27 changed files with 206 additions and 183 deletions
+1 -1
View File
@@ -373,7 +373,7 @@ func (s *Service) resolveIdenity(ctx context.Context, orgID int64, namespaceID a
}}, nil
}
resolver, ok := s.idenityResolverClients[namespaceID.Namespace()]
resolver, ok := s.idenityResolverClients[namespaceID.Namespace().String()]
if !ok {
return nil, authn.ErrUnsupportedIdentity.Errorf("no resolver for : %s", namespaceID.Namespace())
}
+1 -1
View File
@@ -514,7 +514,7 @@ func TestService_ResolveIdentity(t *testing.T) {
t.Run("should resolve for valid namespace if client is registered", func(t *testing.T) {
svc := setupTests(t, func(svc *Service) {
svc.RegisterClient(&authntest.MockClient{
NamespaceFunc: func() string { return authn.NamespaceAPIKey },
NamespaceFunc: func() string { return authn.NamespaceAPIKey.String() },
ResolveIdentityFunc: func(ctx context.Context, orgID int64, namespaceID authn.NamespaceID) (*authn.Identity, error) {
return &authn.Identity{}, nil
},
+1 -1
View File
@@ -135,7 +135,7 @@ func (s *APIKey) Priority() uint {
}
func (s *APIKey) Namespace() string {
return authn.NamespaceAPIKey
return authn.NamespaceAPIKey.String()
}
func (s *APIKey) ResolveIdentity(ctx context.Context, orgID int64, namespaceID authn.NamespaceID) (*authn.Identity, error) {
+12 -1
View File
@@ -71,16 +71,27 @@ type Identity struct {
// IDToken is a signed token representing the identity that can be forwarded to plugins and external services.
// Will only be set when featuremgmt.FlagIdForwarding is enabled.
IDToken string
// UserUID is the unique identifier for the entity in the Grafana database.
UserUID string
}
func (i *Identity) GetID() NamespaceID {
return i.ID
}
func (i *Identity) GetNamespacedID() (namespace string, identifier string) {
func (i *Identity) GetNamespacedID() (namespace identity.Namespace, identifier string) {
return i.ID.Namespace(), i.ID.ID()
}
func (i *Identity) GetUID() NamespaceID {
ns, uid := i.GetNamespacedUID()
return identity.NewNamespaceIDString(ns, uid)
}
func (i *Identity) GetNamespacedUID() (namespace identity.Namespace, identifier string) {
return i.ID.Namespace(), i.UserUID
}
func (i *Identity) GetAuthID() string {
return i.AuthID
}