mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
4fd3dd41bc
* Add extra fields to OSS types to support enterprise * WIP service accounts * Update public/app/features/api-keys/ApiKeysForm.tsx Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> * Create a service account at the same time as the API key * Use service account credentials when accessing API with APIkey * Throw better error * Use Boolean for "create service account button" * Add GetRole to service, merge RoleDTO and Role structs This patch merges the identical OSS and Enterprise data structures, which improves the code for two reasons: 1. Makes switching between OSS and Enterprise easier 2. Reduces the chance of incompatibilities developing between the same functions in OSS and Enterprise * Start work cloning permissions onto service account * If API key is not linked to a service account, continue login as usual * Fallback to old auth if no service account linked to key * Commented * Add CloneUserToServiceAccount * Update mock.go * Put graphical bits behind a feature toggle * Start adding LinkAPIKeyToServiceAccount * Update pkg/models/user.go Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com> * Update pkg/api/apikey.go Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com> * Update pkg/api/apikey.go Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com> * Finish LinkAPIKeyToServiceAccount * Update comment * Handle api key link error * Update pkg/services/sqlstore/apikey.go Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> * Feature toggle * Update pkg/services/accesscontrol/accesscontrol.go Co-authored-by: Ieva <ieva.vasiljeva@grafana.com> * Not needed (yet) * Better error messages for OSS accesscontrol * Set an invalid user id as default * ServiceAccountId should be string * Re-arrange field names * ServiceAccountId is integer * Update ossaccesscontrol.go * Linter * Remove fronend edits * Remove console log * Update ApiKeysForm.tsx * feat: add serviceaccount deletion * feat: make sure we do not accidently delete serviceaccount * feat: ServiceAccount Type * refactor: userDeletions function * refactor: serviceaccount deletions\ * refactor: error name and removed attribute for userDeletecommand * refactor:: remove serviceaccount type for now * WIP * add mocked function * Remove unnecessary db query, move to right place * Update pkg/services/accesscontrol/mock/mock.go Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> * Update pkg/services/accesscontrol/mock/mock.go Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> * Update pkg/services/accesscontrol/mock/mock.go Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> * Better error messages * Better and correcter error messages * add mocked function * refactor: move function call, add error msg * add IsServiceAccount and fix table * add service accounts package * WIP * WIP * working serviceaccountsapi registration * WIP tests * test * test working * test running for service * moved the error out of the models package * fixed own review * linting errors * Update pkg/services/serviceaccounts/database/database.go Co-authored-by: Jeremy Price <Jeremy.price@grafana.com> * tests running for api * WIP * WIP * removed unused secrets background svc * removed background svc for serviceaccount infavor or wire.go * serviceaccounts manager tests * registering as backend service Co-authored-by: Jeremy Price <jeremy.price@grafana.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com> Co-authored-by: Ieva <ieva.vasiljeva@grafana.com> Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
198 lines
8.1 KiB
Go
198 lines
8.1 KiB
Go
//go:build wireinject
|
|
// +build wireinject
|
|
|
|
package server
|
|
|
|
import (
|
|
"github.com/google/wire"
|
|
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
|
"github.com/grafana/grafana/pkg/api"
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/expr"
|
|
"github.com/grafana/grafana/pkg/infra/httpclient"
|
|
"github.com/grafana/grafana/pkg/infra/httpclient/httpclientprovider"
|
|
"github.com/grafana/grafana/pkg/infra/kvstore"
|
|
"github.com/grafana/grafana/pkg/infra/localcache"
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
|
"github.com/grafana/grafana/pkg/infra/remotecache"
|
|
"github.com/grafana/grafana/pkg/infra/serverlock"
|
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
|
"github.com/grafana/grafana/pkg/infra/usagestats"
|
|
uss "github.com/grafana/grafana/pkg/infra/usagestats/service"
|
|
"github.com/grafana/grafana/pkg/login/social"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
"github.com/grafana/grafana/pkg/plugins/manager"
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader"
|
|
"github.com/grafana/grafana/pkg/plugins/plugincontext"
|
|
"github.com/grafana/grafana/pkg/plugins/plugindashboards"
|
|
"github.com/grafana/grafana/pkg/services/alerting"
|
|
"github.com/grafana/grafana/pkg/services/auth/jwt"
|
|
"github.com/grafana/grafana/pkg/services/cleanup"
|
|
"github.com/grafana/grafana/pkg/services/contexthandler"
|
|
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
|
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
|
"github.com/grafana/grafana/pkg/services/hooks"
|
|
"github.com/grafana/grafana/pkg/services/libraryelements"
|
|
"github.com/grafana/grafana/pkg/services/librarypanels"
|
|
"github.com/grafana/grafana/pkg/services/live"
|
|
"github.com/grafana/grafana/pkg/services/live/pushhttp"
|
|
"github.com/grafana/grafana/pkg/services/login"
|
|
"github.com/grafana/grafana/pkg/services/login/authinfoservice"
|
|
"github.com/grafana/grafana/pkg/services/login/loginservice"
|
|
"github.com/grafana/grafana/pkg/services/ngalert"
|
|
ngmetrics "github.com/grafana/grafana/pkg/services/ngalert/metrics"
|
|
"github.com/grafana/grafana/pkg/services/notifications"
|
|
"github.com/grafana/grafana/pkg/services/oauthtoken"
|
|
"github.com/grafana/grafana/pkg/services/pluginsettings"
|
|
"github.com/grafana/grafana/pkg/services/quota"
|
|
"github.com/grafana/grafana/pkg/services/rendering"
|
|
"github.com/grafana/grafana/pkg/services/schemaloader"
|
|
"github.com/grafana/grafana/pkg/services/search"
|
|
"github.com/grafana/grafana/pkg/services/secrets"
|
|
secretsDatabase "github.com/grafana/grafana/pkg/services/secrets/database"
|
|
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
|
serviceaccountsmanager "github.com/grafana/grafana/pkg/services/serviceaccounts/manager"
|
|
"github.com/grafana/grafana/pkg/services/shorturls"
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
"github.com/grafana/grafana/pkg/services/updatechecker"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/grafana/grafana/pkg/tsdb/azuremonitor"
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudmonitoring"
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch"
|
|
"github.com/grafana/grafana/pkg/tsdb/elasticsearch"
|
|
"github.com/grafana/grafana/pkg/tsdb/grafanads"
|
|
"github.com/grafana/grafana/pkg/tsdb/graphite"
|
|
"github.com/grafana/grafana/pkg/tsdb/influxdb"
|
|
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
|
legacydataservice "github.com/grafana/grafana/pkg/tsdb/legacydata/service"
|
|
"github.com/grafana/grafana/pkg/tsdb/loki"
|
|
"github.com/grafana/grafana/pkg/tsdb/mssql"
|
|
"github.com/grafana/grafana/pkg/tsdb/mysql"
|
|
"github.com/grafana/grafana/pkg/tsdb/opentsdb"
|
|
"github.com/grafana/grafana/pkg/tsdb/postgres"
|
|
"github.com/grafana/grafana/pkg/tsdb/prometheus"
|
|
"github.com/grafana/grafana/pkg/tsdb/tempo"
|
|
"github.com/grafana/grafana/pkg/tsdb/testdatasource"
|
|
)
|
|
|
|
var wireBasicSet = wire.NewSet(
|
|
legacydataservice.ProvideService,
|
|
wire.Bind(new(legacydata.RequestHandler), new(*legacydataservice.Service)),
|
|
alerting.ProvideAlertEngine,
|
|
wire.Bind(new(alerting.UsageStatsQuerier), new(*alerting.AlertEngine)),
|
|
setting.NewCfgFromArgs,
|
|
New,
|
|
api.ProvideHTTPServer,
|
|
bus.ProvideBus,
|
|
wire.Bind(new(bus.Bus), new(*bus.InProcBus)),
|
|
rendering.ProvideService,
|
|
wire.Bind(new(rendering.Service), new(*rendering.RenderingService)),
|
|
routing.ProvideRegister,
|
|
wire.Bind(new(routing.RouteRegister), new(*routing.RouteRegisterImpl)),
|
|
hooks.ProvideService,
|
|
kvstore.ProvideService,
|
|
localcache.ProvideService,
|
|
updatechecker.ProvideService,
|
|
uss.ProvideService,
|
|
wire.Bind(new(usagestats.Service), new(*uss.UsageStats)),
|
|
manager.ProvideService,
|
|
wire.Bind(new(plugins.Client), new(*manager.PluginManager)),
|
|
wire.Bind(new(plugins.Store), new(*manager.PluginManager)),
|
|
wire.Bind(new(plugins.CoreBackendRegistrar), new(*manager.PluginManager)),
|
|
wire.Bind(new(plugins.StaticRouteResolver), new(*manager.PluginManager)),
|
|
wire.Bind(new(plugins.PluginDashboardManager), new(*manager.PluginManager)),
|
|
wire.Bind(new(plugins.RendererManager), new(*manager.PluginManager)),
|
|
loader.ProvideService,
|
|
wire.Bind(new(plugins.Loader), new(*loader.Loader)),
|
|
wire.Bind(new(plugins.ErrorResolver), new(*loader.Loader)),
|
|
cloudwatch.ProvideService,
|
|
cloudwatch.ProvideLogsService,
|
|
cloudmonitoring.ProvideService,
|
|
azuremonitor.ProvideService,
|
|
postgres.ProvideService,
|
|
mysql.ProvideService,
|
|
mssql.ProvideService,
|
|
httpclientprovider.New,
|
|
wire.Bind(new(httpclient.Provider), new(*sdkhttpclient.Provider)),
|
|
serverlock.ProvideService,
|
|
cleanup.ProvideService,
|
|
shorturls.ProvideService,
|
|
wire.Bind(new(shorturls.Service), new(*shorturls.ShortURLService)),
|
|
quota.ProvideService,
|
|
remotecache.ProvideService,
|
|
loginservice.ProvideService,
|
|
wire.Bind(new(login.Service), new(*loginservice.Implementation)),
|
|
authinfoservice.ProvideAuthInfoService,
|
|
wire.Bind(new(login.AuthInfoService), new(*authinfoservice.Implementation)),
|
|
datasourceproxy.ProvideService,
|
|
search.ProvideService,
|
|
live.ProvideService,
|
|
pushhttp.ProvideService,
|
|
plugincontext.ProvideService,
|
|
contexthandler.ProvideService,
|
|
jwt.ProvideService,
|
|
wire.Bind(new(models.JWTService), new(*jwt.AuthService)),
|
|
plugindashboards.ProvideService,
|
|
schemaloader.ProvideService,
|
|
ngalert.ProvideService,
|
|
librarypanels.ProvideService,
|
|
wire.Bind(new(librarypanels.Service), new(*librarypanels.LibraryPanelService)),
|
|
libraryelements.ProvideService,
|
|
wire.Bind(new(libraryelements.Service), new(*libraryelements.LibraryElementService)),
|
|
notifications.ProvideService,
|
|
tracing.ProvideService,
|
|
metrics.ProvideService,
|
|
testdatasource.ProvideService,
|
|
opentsdb.ProvideService,
|
|
social.ProvideService,
|
|
influxdb.ProvideService,
|
|
wire.Bind(new(social.Service), new(*social.SocialService)),
|
|
oauthtoken.ProvideService,
|
|
wire.Bind(new(oauthtoken.OAuthTokenService), new(*oauthtoken.Service)),
|
|
tempo.ProvideService,
|
|
loki.ProvideService,
|
|
graphite.ProvideService,
|
|
prometheus.ProvideService,
|
|
elasticsearch.ProvideService,
|
|
secretsManager.ProvideSecretsService,
|
|
wire.Bind(new(secrets.Service), new(*secretsManager.SecretsService)),
|
|
wire.Bind(new(secrets.ProvidersRegistrar), new(*secretsManager.SecretsService)),
|
|
secretsDatabase.ProvideSecretsStore,
|
|
wire.Bind(new(secrets.Store), new(*secretsDatabase.SecretsStoreImpl)),
|
|
grafanads.ProvideService,
|
|
dashboardsnapshots.ProvideService,
|
|
datasources.ProvideService,
|
|
pluginsettings.ProvideService,
|
|
alerting.ProvideService,
|
|
serviceaccountsmanager.ProvideServiceAccountsService,
|
|
wire.Bind(new(serviceaccounts.Service), new(*serviceaccountsmanager.ServiceAccountsService)),
|
|
expr.ProvideService,
|
|
)
|
|
|
|
var wireSet = wire.NewSet(
|
|
wireBasicSet,
|
|
sqlstore.ProvideService,
|
|
ngmetrics.ProvideService,
|
|
)
|
|
|
|
var wireTestSet = wire.NewSet(
|
|
wireBasicSet,
|
|
ProvideTestEnv,
|
|
sqlstore.ProvideServiceForTests,
|
|
ngmetrics.ProvideServiceForTest,
|
|
)
|
|
|
|
func Initialize(cla setting.CommandLineArgs, opts Options, apiOpts api.ServerOptions) (*Server, error) {
|
|
wire.Build(wireExtsSet)
|
|
return &Server{}, nil
|
|
}
|
|
|
|
func InitializeForTest(cla setting.CommandLineArgs, opts Options, apiOpts api.ServerOptions) (*TestEnv, error) {
|
|
wire.Build(wireExtsTestSet)
|
|
return &TestEnv{Server: &Server{}, SQLStore: &sqlstore.SQLStore{}}, nil
|
|
}
|