fix(tools.custom_builder): Error out for unknown plugins in configuration (#13563)

This commit is contained in:
Sven Rebhan 2023-07-07 15:45:18 +02:00 committed by GitHub
parent 0b1bd42ad2
commit bfc5a6a084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -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 {

View File

@ -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()
}