Plugins: Remove pkg/services/org and pkg/services/pluginsintegration/pluginerrs dependencies (#115820)

* remove deps from pkg/plugins

* fmt

* lint fix
This commit is contained in:
Will Browne
2026-01-05 14:10:44 +00:00
committed by GitHub
parent b4a65ac5ac
commit 99cabcb8be
19 changed files with 60 additions and 56 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ import (
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/initialization"
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/termination"
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/validation"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs"
"github.com/grafana/grafana/pkg/plugins/pluginerrs"
)
type Loader struct {
+8 -8
View File
@@ -11,6 +11,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/config"
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/bootstrap"
@@ -20,8 +21,7 @@ import (
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/validation"
"github.com/grafana/grafana/pkg/plugins/manager/pluginfakes"
"github.com/grafana/grafana/pkg/plugins/manager/sources"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginerrs"
"github.com/grafana/grafana/pkg/plugins/pluginerrs"
)
var compareOpts = []cmp.Option{cmpopts.IgnoreFields(plugins.Plugin{}, "client", "log", "mu"), fsComparer}
@@ -180,7 +180,7 @@ func TestLoader_Load(t *testing.T) {
Name: "Nginx Connections",
Path: "dashboards/connections.json",
Type: "dashboard",
Role: org.RoleViewer,
Role: identity.RoleViewer,
Action: plugins.ActionAppAccess,
Slug: "nginx-connections",
},
@@ -188,21 +188,21 @@ func TestLoader_Load(t *testing.T) {
Name: "Nginx Memory",
Path: "dashboards/memory.json",
Type: "dashboard",
Role: org.RoleViewer,
Role: identity.RoleViewer,
Action: plugins.ActionAppAccess,
Slug: "nginx-memory",
},
{
Name: "Nginx Panel",
Type: string(plugins.TypePanel),
Role: org.RoleViewer,
Role: identity.RoleViewer,
Action: plugins.ActionAppAccess,
Slug: "nginx-panel",
},
{
Name: "Nginx Datasource",
Type: string(plugins.TypeDataSource),
Role: org.RoleViewer,
Role: identity.RoleViewer,
Action: plugins.ActionAppAccess,
Slug: "nginx-datasource",
},
@@ -413,8 +413,8 @@ func TestLoader_Load(t *testing.T) {
},
},
Includes: []*plugins.Includes{
{Name: "Nginx Memory", Path: "dashboards/memory.json", Type: "dashboard", Role: org.RoleViewer, Action: plugins.ActionAppAccess, Slug: "nginx-memory"},
{Name: "Root Page (react)", Type: "page", Role: org.RoleViewer, Action: plugins.ActionAppAccess, Path: "/a/my-simple-app", DefaultNav: true, AddToNav: true, Slug: "root-page-react"},
{Name: "Nginx Memory", Path: "dashboards/memory.json", Type: "dashboard", Role: identity.RoleViewer, Action: plugins.ActionAppAccess, Slug: "nginx-memory"},
{Name: "Root Page (react)", Type: "page", Role: identity.RoleViewer, Action: plugins.ActionAppAccess, Path: "/a/my-simple-app", DefaultNav: true, AddToNav: true, Slug: "root-page-react"},
},
Extensions: plugins.Extensions{
AddedLinks: []plugins.AddedLink{},
+12 -12
View File
@@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/apimachinery/identity"
)
const (
@@ -148,17 +148,17 @@ type ExtensionsDependencies struct {
}
type Includes struct {
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
Component string `json:"component"`
Role org.RoleType `json:"role"`
Action string `json:"action,omitempty"`
AddToNav bool `json:"addToNav"`
DefaultNav bool `json:"defaultNav"`
Slug string `json:"slug"`
Icon string `json:"icon"`
UID string `json:"uid"`
Name string `json:"name"`
Path string `json:"path"`
Type string `json:"type"`
Component string `json:"component"`
Role identity.RoleType `json:"role"`
Action string `json:"action,omitempty"`
AddToNav bool `json:"addToNav"`
DefaultNav bool `json:"defaultNav"`
Slug string `json:"slug"`
Icon string `json:"icon"`
UID string `json:"uid"`
ID string `json:"-"`
}
+82
View File
@@ -0,0 +1,82 @@
package pluginerrs
import (
"context"
"github.com/grafana/grafana/pkg/plugins"
"github.com/grafana/grafana/pkg/plugins/log"
)
var _ plugins.ErrorResolver = (*Store)(nil)
type Store struct {
errs ErrorTracker
}
func ProvideStore(errs ErrorTracker) *Store {
return &Store{
errs: errs,
}
}
func (s *Store) PluginErrors(ctx context.Context) []*plugins.Error {
errs := s.errs.Errors(ctx)
for _, err := range errs {
err.ErrorCode = err.AsErrorCode()
}
return errs
}
func (s *Store) PluginError(ctx context.Context, pluginID string) *plugins.Error {
err := s.errs.Error(ctx, pluginID)
if err == nil {
return nil
}
err.ErrorCode = err.AsErrorCode()
return err
}
type ErrorRegistry struct {
errs map[string]*plugins.Error
log log.Logger
}
type ErrorTracker interface {
Record(ctx context.Context, err *plugins.Error)
Clear(ctx context.Context, pluginID string)
Errors(ctx context.Context) []*plugins.Error
Error(ctx context.Context, pluginID string) *plugins.Error
}
func ProvideErrorTracker() *ErrorRegistry {
return newErrorRegistry()
}
func newErrorRegistry() *ErrorRegistry {
return &ErrorRegistry{
errs: make(map[string]*plugins.Error),
log: log.New("plugins.errors"),
}
}
func (r *ErrorRegistry) Record(_ context.Context, err *plugins.Error) {
r.errs[err.PluginID] = err
}
func (r *ErrorRegistry) Clear(_ context.Context, pluginID string) {
delete(r.errs, pluginID)
}
func (r *ErrorRegistry) Errors(_ context.Context) []*plugins.Error {
errs := make([]*plugins.Error, 0, len(r.errs))
for _, err := range r.errs {
errs = append(errs, err)
}
return errs
}
func (r *ErrorRegistry) Error(_ context.Context, pluginID string) *plugins.Error {
return r.errs[pluginID]
}
+14 -15
View File
@@ -14,11 +14,11 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/plugins/auth"
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/services/org"
)
var (
@@ -26,7 +26,6 @@ var (
ErrPluginFileRead = errors.New("file could not be read")
ErrUninstallInvalidPluginDir = errors.New("cannot recognize as plugin folder")
ErrInvalidPluginJSON = errors.New("did not find valid type or id properties in plugin.json")
ErrUnsupportedAlias = errors.New("can not set alias in plugin.json")
)
type Plugin struct {
@@ -186,11 +185,11 @@ func ReadPluginJSON(reader io.Reader) (JSONData, error) {
for _, include := range plugin.Includes {
if include.Role == "" {
include.Role = org.RoleViewer
include.Role = identity.RoleViewer
}
// Default to app access for app plugins
if plugin.Type == TypeApp && include.Role == org.RoleViewer && include.Action == "" {
if plugin.Type == TypeApp && include.Role == identity.RoleViewer && include.Action == "" {
include.Action = ActionAppAccess
}
}
@@ -219,17 +218,17 @@ func (d JSONData) DashboardIncludes() []*Includes {
// Route describes a plugin route that is defined in
// the plugin.json file for a plugin.
type Route struct {
Path string `json:"path"`
Method string `json:"method"`
ReqRole org.RoleType `json:"reqRole"`
ReqAction string `json:"reqAction"`
URL string `json:"url"`
URLParams []URLParam `json:"urlParams"`
Headers []Header `json:"headers"`
AuthType string `json:"authType"`
TokenAuth *JWTTokenAuth `json:"tokenAuth"`
JwtTokenAuth *JWTTokenAuth `json:"jwtTokenAuth"`
Body json.RawMessage `json:"body"`
Path string `json:"path"`
Method string `json:"method"`
ReqRole identity.RoleType `json:"reqRole"`
ReqAction string `json:"reqAction"`
URL string `json:"url"`
URLParams []URLParam `json:"urlParams"`
Headers []Header `json:"headers"`
AuthType string `json:"authType"`
TokenAuth *JWTTokenAuth `json:"tokenAuth"`
JwtTokenAuth *JWTTokenAuth `json:"jwtTokenAuth"`
Body json.RawMessage `json:"body"`
}
// Header describes an HTTP header that is forwarded with
+7 -6
View File
@@ -8,8 +8,9 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/grafana/grafana/pkg/services/org"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/apimachinery/identity"
)
func Test_ReadPluginJSON(t *testing.T) {
@@ -73,10 +74,10 @@ func Test_ReadPluginJSON(t *testing.T) {
},
Includes: []*Includes{
{Name: "Nginx Connections", Path: "dashboards/connections.json", Type: "dashboard", Role: org.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Memory", Path: "dashboards/memory.json", Type: "dashboard", Role: org.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Panel", Type: "panel", Role: org.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Datasource", Type: "datasource", Role: org.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Connections", Path: "dashboards/connections.json", Type: "dashboard", Role: identity.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Memory", Path: "dashboards/memory.json", Type: "dashboard", Role: identity.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Panel", Type: "panel", Role: identity.RoleViewer, Action: ActionAppAccess},
{Name: "Nginx Datasource", Type: "datasource", Role: identity.RoleViewer, Action: ActionAppAccess},
},
Backend: false,
},
@@ -126,7 +127,7 @@ func Test_ReadPluginJSON(t *testing.T) {
},
Includes: []*Includes{
{Name: "Pie Charts", Path: "dashboards/demo.json", Type: "dashboard", Role: org.RoleViewer},
{Name: "Pie Charts", Path: "dashboards/demo.json", Type: "dashboard", Role: identity.RoleViewer},
},
},
},