fix(tools.custom_builder): Error out for unknown plugins in configuration (#13563)
This commit is contained in:
parent
0b1bd42ad2
commit
bfc5a6a084
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/influxdata/toml"
|
"github.com/influxdata/toml"
|
||||||
"github.com/influxdata/toml/ast"
|
"github.com/influxdata/toml/ast"
|
||||||
|
|
@ -57,7 +58,7 @@ func ImportConfigurations(files, dirs []string) (*selection, int, error) {
|
||||||
return sel, len(filenames), err
|
return sel, len(filenames), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selection) Filter(p packageCollection) *packageCollection {
|
func (s *selection) Filter(p packageCollection) (*packageCollection, error) {
|
||||||
enabled := packageCollection{
|
enabled := packageCollection{
|
||||||
packages: map[string][]packageInfo{},
|
packages: map[string][]packageInfo{},
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +127,30 @@ func (s *selection) Filter(p packageCollection) *packageCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &enabled
|
// Check if all packages in the config were covered
|
||||||
|
available := make(map[string]bool)
|
||||||
|
for category, pkgs := range p.packages {
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
available[category+"."+pkg.Plugin] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var unknown []string
|
||||||
|
for pkg := range s.plugins {
|
||||||
|
if !available[pkg] {
|
||||||
|
unknown = append(unknown, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for pkg := range implicitlyConfigured {
|
||||||
|
if !available[pkg] {
|
||||||
|
unknown = append(unknown, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(unknown) > 0 {
|
||||||
|
return nil, fmt.Errorf("configured but unknown packages %q", strings.Join(unknown, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &enabled, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selection) importFiles(configurations []string) error {
|
func (s *selection) importFiles(configurations []string) error {
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,10 @@ func main() {
|
||||||
|
|
||||||
// Process the plugin list with the given config. This will
|
// Process the plugin list with the given config. This will
|
||||||
// only keep the plugins that adhere to the filtering criteria.
|
// only keep the plugins that adhere to the filtering criteria.
|
||||||
enabled := cfg.Filter(packages)
|
enabled, err := cfg.Filter(packages)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Filtering packages failed: %v", err)
|
||||||
|
}
|
||||||
if !quiet {
|
if !quiet {
|
||||||
enabled.Print()
|
enabled.Print()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue