mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove apikey store methods from sqlstore (#53197)
* Chore: remove apikey store methods from sqlstore * remove GetAPIKeys * remove GetAllAPIKeys * remove the rest of apikey from sqlstore
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
acDatabase "github.com/grafana/grafana/pkg/services/accesscontrol/database"
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/apikey/apikeyimpl"
|
||||
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
|
||||
"github.com/grafana/grafana/pkg/services/licensing"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
@@ -38,8 +39,9 @@ var (
|
||||
|
||||
func TestServiceAccountsAPI_CreateServiceAccount(t *testing.T) {
|
||||
store := sqlstore.InitTestDB(t)
|
||||
apiKeyService := apikeyimpl.ProvideService(store, store.Cfg)
|
||||
kvStore := kvstore.ProvideService(store)
|
||||
saStore := database.ProvideServiceAccountsStore(store, kvStore)
|
||||
saStore := database.ProvideServiceAccountsStore(store, apiKeyService, kvStore)
|
||||
svcmock := tests.ServiceAccountMock{}
|
||||
|
||||
autoAssignOrg := store.Cfg.AutoAssignOrg
|
||||
@@ -204,7 +206,8 @@ func TestServiceAccountsAPI_CreateServiceAccount(t *testing.T) {
|
||||
func TestServiceAccountsAPI_DeleteServiceAccount(t *testing.T) {
|
||||
store := sqlstore.InitTestDB(t)
|
||||
kvStore := kvstore.ProvideService(store)
|
||||
saStore := database.ProvideServiceAccountsStore(store, kvStore)
|
||||
apiKeyService := apikeyimpl.ProvideService(store, store.Cfg)
|
||||
saStore := database.ProvideServiceAccountsStore(store, apiKeyService, kvStore)
|
||||
svcmock := tests.ServiceAccountMock{}
|
||||
|
||||
var requestResponse = func(server *web.Mux, httpMethod, requestpath string) *httptest.ResponseRecorder {
|
||||
@@ -304,8 +307,9 @@ func setupTestServer(t *testing.T, svc *tests.ServiceAccountMock,
|
||||
|
||||
func TestServiceAccountsAPI_RetrieveServiceAccount(t *testing.T) {
|
||||
store := sqlstore.InitTestDB(t)
|
||||
apiKeyService := apikeyimpl.ProvideService(store, store.Cfg)
|
||||
kvStore := kvstore.ProvideService(store)
|
||||
saStore := database.ProvideServiceAccountsStore(store, kvStore)
|
||||
saStore := database.ProvideServiceAccountsStore(store, apiKeyService, kvStore)
|
||||
svcmock := tests.ServiceAccountMock{}
|
||||
type testRetrieveSATestCase struct {
|
||||
desc string
|
||||
@@ -395,8 +399,9 @@ func newString(s string) *string {
|
||||
|
||||
func TestServiceAccountsAPI_UpdateServiceAccount(t *testing.T) {
|
||||
store := sqlstore.InitTestDB(t)
|
||||
apiKeyService := apikeyimpl.ProvideService(store, store.Cfg)
|
||||
kvStore := kvstore.ProvideService(store)
|
||||
saStore := database.ProvideServiceAccountsStore(store, kvStore)
|
||||
saStore := database.ProvideServiceAccountsStore(store, apiKeyService, kvStore)
|
||||
svcmock := tests.ServiceAccountMock{}
|
||||
type testUpdateSATestCase struct {
|
||||
desc string
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
accesscontrolmock "github.com/grafana/grafana/pkg/services/accesscontrol/mock"
|
||||
"github.com/grafana/grafana/pkg/services/apikey/apikeyimpl"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
|
||||
@@ -51,8 +52,9 @@ func createTokenforSA(t *testing.T, store serviceaccounts.Store, keyName string,
|
||||
|
||||
func TestServiceAccountsAPI_CreateToken(t *testing.T) {
|
||||
store := sqlstore.InitTestDB(t)
|
||||
apiKeyService := apikeyimpl.ProvideService(store, store.Cfg)
|
||||
kvStore := kvstore.ProvideService(store)
|
||||
saStore := database.ProvideServiceAccountsStore(store, kvStore)
|
||||
saStore := database.ProvideServiceAccountsStore(store, apiKeyService, kvStore)
|
||||
svcmock := tests.ServiceAccountMock{}
|
||||
sa := tests.SetupUserServiceAccount(t, store, tests.TestUser{Login: "sa", IsServiceAccount: true})
|
||||
|
||||
@@ -147,7 +149,7 @@ func TestServiceAccountsAPI_CreateToken(t *testing.T) {
|
||||
assert.Equal(t, tc.body["name"], actualBody["name"])
|
||||
|
||||
query := models.GetApiKeyByNameQuery{KeyName: tc.body["name"].(string), OrgId: sa.OrgID}
|
||||
err = store.GetApiKeyByName(context.Background(), &query)
|
||||
err = apiKeyService.GetApiKeyByName(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, sa.ID, *query.Result.ServiceAccountId)
|
||||
@@ -167,9 +169,10 @@ func TestServiceAccountsAPI_CreateToken(t *testing.T) {
|
||||
|
||||
func TestServiceAccountsAPI_DeleteToken(t *testing.T) {
|
||||
store := sqlstore.InitTestDB(t)
|
||||
apiKeyService := apikeyimpl.ProvideService(store, store.Cfg)
|
||||
kvStore := kvstore.ProvideService(store)
|
||||
svcMock := &tests.ServiceAccountMock{}
|
||||
saStore := database.ProvideServiceAccountsStore(store, kvStore)
|
||||
saStore := database.ProvideServiceAccountsStore(store, apiKeyService, kvStore)
|
||||
sa := tests.SetupUserServiceAccount(t, store, tests.TestUser{Login: "sa", IsServiceAccount: true})
|
||||
|
||||
type testCreateSAToken struct {
|
||||
@@ -243,7 +246,7 @@ func TestServiceAccountsAPI_DeleteToken(t *testing.T) {
|
||||
require.Equal(t, tc.expectedCode, actualCode, endpoint, actualBody)
|
||||
|
||||
query := models.GetApiKeyByNameQuery{KeyName: tc.keyName, OrgId: sa.OrgID}
|
||||
err := store.GetApiKeyByName(context.Background(), &query)
|
||||
err := apiKeyService.GetApiKeyByName(context.Background(), &query)
|
||||
if actualCode == http.StatusOK {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user