Identity: Rename "namespace" to "type" in the requester interface (#90567)

This commit is contained in:
Ryan McKinley
2024-07-25 12:52:14 +03:00
committed by GitHub
parent 8cdf5ee824
commit 9db3bc926e
109 changed files with 649 additions and 632 deletions
+20 -20
View File
@@ -43,7 +43,7 @@ type SignedInUser 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 `json:"-" xorm:"-"`
NamespacedID identity.NamespaceID
NamespacedID identity.TypedID
}
func (u *SignedInUser) ShouldUpdateLastSeenAt() bool {
@@ -98,7 +98,7 @@ func (u *SignedInUser) GetAllowedKubernetesNamespace() string {
// GetCacheKey returns a unique key for the entity.
// Add an extra prefix to avoid collisions with other caches
func (u *SignedInUser) GetCacheKey() string {
namespace, id := u.GetNamespacedID()
namespace, id := u.GetTypedID()
if !u.HasUniqueId() {
// Hack use the org role as id for identities that do not have a unique id
// e.g. anonymous and render key.
@@ -173,46 +173,46 @@ func (u *SignedInUser) GetOrgRole() identity.RoleType {
}
// GetID returns namespaced id for the entity
func (u *SignedInUser) GetID() identity.NamespaceID {
ns, id := u.GetNamespacedID()
return identity.NewNamespaceIDString(ns, id)
func (u *SignedInUser) GetID() identity.TypedID {
ns, id := u.GetTypedID()
return identity.NewTypedIDString(ns, id)
}
// GetNamespacedID returns the namespace and ID of the active entity
// GetTypedID returns the namespace and ID of the active entity
// The namespace is one of the constants defined in pkg/apimachinery/identity
func (u *SignedInUser) GetNamespacedID() (identity.Namespace, string) {
func (u *SignedInUser) GetTypedID() (identity.IdentityType, string) {
switch {
case u.ApiKeyID != 0:
return identity.NamespaceAPIKey, strconv.FormatInt(u.ApiKeyID, 10)
return identity.TypeAPIKey, strconv.FormatInt(u.ApiKeyID, 10)
case u.IsServiceAccount:
return identity.NamespaceServiceAccount, strconv.FormatInt(u.UserID, 10)
return identity.TypeServiceAccount, strconv.FormatInt(u.UserID, 10)
case u.UserID > 0:
return identity.NamespaceUser, strconv.FormatInt(u.UserID, 10)
return identity.TypeUser, strconv.FormatInt(u.UserID, 10)
case u.IsAnonymous:
return identity.NamespaceAnonymous, "0"
return identity.TypeAnonymous, "0"
case u.AuthenticatedBy == "render" && u.UserID == 0:
return identity.NamespaceRenderService, "0"
return identity.TypeRenderService, "0"
}
return u.NamespacedID.Namespace(), u.NamespacedID.ID()
return u.NamespacedID.Type(), u.NamespacedID.ID()
}
// GetUID returns namespaced uid for the entity
func (u *SignedInUser) GetUID() identity.NamespaceID {
func (u *SignedInUser) GetUID() identity.TypedID {
switch {
case u.ApiKeyID != 0:
return identity.NewNamespaceIDString(identity.NamespaceAPIKey, strconv.FormatInt(u.ApiKeyID, 10))
return identity.NewTypedIDString(identity.TypeAPIKey, strconv.FormatInt(u.ApiKeyID, 10))
case u.IsServiceAccount:
return identity.NewNamespaceIDString(identity.NamespaceServiceAccount, u.UserUID)
return identity.NewTypedIDString(identity.TypeServiceAccount, u.UserUID)
case u.UserID > 0:
return identity.NewNamespaceIDString(identity.NamespaceUser, u.UserUID)
return identity.NewTypedIDString(identity.TypeUser, u.UserUID)
case u.IsAnonymous:
return identity.NewNamespaceIDString(identity.NamespaceAnonymous, "0")
return identity.NewTypedIDString(identity.TypeAnonymous, "0")
case u.AuthenticatedBy == "render" && u.UserID == 0:
return identity.NewNamespaceIDString(identity.NamespaceRenderService, "0")
return identity.NewTypedIDString(identity.TypeRenderService, "0")
}
return identity.NewNamespaceIDString(identity.NamespaceEmpty, "0")
return identity.NewTypedIDString(identity.TypeEmpty, "0")
}
func (u *SignedInUser) GetAuthID() string {
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/grafana/grafana/pkg/apimachinery/errutil"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/services/notifications"
@@ -152,6 +153,6 @@ func (s *Verifier) Complete(ctx context.Context, cmd user.CompleteEmailVerifyCom
// remove the current token, so a new one can be generated with correct values.
return s.is.RemoveIDToken(
ctx,
&authn.Identity{ID: authn.NewNamespaceID(authn.NamespaceUser, usr.ID), OrgID: usr.OrgID},
&authn.Identity{ID: identity.NewTypedID(identity.TypeUser, usr.ID), OrgID: usr.OrgID},
)
}