From ed400f0bbfe4369c29db14503af6ca3123ce96ab Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 12 Jun 2024 19:39:34 +0300 Subject: [PATCH] EntityStore: Use standard user identifier rather than custom version (#89080) user uid string --- pkg/services/store/auth.go | 30 ------------------- pkg/services/store/entity/sqlstash/utils.go | 3 +- .../entity/tests/server_integration_test.go | 3 +- 3 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 pkg/services/store/auth.go diff --git a/pkg/services/store/auth.go b/pkg/services/store/auth.go deleted file mode 100644 index af6fff1551b..00000000000 --- a/pkg/services/store/auth.go +++ /dev/null @@ -1,30 +0,0 @@ -package store - -import ( - "fmt" - - "github.com/grafana/grafana/pkg/services/user" -) - -// Really just spitballing here :) this should hook into a system that can give better display info -func GetUserIDString(user *user.SignedInUser) string { - // TODO: should we check IsDisabled? - // TODO: could we use the NamespacedID.ID() as prefix instead of manually - // setting "anon", "key", etc.? - // TODO: the default unauthenticated user is not anonymous and would be - // returned as `sys:0:` here. We may want to do something special in that - // case - if user == nil { - return "" - } - if user.IsAnonymous { - return "anon" - } - if user.ApiKeyID > 0 { - return fmt.Sprintf("key:%d", user.UserID) - } - if user.IsRealUser() { - return fmt.Sprintf("user:%d:%s", user.UserID, user.Login) - } - return fmt.Sprintf("sys:%d:%s", user.UserID, user.Login) -} diff --git a/pkg/services/store/entity/sqlstash/utils.go b/pkg/services/store/entity/sqlstash/utils.go index 84768b3f06d..ade92f40374 100644 --- a/pkg/services/store/entity/sqlstash/utils.go +++ b/pkg/services/store/entity/sqlstash/utils.go @@ -9,7 +9,6 @@ import ( "text/template" "github.com/grafana/grafana/pkg/infra/appcontext" - "github.com/grafana/grafana/pkg/services/store" "github.com/grafana/grafana/pkg/services/store/entity/db" "github.com/grafana/grafana/pkg/services/store/entity/sqlstash/sqltemplate" ) @@ -33,7 +32,7 @@ func getCurrentUser(ctx context.Context) (string, error) { return "", fmt.Errorf("%w: %w", ErrUserNotFoundInContext, err) } - return store.GetUserIDString(user), nil + return user.GetUID().String(), nil } // ptrOr returns the first non-nil pointer in the list or a new non-nil pointer. diff --git a/pkg/services/store/entity/tests/server_integration_test.go b/pkg/services/store/entity/tests/server_integration_test.go index 44eec13b401..6afe43b3173 100644 --- a/pkg/services/store/entity/tests/server_integration_test.go +++ b/pkg/services/store/entity/tests/server_integration_test.go @@ -11,7 +11,6 @@ import ( "github.com/stretchr/testify/require" "github.com/grafana/grafana/pkg/infra/appcontext" - "github.com/grafana/grafana/pkg/services/store" "github.com/grafana/grafana/pkg/services/store/entity" ) @@ -122,7 +121,7 @@ func TestIntegrationEntityServer(t *testing.T) { testCtx := createTestContext(t) ctx := appcontext.WithUser(testCtx.ctx, testCtx.user) - fakeUser := store.GetUserIDString(testCtx.user) + fakeUser := testCtx.user.GetUID().String() firstVersion := int64(0) group := "test.grafana.app" resource := "jsonobjs"