Skip to content

Commit

Permalink
config: remove yaml.Node in API
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Nov 3, 2021
1 parent eb64aa5 commit 0439169
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
10 changes: 9 additions & 1 deletion cmd/clairctl/export.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -62,7 +63,14 @@ func exportAction(c *cli.Context) error {
}
cfgs := make(map[string]driver.ConfigUnmarshaler, len(cfg.Updaters.Config))
for name, node := range cfg.Updaters.Config {
cfgs[name] = node.Decode
node := node
cfgs[name] = func(v interface{}) error {
b, err := json.Marshal(node)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}
}

tr := http.DefaultTransport.(*http.Transport).Clone()
Expand Down
1 change: 0 additions & 1 deletion cmd/clairctl/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func reportAction(c *cli.Context) error {
close(result)
<-done
return nil

}

func resolveRef(r string) (claircore.Digest, error) {
Expand Down
8 changes: 3 additions & 5 deletions config/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package config

import (
"fmt"

"gopkg.in/yaml.v3"
)

// Indexer provides Clair Indexer node configuration
Expand Down Expand Up @@ -56,7 +54,7 @@ func (i *Indexer) Validate(combo bool) error {
}

type ScannerConfig struct {
Package map[string]yaml.Node `yaml:"package" json:"package"`
Dist map[string]yaml.Node `yaml:"dist" json:"dist"`
Repo map[string]yaml.Node `yaml:"repo" json:"repo"`
Package map[string]interface{} `yaml:"package" json:"package"`
Dist map[string]interface{} `yaml:"dist" json:"dist"`
Repo map[string]interface{} `yaml:"repo" json:"repo"`
}
6 changes: 1 addition & 5 deletions config/matchers.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package config

import (
"gopkg.in/yaml.v3"
)

type Matchers struct {
// Config holds configuration blocks for MatcherFactories and Matchers,
// keyed by name.
Config map[string]yaml.Node `yaml:"config" json:"config"`
Config map[string]interface{} `yaml:"config" json:"config"`
// A slice of strings representing which
// matchers will be used.
//
Expand Down
6 changes: 1 addition & 5 deletions config/updaters.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package config

import (
"gopkg.in/yaml.v3"
)

// Updaters configures updater behavior.
type Updaters struct {
// Filter is a regexp that disallows updaters that do not match from
Expand All @@ -17,7 +13,7 @@ type Updaters struct {
//
// These are defined by the updater implementation and can't be documented
// here. Improving the documentation for these is an open issue.
Config map[string]yaml.Node `yaml:"config" json:"config"`
Config map[string]interface{} `yaml:"config" json:"config"`
// A slice of strings representing which
// updaters will be used.
//
Expand Down
46 changes: 41 additions & 5 deletions initialize/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package initialize

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -123,19 +124,40 @@ func localIndexer(ctx context.Context, cfg *config.Config) (indexer.Service, err
if cfg.Indexer.Scanner.Package != nil {
opts.ScannerConfig.Package = make(map[string]func(interface{}) error, len(cfg.Indexer.Scanner.Package))
for name, node := range cfg.Indexer.Scanner.Package {
opts.ScannerConfig.Package[name] = node.Decode
node := node
opts.ScannerConfig.Package[name] = func(v interface{}) error {
b, err := json.Marshal(node)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}
}
}
if cfg.Indexer.Scanner.Dist != nil {
opts.ScannerConfig.Dist = make(map[string]func(interface{}) error, len(cfg.Indexer.Scanner.Dist))
for name, node := range cfg.Indexer.Scanner.Dist {
opts.ScannerConfig.Dist[name] = node.Decode
node := node
opts.ScannerConfig.Dist[name] = func(v interface{}) error {
b, err := json.Marshal(node)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}
}
}
if cfg.Indexer.Scanner.Repo != nil {
opts.ScannerConfig.Repo = make(map[string]func(interface{}) error, len(cfg.Indexer.Scanner.Repo))
for name, node := range cfg.Indexer.Scanner.Repo {
opts.ScannerConfig.Repo[name] = node.Decode
node := node
opts.ScannerConfig.Repo[name] = func(v interface{}) error {
b, err := json.Marshal(node)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}
}
}
tr := http.DefaultTransport.(*http.Transport).Clone()
Expand Down Expand Up @@ -203,11 +225,25 @@ func localMatcher(ctx context.Context, cfg *config.Config) (matcher.Service, err
}
updaterConfigs := make(map[string]driver.ConfigUnmarshaler)
for name, node := range cfg.Updaters.Config {
updaterConfigs[name] = node.Decode
node := node
updaterConfigs[name] = func(v interface{}) error {
b, err := json.Marshal(node)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}
}
matcherConfigs := make(map[string]driver.MatcherConfigUnmarshaler)
for name, node := range cfg.Matchers.Config {
matcherConfigs[name] = node.Decode
node := node
matcherConfigs[name] = func(v interface{}) error {
b, err := json.Marshal(node)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}
}
s, err := libvuln.New(ctx, &libvuln.Opts{
MaxConnPool: int32(cfg.Matcher.MaxConnPool),
Expand Down

0 comments on commit 0439169

Please sign in to comment.