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:
Selene
2025-01-10 22:43:40 +02:00
committed by GitHub
parent c9d22f06c3
commit 9e5fd78b52
17 changed files with 90 additions and 191 deletions
+10 -3
View File
@@ -2,8 +2,6 @@ package auth
import (
"context"
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
)
type ExternalService struct {
@@ -12,8 +10,17 @@ type ExternalService struct {
PrivateKey string `json:"privateKey"`
}
type IAM struct {
Permissions []Permission `json:"permissions,omitempty"`
}
type Permission struct {
Action string `json:"action"`
Scope string `json:"scope"`
}
type ExternalServiceRegistry interface {
HasExternalService(ctx context.Context, pluginID string) (bool, error)
RegisterExternalService(ctx context.Context, pluginID string, pType pfs.Type, svc *pfs.IAM) (*ExternalService, error)
RegisterExternalService(ctx context.Context, pluginID string, pType string, svc *IAM) (*ExternalService, error)
RemoveExternalService(ctx context.Context, pluginID string) error
}
+1 -22
View File
@@ -1,38 +1,17 @@
package pfs
type Type string
// Defines values for Type.
const (
TypeApp Type = "app"
TypeDatasource Type = "datasource"
TypePanel Type = "panel"
TypeRenderer Type = "renderer"
TypeSecretsmanager Type = "secretsmanager"
)
type PluginDef struct {
Id string
Name string
Backend *bool
Type Type
Type string
Info Info
IAM IAM
}
type Info struct {
Version *string
}
type IAM struct {
Permissions []Permission `json:"permissions,omitempty"`
}
type Permission struct {
Action string `json:"action"`
Scope *string `json:"scope,omitempty"`
}
func (pd PluginDef) Validate() error {
if pd.Id == "" || pd.Name == "" || pd.Type == "" {
return ErrInvalidRootFile
+1 -2
View File
@@ -14,7 +14,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/log"
"github.com/grafana/grafana/pkg/plugins/repo"
"github.com/grafana/grafana/pkg/plugins/storage"
@@ -517,7 +516,7 @@ func (f *FakeAuthService) HasExternalService(ctx context.Context, pluginID strin
return f.Result != nil, nil
}
func (f *FakeAuthService) RegisterExternalService(ctx context.Context, pluginID string, pType pfs.Type, svc *pfs.IAM) (*auth.ExternalService, error) {
func (f *FakeAuthService) RegisterExternalService(ctx context.Context, pluginID string, pType string, svc *auth.IAM) (*auth.ExternalService, error) {
return f.Result, nil
}
+1 -2
View File
@@ -18,7 +18,6 @@ import (
"github.com/grafana/grafana/pkg/plugins/backendplugin"
"github.com/grafana/grafana/pkg/plugins/backendplugin/pluginextensionv2"
"github.com/grafana/grafana/pkg/plugins/backendplugin/secretsmanagerplugin"
"github.com/grafana/grafana/pkg/plugins/codegen/pfs"
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/util"
@@ -131,7 +130,7 @@ type JSONData struct {
Executable string `json:"executable,omitempty"`
// App Service Auth Registration
IAM *pfs.IAM `json:"iam,omitempty"`
IAM *auth.IAM `json:"iam,omitempty"`
}
func ReadPluginJSON(reader io.Reader) (JSONData, error) {