plugins: New static scanner and validator, with Thema slot support (#53754)
* coremodels: Convert plugin-metadata schema to a coremodel * Newer cuetsy; try quoting field name * Add slot definitions * Start sketching out pfs package * Rerun codegen with fixes, new cuetsy * Catch up dashboard with new cuetsy * Update to go1.18 * Use new vmuxers in thema * Add slot system in Go * Draft finished implementation of pfs * Collapse slot pkg into coremodel dir; add PluginInfo * Add the mux type on top of kernel * Refactor plugin generator for extensibility * Change models.cue package, numerous debugs * Bring new output to parity with old * Remove old plugin generation logic * Misc tweaking * Reintroduce generation of shared schemas * Drop back to go1.17 * Add globbing to tsconfig exclude * Introduce pfs test on existing testdata * Make most existing testdata tests pass with pfs * coremodels: Convert plugin-metadata schema to a coremodel * Newer cuetsy; try quoting field name * Add APIType control concept, regen pluginmeta * Use proper numeric types for schema fields * Make pluginmeta schema follow Go type breakdown * More decomposition into distinct types * Add test case for no plugin.json file * Fix missing ref to #Dependencies * Remove generated TS for pluginmeta * Update dependencies, rearrange go.mod * Regenerate without Model prefix * Use updated thema loader; this is now runnable * Skip app plugin with weird include * Make plugin tree extractor reusable * Split out slot lineage load/validate logic * Add myriad tests for new plugin validation failures * Add test for zip fixtures * One last run of codegen * Proper delinting * Ensure validation order is deterministic * Let there actually be sorting * Undo reliance on builtIn field (#54009) * undo builtIn reliance * fix tests Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:
@@ -108,7 +108,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
ID: "test-datasource",
|
||||
Type: "datasource",
|
||||
Name: "Test",
|
||||
Info: plugins.Info{
|
||||
@@ -131,8 +131,8 @@ func TestLoader_Load(t *testing.T) {
|
||||
Backend: true,
|
||||
State: "alpha",
|
||||
},
|
||||
Module: "plugins/test/module",
|
||||
BaseURL: "public/plugins/test",
|
||||
Module: "plugins/test-datasource/module",
|
||||
BaseURL: "public/plugins/test-datasource",
|
||||
PluginDir: filepath.Join(parentDir, "testdata/valid-v2-signature/plugin/"),
|
||||
Signature: "valid",
|
||||
SignatureType: plugins.GrafanaSignature,
|
||||
@@ -229,7 +229,7 @@ func TestLoader_Load(t *testing.T) {
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
ID: "test-datasource",
|
||||
Type: "datasource",
|
||||
Name: "Test",
|
||||
Info: plugins.Info{
|
||||
@@ -251,8 +251,8 @@ func TestLoader_Load(t *testing.T) {
|
||||
State: plugins.AlphaRelease,
|
||||
},
|
||||
Class: plugins.External,
|
||||
Module: "plugins/test/module",
|
||||
BaseURL: "public/plugins/test",
|
||||
Module: "plugins/test-datasource/module",
|
||||
BaseURL: "public/plugins/test-datasource",
|
||||
PluginDir: filepath.Join(parentDir, "testdata/unsigned-datasource/plugin"),
|
||||
Signature: "unsigned",
|
||||
},
|
||||
@@ -266,8 +266,8 @@ func TestLoader_Load(t *testing.T) {
|
||||
pluginPaths: []string{"../testdata/unsigned-datasource"},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.Error{
|
||||
"test": {
|
||||
PluginID: "test",
|
||||
"test-datasource": {
|
||||
PluginID: "test-datasource",
|
||||
ErrorCode: "signatureMissing",
|
||||
},
|
||||
},
|
||||
@@ -277,13 +277,13 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.External,
|
||||
cfg: &plugins.Cfg{
|
||||
PluginsPath: filepath.Join(parentDir),
|
||||
PluginsAllowUnsigned: []string{"test"},
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
},
|
||||
pluginPaths: []string{"../testdata/unsigned-datasource"},
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
ID: "test-datasource",
|
||||
Type: "datasource",
|
||||
Name: "Test",
|
||||
Info: plugins.Info{
|
||||
@@ -305,8 +305,8 @@ func TestLoader_Load(t *testing.T) {
|
||||
State: plugins.AlphaRelease,
|
||||
},
|
||||
Class: plugins.External,
|
||||
Module: "plugins/test/module",
|
||||
BaseURL: "public/plugins/test",
|
||||
Module: "plugins/test-datasource/module",
|
||||
BaseURL: "public/plugins/test-datasource",
|
||||
PluginDir: filepath.Join(parentDir, "testdata/unsigned-datasource/plugin"),
|
||||
Signature: plugins.SignatureUnsigned,
|
||||
},
|
||||
@@ -321,8 +321,8 @@ func TestLoader_Load(t *testing.T) {
|
||||
pluginPaths: []string{"../testdata/lacking-files"},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.Error{
|
||||
"test": {
|
||||
PluginID: "test",
|
||||
"test-datasource": {
|
||||
PluginID: "test-datasource",
|
||||
ErrorCode: "signatureModified",
|
||||
},
|
||||
},
|
||||
@@ -332,13 +332,13 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.External,
|
||||
cfg: &plugins.Cfg{
|
||||
PluginsPath: filepath.Join(parentDir),
|
||||
PluginsAllowUnsigned: []string{"test"},
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
},
|
||||
pluginPaths: []string{"../testdata/lacking-files"},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.Error{
|
||||
"test": {
|
||||
PluginID: "test",
|
||||
"test-datasource": {
|
||||
PluginID: "test-datasource",
|
||||
ErrorCode: "signatureModified",
|
||||
},
|
||||
},
|
||||
@@ -348,13 +348,13 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.External,
|
||||
cfg: &plugins.Cfg{
|
||||
PluginsPath: filepath.Join(parentDir),
|
||||
PluginsAllowUnsigned: []string{"test"},
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
},
|
||||
pluginPaths: []string{"../testdata/invalid-v2-missing-file"},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.Error{
|
||||
"test": {
|
||||
PluginID: "test",
|
||||
"test-datasource": {
|
||||
PluginID: "test-datasource",
|
||||
ErrorCode: "signatureModified",
|
||||
},
|
||||
},
|
||||
@@ -364,13 +364,13 @@ func TestLoader_Load(t *testing.T) {
|
||||
class: plugins.External,
|
||||
cfg: &plugins.Cfg{
|
||||
PluginsPath: filepath.Join(parentDir),
|
||||
PluginsAllowUnsigned: []string{"test"},
|
||||
PluginsAllowUnsigned: []string{"test-datasource"},
|
||||
},
|
||||
pluginPaths: []string{"../testdata/invalid-v2-extra-file"},
|
||||
want: []*plugins.Plugin{},
|
||||
pluginErrors: map[string]*plugins.Error{
|
||||
"test": {
|
||||
PluginID: "test",
|
||||
"test-datasource": {
|
||||
PluginID: "test-datasource",
|
||||
ErrorCode: "signatureModified",
|
||||
},
|
||||
},
|
||||
@@ -530,7 +530,7 @@ func TestLoader_Load_MultiplePlugins(t *testing.T) {
|
||||
want: []*plugins.Plugin{
|
||||
{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
ID: "test-datasource",
|
||||
Type: "datasource",
|
||||
Name: "Test",
|
||||
Info: plugins.Info{
|
||||
@@ -554,8 +554,8 @@ func TestLoader_Load_MultiplePlugins(t *testing.T) {
|
||||
State: plugins.AlphaRelease,
|
||||
},
|
||||
Class: plugins.External,
|
||||
Module: "plugins/test/module",
|
||||
BaseURL: "public/plugins/test",
|
||||
Module: "plugins/test-datasource/module",
|
||||
BaseURL: "public/plugins/test-datasource",
|
||||
PluginDir: filepath.Join(parentDir, "testdata/valid-v2-pvt-signature/plugin"),
|
||||
Signature: "valid",
|
||||
SignatureType: plugins.PrivateSignature,
|
||||
@@ -621,7 +621,7 @@ func TestLoader_Signature_RootURL(t *testing.T) {
|
||||
expected := []*plugins.Plugin{
|
||||
{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test",
|
||||
ID: "test-datasource",
|
||||
Type: "datasource",
|
||||
Name: "Test",
|
||||
Info: plugins.Info{
|
||||
@@ -643,8 +643,8 @@ func TestLoader_Signature_RootURL(t *testing.T) {
|
||||
Signature: plugins.SignatureValid,
|
||||
SignatureType: plugins.PrivateSignature,
|
||||
SignatureOrg: "Will Browne",
|
||||
Module: "plugins/test/module",
|
||||
BaseURL: "public/plugins/test",
|
||||
Module: "plugins/test-datasource/module",
|
||||
BaseURL: "public/plugins/test-datasource",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -738,7 +738,7 @@ func TestLoader_loadNestedPlugins(t *testing.T) {
|
||||
}
|
||||
parent := &plugins.Plugin{
|
||||
JSONData: plugins.JSONData{
|
||||
ID: "test-ds",
|
||||
ID: "test-datasource",
|
||||
Type: "datasource",
|
||||
Name: "Parent",
|
||||
Info: plugins.Info{
|
||||
@@ -760,8 +760,8 @@ func TestLoader_loadNestedPlugins(t *testing.T) {
|
||||
},
|
||||
Backend: true,
|
||||
},
|
||||
Module: "plugins/test-ds/module",
|
||||
BaseURL: "public/plugins/test-ds",
|
||||
Module: "plugins/test-datasource/module",
|
||||
BaseURL: "public/plugins/test-datasource",
|
||||
PluginDir: filepath.Join(rootDir, "testdata/nested-plugins/parent"),
|
||||
Signature: plugins.SignatureValid,
|
||||
SignatureType: plugins.GrafanaSignature,
|
||||
@@ -1149,23 +1149,23 @@ func Test_validatePluginJSON(t *testing.T) {
|
||||
func Test_setPathsBasedOnApp(t *testing.T) {
|
||||
t.Run("When setting paths based on core plugin on Windows", func(t *testing.T) {
|
||||
child := &plugins.Plugin{
|
||||
PluginDir: "c:\\grafana\\public\\app\\plugins\\app\\testdata\\datasources\\datasource",
|
||||
PluginDir: "c:\\grafana\\public\\app\\plugins\\app\\testdata-app\\datasources\\datasource",
|
||||
}
|
||||
parent := &plugins.Plugin{
|
||||
JSONData: plugins.JSONData{
|
||||
Type: plugins.App,
|
||||
ID: "testdata",
|
||||
ID: "testdata-app",
|
||||
},
|
||||
Class: plugins.Core,
|
||||
PluginDir: "c:\\grafana\\public\\app\\plugins\\app\\testdata",
|
||||
BaseURL: "public/app/plugins/app/testdata",
|
||||
PluginDir: "c:\\grafana\\public\\app\\plugins\\app\\testdata-app",
|
||||
BaseURL: "public/app/plugins/app/testdata-app",
|
||||
}
|
||||
|
||||
configureAppChildOPlugin(parent, child)
|
||||
|
||||
assert.Equal(t, "app/plugins/app/testdata/datasources/datasource/module", child.Module)
|
||||
assert.Equal(t, "testdata", child.IncludedInAppID)
|
||||
assert.Equal(t, "public/app/plugins/app/testdata", child.BaseURL)
|
||||
assert.Equal(t, "app/plugins/app/testdata-app/datasources/datasource/module", child.Module)
|
||||
assert.Equal(t, "testdata-app", child.IncludedInAppID)
|
||||
assert.Equal(t, "public/app/plugins/app/testdata-app", child.BaseURL)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user