Codegen: Remove pfs codegen dependency from Grafana codebase (#98840)
* Remove pfs dependency for IAM struct to avoid to import codegen code in main go.mod * Remove pointer * Remove dependency cycle * Update tests
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/auth"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
@@ -521,8 +520,6 @@ func TestLoader_Load(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoader_Load_ExternalRegistration(t *testing.T) {
|
||||
stringPtr := func(s string) *string { return &s }
|
||||
|
||||
t.Run("Load a plugin with service account registration", func(t *testing.T) {
|
||||
cfg := &config.PluginManagementCfg{
|
||||
PluginsAllowUnsigned: []string{"grafana-test-datasource"},
|
||||
@@ -562,11 +559,11 @@ func TestLoader_Load_ExternalRegistration(t *testing.T) {
|
||||
ExposedComponents: []plugins.ExposedComponent{},
|
||||
ExtensionPoints: []plugins.ExtensionPoint{},
|
||||
},
|
||||
IAM: &pfs.IAM{
|
||||
Permissions: []pfs.Permission{
|
||||
IAM: &auth.IAM{
|
||||
Permissions: []auth.Permission{
|
||||
{
|
||||
Action: "read",
|
||||
Scope: stringPtr("datasource"),
|
||||
Scope: "datasource",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/auth"
|
||||
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/initialization"
|
||||
@@ -57,7 +56,7 @@ func (r *ExternalServiceRegistration) Register(ctx context.Context, p *plugins.P
|
||||
|
||||
ctxLogger := r.log.FromContext(ctx)
|
||||
|
||||
s, err := r.externalServiceRegistry.RegisterExternalService(ctx, p.ID, pfs.Type(p.Type), p.IAM)
|
||||
s, err := r.externalServiceRegistry.RegisterExternalService(ctx, p.ID, string(p.Type), p.IAM)
|
||||
if err != nil {
|
||||
ctxLogger.Error("Could not register an external service. Initialization skipped", "pluginId", p.ID, "error", err)
|
||||
span.SetStatus(codes.Error, fmt.Sprintf("could not register external service: %v", err))
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/auth"
|
||||
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
|
||||
"github.com/grafana/grafana/pkg/plugins/config"
|
||||
"github.com/grafana/grafana/pkg/plugins/envvars"
|
||||
"github.com/grafana/grafana/pkg/plugins/manager/fakes"
|
||||
@@ -457,7 +456,7 @@ func TestPluginEnvVarsProvider_authEnvVars(t *testing.T) {
|
||||
p := &plugins.Plugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
IAM: &pfs.IAM{},
|
||||
IAM: &auth.IAM{},
|
||||
},
|
||||
ExternalService: &auth.ExternalService{
|
||||
ClientID: "clientID",
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/plugins/auth"
|
||||
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/extsvcauth"
|
||||
@@ -42,7 +42,7 @@ func (s *Service) HasExternalService(ctx context.Context, pluginID string) (bool
|
||||
}
|
||||
|
||||
// RegisterExternalService is a simplified wrapper around SaveExternalService for the plugin use case.
|
||||
func (s *Service) RegisterExternalService(ctx context.Context, pluginID string, pType pfs.Type, svc *pfs.IAM) (*auth.ExternalService, error) {
|
||||
func (s *Service) RegisterExternalService(ctx context.Context, pluginID string, pType string, svc *auth.IAM) (*auth.ExternalService, error) {
|
||||
ctxLogger := s.log.FromContext(ctx)
|
||||
|
||||
if !s.featureEnabled {
|
||||
@@ -53,7 +53,7 @@ func (s *Service) RegisterExternalService(ctx context.Context, pluginID string,
|
||||
// Datasource plugins can only be enabled
|
||||
enabled := true
|
||||
// App plugins can be disabled
|
||||
if pType == pfs.TypeApp {
|
||||
if pType == string(plugins.TypeApp) {
|
||||
settings, err := s.settingsSvc.GetPluginSettingByPluginID(ctx, &pluginsettings.GetByPluginIDArgs{PluginID: pluginID})
|
||||
if err != nil && !errors.Is(err, pluginsettings.ErrPluginSettingNotFound) {
|
||||
return nil, err
|
||||
@@ -89,16 +89,12 @@ func (s *Service) RegisterExternalService(ctx context.Context, pluginID string,
|
||||
PrivateKey: privateKey}, nil
|
||||
}
|
||||
|
||||
func toAccessControlPermissions(ps []pfs.Permission) []accesscontrol.Permission {
|
||||
func toAccessControlPermissions(ps []auth.Permission) []accesscontrol.Permission {
|
||||
res := make([]accesscontrol.Permission, 0, len(ps))
|
||||
for _, p := range ps {
|
||||
scope := ""
|
||||
if p.Scope != nil {
|
||||
scope = *p.Scope
|
||||
}
|
||||
res = append(res, accesscontrol.Permission{
|
||||
Action: p.Action,
|
||||
Scope: scope,
|
||||
Scope: p.Scope,
|
||||
})
|
||||
}
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user