2022-12-01 12:08:36 -06:00
|
|
|
package pluginsintegration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/wire"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/backendplugin/provider"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/config"
|
2023-01-18 11:02:54 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/licensing"
|
2022-12-01 12:08:36 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/client"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader"
|
2023-01-27 08:08:17 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
|
2022-12-01 12:08:36 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/process"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/store"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/plugincontext"
|
2023-01-27 08:08:17 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/pluginscdn"
|
2022-12-01 12:08:36 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/repo"
|
|
|
|
"github.com/grafana/grafana/pkg/services/oauthtoken"
|
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/clientmiddleware"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WireSet provides a wire.ProviderSet of plugin providers.
|
|
|
|
var WireSet = wire.NewSet(
|
|
|
|
config.ProvideConfig,
|
|
|
|
store.ProvideService,
|
|
|
|
wire.Bind(new(plugins.Store), new(*store.Service)),
|
|
|
|
wire.Bind(new(plugins.RendererManager), new(*store.Service)),
|
|
|
|
wire.Bind(new(plugins.SecretsPluginManager), new(*store.Service)),
|
|
|
|
wire.Bind(new(plugins.StaticRouteResolver), new(*store.Service)),
|
|
|
|
ProvideClientDecorator,
|
|
|
|
wire.Bind(new(plugins.Client), new(*client.Decorator)),
|
|
|
|
process.ProvideService,
|
|
|
|
wire.Bind(new(process.Service), new(*process.Manager)),
|
|
|
|
coreplugin.ProvideCoreRegistry,
|
2023-01-27 08:08:17 -06:00
|
|
|
pluginscdn.ProvideService,
|
|
|
|
assetpath.ProvideService,
|
2022-12-01 12:08:36 -06:00
|
|
|
loader.ProvideService,
|
|
|
|
wire.Bind(new(loader.Service), new(*loader.Loader)),
|
|
|
|
wire.Bind(new(plugins.ErrorResolver), new(*loader.Loader)),
|
|
|
|
manager.ProvideInstaller,
|
|
|
|
wire.Bind(new(plugins.Installer), new(*manager.PluginInstaller)),
|
|
|
|
registry.ProvideService,
|
|
|
|
wire.Bind(new(registry.Service), new(*registry.InMemory)),
|
|
|
|
repo.ProvideService,
|
|
|
|
wire.Bind(new(repo.Service), new(*repo.Manager)),
|
|
|
|
plugincontext.ProvideService,
|
2023-01-18 11:02:54 -06:00
|
|
|
licensing.ProvideLicensing,
|
|
|
|
wire.Bind(new(plugins.Licensing), new(*licensing.Service)),
|
2022-12-01 12:08:36 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// WireExtensionSet provides a wire.ProviderSet of plugin providers that can be
|
|
|
|
// extended.
|
|
|
|
var WireExtensionSet = wire.NewSet(
|
|
|
|
provider.ProvideService,
|
|
|
|
wire.Bind(new(plugins.BackendFactoryProvider), new(*provider.Service)),
|
|
|
|
signature.ProvideOSSAuthorizer,
|
|
|
|
wire.Bind(new(plugins.PluginLoaderAuthorizer), new(*signature.UnsignedPluginAuthorizer)),
|
|
|
|
)
|
|
|
|
|
|
|
|
func ProvideClientDecorator(cfg *setting.Cfg, pCfg *config.Cfg,
|
|
|
|
pluginRegistry registry.Service,
|
|
|
|
oAuthTokenService oauthtoken.OAuthTokenService) (*client.Decorator, error) {
|
|
|
|
return NewClientDecorator(cfg, pCfg, pluginRegistry, oAuthTokenService)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewClientDecorator(cfg *setting.Cfg, pCfg *config.Cfg,
|
|
|
|
pluginRegistry registry.Service,
|
|
|
|
oAuthTokenService oauthtoken.OAuthTokenService) (*client.Decorator, error) {
|
|
|
|
c := client.ProvideService(pluginRegistry, pCfg)
|
|
|
|
middlewares := CreateMiddlewares(cfg, oAuthTokenService)
|
|
|
|
|
|
|
|
return client.NewDecorator(c, middlewares...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateMiddlewares(cfg *setting.Cfg, oAuthTokenService oauthtoken.OAuthTokenService) []plugins.ClientMiddleware {
|
|
|
|
skipCookiesNames := []string{cfg.LoginCookieName}
|
|
|
|
middlewares := []plugins.ClientMiddleware{
|
2022-12-22 04:15:00 -06:00
|
|
|
clientmiddleware.NewTracingHeaderMiddleware(),
|
2022-12-01 12:08:36 -06:00
|
|
|
clientmiddleware.NewClearAuthHeadersMiddleware(),
|
|
|
|
clientmiddleware.NewOAuthTokenMiddleware(oAuthTokenService),
|
|
|
|
clientmiddleware.NewCookiesMiddleware(skipCookiesNames),
|
|
|
|
}
|
|
|
|
|
2022-12-15 08:28:25 -06:00
|
|
|
if cfg.SendUserHeader {
|
|
|
|
middlewares = append(middlewares, clientmiddleware.NewUserHeaderMiddleware())
|
|
|
|
}
|
|
|
|
|
2022-12-21 06:25:58 -06:00
|
|
|
middlewares = append(middlewares, clientmiddleware.NewHTTPClientMiddleware())
|
|
|
|
|
2022-12-01 12:08:36 -06:00
|
|
|
return middlewares
|
|
|
|
}
|