Plugins: Introduce plugin asset provider (#108063)
* introduce plugin asset provider * simply with PR feedback * fix linter
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/auth"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/pluginassets"
|
||||
"github.com/grafana/grafana/pkg/plugins/repo"
|
||||
"github.com/grafana/grafana/pkg/plugins/storage"
|
||||
)
|
||||
@@ -378,6 +379,7 @@ type FakeLicensingService struct {
|
||||
TokenRaw string
|
||||
LicensePath string
|
||||
LicenseAppURL string
|
||||
CDNPrefix string
|
||||
}
|
||||
|
||||
func NewFakeLicensingService() *FakeLicensingService {
|
||||
@@ -400,6 +402,10 @@ func (s *FakeLicensingService) Environment() []string {
|
||||
return []string{fmt.Sprintf("GF_ENTERPRISE_LICENSE_TEXT=%s", s.TokenRaw)}
|
||||
}
|
||||
|
||||
func (s *FakeLicensingService) ContentDeliveryPrefix() string {
|
||||
return s.CDNPrefix
|
||||
}
|
||||
|
||||
type FakeRoleRegistry struct {
|
||||
ExpectedErr error
|
||||
}
|
||||
@@ -665,3 +671,26 @@ func (p *FakeBackendPlugin) Target() backendplugin.Target {
|
||||
func (p *FakeBackendPlugin) Logger() log.Logger {
|
||||
return log.NewTestLogger()
|
||||
}
|
||||
|
||||
type AssetProvider struct {
|
||||
ModuleFunc func(plugin pluginassets.PluginInfo) (string, error)
|
||||
AssetPathFunc func(plugin pluginassets.PluginInfo, assetPath ...string) (string, error)
|
||||
}
|
||||
|
||||
func NewFakeAssetProvider() *AssetProvider {
|
||||
return &AssetProvider{}
|
||||
}
|
||||
|
||||
func (p *AssetProvider) Module(plugin pluginassets.PluginInfo) (string, error) {
|
||||
if p.ModuleFunc != nil {
|
||||
return p.ModuleFunc(plugin)
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *AssetProvider) AssetPath(plugin pluginassets.PluginInfo, assetPath ...string) (string, error) {
|
||||
if p.AssetPathFunc != nil {
|
||||
return p.AssetPathFunc(plugin, assetPath...)
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user