From bfc5a6a0844244df380bab568e8641aa882c14e0 Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Fri, 7 Jul 2023 15:45:18 +0200 Subject: [PATCH] fix(tools.custom_builder): Error out for unknown plugins in configuration (#13563) --- tools/custom_builder/config.go | 28 ++++++++++++++++++++++++++-- tools/custom_builder/main.go | 5 ++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tools/custom_builder/config.go b/tools/custom_builder/config.go index 5985980ef..fd9e96443 100644 --- a/tools/custom_builder/config.go +++ b/tools/custom_builder/config.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/influxdata/toml" "github.com/influxdata/toml/ast" @@ -57,7 +58,7 @@ func ImportConfigurations(files, dirs []string) (*selection, int, error) { return sel, len(filenames), err } -func (s *selection) Filter(p packageCollection) *packageCollection { +func (s *selection) Filter(p packageCollection) (*packageCollection, error) { enabled := packageCollection{ 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 { diff --git a/tools/custom_builder/main.go b/tools/custom_builder/main.go index 3b0327724..b203c2d11 100644 --- a/tools/custom_builder/main.go +++ b/tools/custom_builder/main.go @@ -116,7 +116,10 @@ func main() { // Process the plugin list with the given config. This will // 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 { enabled.Print() }