Authn: move namespace id type (#86853)
* Use RoleType from org package * Move to identity package and re-export from authn * Replace usage of top level functions for identity Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
This commit is contained in:
@@ -260,7 +260,7 @@ func (s *Service) RedirectURL(ctx context.Context, client string, r *authn.Reque
|
||||
return redirectClient.RedirectURL(ctx, r)
|
||||
}
|
||||
|
||||
func (s *Service) Logout(ctx context.Context, user identity.Requester, sessionToken *auth.UserToken) (*authn.Redirect, error) {
|
||||
func (s *Service) Logout(ctx context.Context, user authn.Requester, sessionToken *auth.UserToken) (*authn.Redirect, error) {
|
||||
ctx, span := s.tracer.Start(ctx, "authn.Logout")
|
||||
defer span.End()
|
||||
|
||||
|
||||
@@ -488,7 +488,7 @@ func TestService_ResolveIdentity(t *testing.T) {
|
||||
t.Run("should return error for for unknown namespace", func(t *testing.T) {
|
||||
svc := setupTests(t)
|
||||
_, err := svc.ResolveIdentity(context.Background(), 1, "some:1")
|
||||
assert.ErrorIs(t, err, authn.ErrInvalidNamepsaceID)
|
||||
assert.ErrorIs(t, err, authn.ErrInvalidNamespaceID)
|
||||
})
|
||||
|
||||
t.Run("should return error for for namespace that don't have a resolver", func(t *testing.T) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/login/social/socialtest"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
"github.com/grafana/grafana/pkg/services/auth/authtest"
|
||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/oauthtoken/oauthtokentest"
|
||||
@@ -92,7 +91,7 @@ func TestOAuthTokenSync_SyncOAuthTokenHook(t *testing.T) {
|
||||
)
|
||||
|
||||
service := &oauthtokentest.MockOauthTokenService{
|
||||
HasOAuthEntryFunc: func(ctx context.Context, usr identity.Requester) (*login.UserAuth, bool, error) {
|
||||
HasOAuthEntryFunc: func(ctx context.Context, usr authn.Requester) (*login.UserAuth, bool, error) {
|
||||
hasEntryCalled = true
|
||||
return tt.expectedHasEntryToken, tt.expectedHasEntryToken != nil, nil
|
||||
},
|
||||
@@ -100,7 +99,7 @@ func TestOAuthTokenSync_SyncOAuthTokenHook(t *testing.T) {
|
||||
invalidateTokensCalled = true
|
||||
return nil
|
||||
},
|
||||
TryTokenRefreshFunc: func(ctx context.Context, usr identity.Requester) error {
|
||||
TryTokenRefreshFunc: func(ctx context.Context, usr authn.Requester) error {
|
||||
tryRefreshCalled = true
|
||||
return tt.expectedTryRefreshErr
|
||||
},
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
acmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/auth/identity"
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -143,7 +142,7 @@ func TestRBACSync_SyncCloudRoles(t *testing.T) {
|
||||
|
||||
func setupTestEnv() *RBACSync {
|
||||
acMock := &acmock.Mock{
|
||||
GetUserPermissionsFunc: func(ctx context.Context, siu identity.Requester, o accesscontrol.Options) ([]accesscontrol.Permission, error) {
|
||||
GetUserPermissionsFunc: func(ctx context.Context, siu authn.Requester, o accesscontrol.Options) ([]accesscontrol.Permission, error) {
|
||||
return []accesscontrol.Permission{
|
||||
{Action: accesscontrol.ActionUsersRead},
|
||||
}, nil
|
||||
|
||||
@@ -4,10 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
authidentity "github.com/grafana/grafana/pkg/services/auth/identity"
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -112,14 +110,13 @@ func (s *UserSync) FetchSyncedUserHook(ctx context.Context, identity *authn.Iden
|
||||
return nil
|
||||
}
|
||||
|
||||
namespace, id := identity.GetNamespacedID()
|
||||
if !authidentity.IsNamespace(namespace, authn.NamespaceUser, authn.NamespaceServiceAccount) {
|
||||
if !identity.ID.IsNamespace(authn.NamespaceUser, authn.NamespaceServiceAccount) {
|
||||
return nil
|
||||
}
|
||||
|
||||
userID, err := strconv.ParseInt(id, 10, 64)
|
||||
userID, err := identity.ID.ParseInt()
|
||||
if err != nil {
|
||||
s.log.FromContext(ctx).Warn("got invalid identity ID", "id", id, "err", err)
|
||||
s.log.FromContext(ctx).Warn("got invalid identity ID", "id", identity.ID, "err", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -151,14 +148,13 @@ func (s *UserSync) SyncLastSeenHook(ctx context.Context, identity *authn.Identit
|
||||
return nil
|
||||
}
|
||||
|
||||
namespace, id := identity.GetNamespacedID()
|
||||
if namespace != authn.NamespaceUser && namespace != authn.NamespaceServiceAccount {
|
||||
if !identity.ID.IsNamespace(authn.NamespaceUser, authn.NamespaceServiceAccount) {
|
||||
return nil
|
||||
}
|
||||
|
||||
userID, err := authidentity.IntIdentifier(namespace, id)
|
||||
userID, err := identity.ID.ParseInt()
|
||||
if err != nil {
|
||||
s.log.FromContext(ctx).Warn("got invalid identity ID", "id", id, "err", err)
|
||||
s.log.FromContext(ctx).Warn("got invalid identity ID", "id", identity.ID, "err", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -184,14 +180,13 @@ func (s *UserSync) EnableUserHook(ctx context.Context, identity *authn.Identity,
|
||||
return nil
|
||||
}
|
||||
|
||||
namespace, id := identity.GetNamespacedID()
|
||||
if namespace != authn.NamespaceUser {
|
||||
if !identity.ID.IsNamespace(authn.NamespaceUser) {
|
||||
return nil
|
||||
}
|
||||
|
||||
userID, err := authidentity.IntIdentifier(namespace, id)
|
||||
userID, err := identity.ID.ParseInt()
|
||||
if err != nil {
|
||||
s.log.FromContext(ctx).Warn("got invalid identity ID", "id", id, "err", err)
|
||||
s.log.FromContext(ctx).Warn("got invalid identity ID", "id", identity.ID, "err", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user