Skip to content

Commit

Permalink
config: add "omitempty" tags everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Mar 21, 2022
1 parent f1bb53e commit f0e077e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 58 deletions.
14 changes: 7 additions & 7 deletions config/config.go
Expand Up @@ -31,14 +31,14 @@ type Config struct {
IntrospectionAddr string `yaml:"introspection_addr" json:"introspection_addr"`
// Set the logging level.
LogLevel LogLevel `yaml:"log_level" json:"log_level"`
Indexer Indexer `yaml:"indexer" json:"indexer"`
Matcher Matcher `yaml:"matcher" json:"matcher"`
Matchers Matchers `yaml:"matchers" json:"matchers"`
Indexer Indexer `yaml:"indexer,omitempty" json:"indexer,omitempty"`
Matcher Matcher `yaml:"matcher,omitempty" json:"matcher,omitempty"`
Matchers Matchers `yaml:"matchers,omitempty" json:"matchers,omitempty"`
Updaters Updaters `yaml:"updaters,omitempty" json:"updaters,omitempty"`
Notifier Notifier `yaml:"notifier" json:"notifier"`
Auth Auth `yaml:"auth" json:"auth"`
Trace Trace `yaml:"trace" json:"trace"`
Metrics Metrics `yaml:"metrics" json:"metrics"`
Notifier Notifier `yaml:"notifier,omitempty" json:"notifier,omitempty"`
Auth Auth `yaml:"auth,omitempty" json:"auth,omitempty"`
Trace Trace `yaml:"trace,omitempty" json:"trace,omitempty"`
Metrics Metrics `yaml:"metrics,omitempty" json:"metrics,omitempty"`
}

func (c *Config) validate(mode Mode) ([]Warning, error) {
Expand Down
19 changes: 9 additions & 10 deletions config/indexer.go
Expand Up @@ -5,7 +5,7 @@ import "runtime"
// Indexer provides Clair Indexer node configuration
type Indexer struct {
// Scanner allows for passing configuration options to layer scanners.
Scanner ScannerConfig `yaml:"scanner" json:"scanner"`
Scanner ScannerConfig `yaml:"scanner,omitempty" json:"scanner,omitempty"`
// A Postgres connection string.
//
// formats
Expand All @@ -17,28 +17,27 @@ type Indexer struct {
//
// Concurrent Indexers lock on manifest scans to avoid clobbering.
// This value tunes how often a waiting Indexer will poll for the lock.
// TODO: Move to async operating mode
ScanLockRetry int `yaml:"scanlock_retry" json:"scanlock_retry"`
ScanLockRetry int `yaml:"scanlock_retry,omitempty" json:"scanlock_retry,omitempty"`
// A positive values representing quantity.
//
// Indexers will index a Manifest's layers concurrently.
// This value tunes the number of layers an Indexer will scan in parallel.
LayerScanConcurrency int `yaml:"layer_scan_concurrency" json:"layer_scan_concurrency"`
LayerScanConcurrency int `yaml:"layer_scan_concurrency,omitempty" json:"layer_scan_concurrency,omitempty"`
// Rate limits the number if index report creation requests.
//
// Setting this to 0 will attempt to auto-size this value. Setting a
// negative value means "unlimited." The auto-sizing is a multiple of the
// number of available cores.
//
// The API will return a 429 status code if concurrency is exceeded.
IndexReportRequestConcurrency int `yaml:"index_report_request_concurrency" json:"index_report_request_concurrency"`
IndexReportRequestConcurrency int `yaml:"index_report_request_concurrency,omitempty" json:"index_report_request_concurrency,omitempty"`
// A "true" or "false" value
//
// Whether Indexer nodes handle migrations to their database.
Migrations bool `yaml:"migrations" json:"migrations"`
Migrations bool `yaml:"migrations,omitempty" json:"migrations,omitempty"`
// Airgap disables scanners that have signaled they expect to talk to the
// Internet.
Airgap bool `yaml:"airgap" json:"airgap"`
Airgap bool `yaml:"airgap,omitempty" json:"airgap,omitempty"`
}

func (i *Indexer) validate(mode Mode) (ws []Warning, err error) {
Expand Down Expand Up @@ -98,7 +97,7 @@ func (i *Indexer) lint() (ws []Warning, err error) {
// ScannerConfig is the object consulted for configuring the various types of
// scanners.
type ScannerConfig struct {
Package map[string]interface{} `yaml:"package" json:"package"`
Dist map[string]interface{} `yaml:"dist" json:"dist"`
Repo map[string]interface{} `yaml:"repo" json:"repo"`
Package map[string]interface{} `yaml:"package,omitempty" json:"package,omitempty"`
Dist map[string]interface{} `yaml:"dist,omitempty" json:"dist,omitempty"`
Repo map[string]interface{} `yaml:"repo,omitempty" json:"repo,omitempty"`
}
25 changes: 12 additions & 13 deletions config/introspection.go
Expand Up @@ -9,8 +9,8 @@ import "fmt"
// Currently, only "jaeger" is supported.
type Trace struct {
Name string `yaml:"name" json:"name"`
Probability *float64 `yaml:"probability" json:"probability"`
Jaeger Jaeger `yaml:"jaeger" json:"jaeger"`
Probability *float64 `yaml:"probability,omitempty" json:"probability,omitempty"`
Jaeger Jaeger `yaml:"jaeger,omitempty" json:"jaeger,omitempty"`
}

func (t *Trace) lint() ([]Warning, error) {
Expand All @@ -28,17 +28,17 @@ func (t *Trace) lint() ([]Warning, error) {

// Jaeger specific distributed tracing configuration.
type Jaeger struct {
Tags map[string]string `yaml:"tags" json:"tags"`
Tags map[string]string `yaml:"tags,omitempty" json:"tags,omitempty"`
Agent struct {
Endpoint string `yaml:"endpoint" json:"endpoint"`
} `yaml:"agent" json:"agent"`
} `yaml:"agent,omitempty" json:"agent,omitempty"`
Collector struct {
Username *string `yaml:"username" json:"username"`
Password *string `yaml:"password" json:"password"`
Username *string `yaml:"username,omitempty" json:"username,omitempty"`
Password *string `yaml:"password,omitempty" json:"password,omitempty"`
Endpoint string `yaml:"endpoint" json:"endpoint"`
} `yaml:"collector" json:"collector"`
ServiceName string `yaml:"service_name" json:"service_name"`
BufferMax int `yaml:"buffer_max" json:"buffer_max"`
} `yaml:"collector,omitempty" json:"collector,omitempty"`
ServiceName string `yaml:"service_name,omitempty" json:"service_name,omitempty"`
BufferMax int `yaml:"buffer_max,omitempty" json:"buffer_max,omitempty"`
}

// Metrics specifies how to configure Clair's metrics exporting.
Expand All @@ -47,7 +47,7 @@ type Jaeger struct {
//
// Currently, only "prometheus" is supported.
type Metrics struct {
Prometheus Prometheus `yaml:"prometheus" json:"prometheus"`
Prometheus Prometheus `yaml:"prometheus,omitempty" json:"prometheus,omitempty"`
Name string `yaml:"name" json:"name"`
}

Expand All @@ -66,7 +66,6 @@ func (m *Metrics) lint() ([]Warning, error) {

// Prometheus specific metrics configuration.
type Prometheus struct {
// Endpoint is a URL path where
// Prometheus metrics will be hosted.
Endpoint *string `yaml:"endpoint" json:"endpoint"`
// Endpoint is a URL path where Prometheus metrics will be hosted.
Endpoint *string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
}
8 changes: 4 additions & 4 deletions config/matcher.go
Expand Up @@ -23,7 +23,7 @@ type Matcher struct {
// Period controls how often updaters are run.
//
// The default is 30 minutes.
Period time.Duration `yaml:"period" json:"period"`
Period time.Duration `yaml:"period,omitempty" json:"period,omitempty"`
// UpdateRetention controls the number of updates to retain between
// garbage collection periods.
//
Expand All @@ -42,7 +42,7 @@ type Matcher struct {
// database, so see
// https://pkg.go.dev/github.com/jackc/pgx/v4/pgxpool#ParseConfig for more
// information.
MaxConnPool int `yaml:"max_conn_pool" json:"max_conn_pool"`
MaxConnPool int `yaml:"max_conn_pool,omitempty" json:"max_conn_pool,omitempty"`
// CacheAge controls how long clients should be hinted to cache responses
// for.
//
Expand All @@ -52,12 +52,12 @@ type Matcher struct {
// A "true" or "false" value
//
// Whether Matcher nodes handle migrations to their databases.
Migrations bool `yaml:"migrations" json:"migrations"`
Migrations bool `yaml:"migrations,omitempty" json:"migrations,omitempty"`
// DisableUpdaters disables the updater's running of matchers.
//
// This should be toggled on if vulnerabilities are being provided by
// another mechanism.
DisableUpdaters bool `yaml:"disable_updaters" json:"disable_updaters"`
DisableUpdaters bool `yaml:"disable_updaters,omitempty" json:"disable_updaters,omitempty"`
}

func (m *Matcher) validate(mode Mode) ([]Warning, error) {
Expand Down
5 changes: 2 additions & 3 deletions config/matchers.go
Expand Up @@ -4,9 +4,8 @@ package config
type Matchers struct {
// Config holds configuration blocks for MatcherFactories and Matchers,
// keyed by name.
Config map[string]interface{} `yaml:"config" json:"config"`
// A slice of strings representing which
// matchers will be used.
Config map[string]interface{} `yaml:"config,omitempty" json:"config,omitempty"`
// A slice of strings representing which matchers will be used.
//
// If nil all default Matchers will be used
//
Expand Down
36 changes: 18 additions & 18 deletions config/notifier.go
Expand Up @@ -15,11 +15,11 @@ type Notifier struct {
// Only one of the following should be provided in the configuration
//
// Configures the notifier for webhook delivery
Webhook *Webhook `yaml:"webhook" json:"webhook"`
Webhook *Webhook `yaml:"webhook,omitempty" json:"webhook,omitempty"`
// Configures the notifier for AMQP delivery.
AMQP *AMQP `yaml:"amqp" json:"amqp"`
AMQP *AMQP `yaml:"amqp,omitempty" json:"amqp,omitempty"`
// Configures the notifier for STOMP delivery.
STOMP *STOMP `yaml:"stomp" json:"stomp"`
STOMP *STOMP `yaml:"stomp,omitempty" json:"stomp,omitempty"`
// A Postgres connection string.
//
// Formats:
Expand All @@ -42,14 +42,14 @@ type Notifier struct {
// The frequency at which the notifier will query at Matcher for Update Operations.
// If a value smaller then 1 second is provided it will be replaced with the
// default 5 second poll interval.
PollInterval time.Duration `yaml:"poll_interval" json:"poll_interval"`
PollInterval time.Duration `yaml:"poll_interval,omitempty" json:"poll_interval,omitempty"`
// A time.ParseDuration parsable string
//
// The frequency at which the notifier attempt delivery of created or previously failed
// notifications
// If a value smaller then 1 second is provided it will be replaced with the
// default 5 second delivery interval.
DeliveryInterval time.Duration `yaml:"delivery_interval" json:"delivery_interval"`
DeliveryInterval time.Duration `yaml:"delivery_interval,omitempty" json:"delivery_interval,omitempty"`
// DisableSummary disables summarizing vulnerabilities per-manifest.
//
// The default is to summarize any new vulnerabilities to the most severe
Expand All @@ -59,11 +59,11 @@ type Notifier struct {
//
// For a machine-consumption use case, it may be easier to instead have the
// notifier push all the data.
DisableSummary bool `yaml:"disable_summary" json:"disable_summary"`
DisableSummary bool `yaml:"disable_summary,omitempty" json:"disable_summary,omitempty"`
// A "true" or "false" value
//
// Whether Notifier nodes handle migrations to their database.
Migrations bool `yaml:"migrations" json:"migrations"`
Migrations bool `yaml:"migrations,omitempty" json:"migrations,omitempty"`
}

func (n *Notifier) validate(mode Mode) ([]Warning, error) {
Expand Down Expand Up @@ -145,7 +145,7 @@ func (n *Notifier) lint() (ws []Warning, err error) {
// Webhook configures the "webhook" notification mechanism.
type Webhook struct {
// any HTTP headers necessary for the request to Target
Headers http.Header `yaml:"headers" json:"headers"`
Headers http.Header `yaml:"headers,omitempty" json:"headers,omitempty"`
// the URL where our webhook will be delivered
Target string `yaml:"target" json:"target"`
// the callback url where notifications can be received
Expand All @@ -154,7 +154,7 @@ type Webhook struct {
// whether the webhook deliverer will sign out going.
// if true webhooks will be sent with a jwt signed by
// the notifier's private key.
Signed bool `yaml:"signed" json:"signed"`
Signed bool `yaml:"signed,omitempty" json:"signed,omitempty"`
}

// Validate will return a copy of the Config on success.
Expand Down Expand Up @@ -212,9 +212,9 @@ type Exchange struct {
// "headers"
Type string `yaml:"type" json:"type"`
// Whether the exchange survives server restarts
Durable bool `yaml:"durability" json:"durability"`
Durable bool `yaml:"durability,omitempty" json:"durability,omitempty"`
// Whether bound consumers define the lifecycle of the Exchange.
AutoDelete bool `yaml:"auto_delete" json:"auto_delete"`
AutoDelete bool `yaml:"auto_delete,omitempty" json:"auto_delete,omitempty"`
}

func (e *Exchange) validate(_ Mode) ([]Warning, error) {
Expand All @@ -226,7 +226,7 @@ func (e *Exchange) validate(_ Mode) ([]Warning, error) {

// AMQP configures the AMQP notification mechanism.
type AMQP struct {
TLS *TLS `yaml:"tls" json:"tls"`
TLS *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`
// The AMQP exchange notifications will be delivered to.
// A passive declare is performed and if the exchange does not exist
// the declare will fail.
Expand All @@ -248,14 +248,14 @@ type AMQP struct {
// Ignored if Direct is not true
// If 0 or 1 is provided no rollup occurs and each notification is delivered
// separately.
Rollup int `yaml:"rollup" json:"rollup"`
Rollup int `yaml:"rollup,omitempty" json:"rollup,omitempty"`
// AMQPConfigures the AMQP delivery to deliver notifications directly to
// the configured Exchange.
//
// If true "Callback" is ignored.
// If false a notifier.Callback is delivered to the queue and clients
// utilize the pagination API to retrieve.
Direct bool `yaml:"direct" json:"direct"`
Direct bool `yaml:"direct,omitempty" json:"direct,omitempty"`
}

// Validate confirms configuration is valid.
Expand Down Expand Up @@ -319,9 +319,9 @@ type Login struct {
// STOMP configures the STOMP notification mechanism.
type STOMP struct {
// optional tls portion of config
TLS *TLS `yaml:"tls" json:"tls"`
TLS *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`
// optional user login portion of config
Login *Login `yaml:"user" json:"user"`
Login *Login `yaml:"user,omitempty" json:"user,omitempty"`
// The callback url where notifications are retrieved.
Callback string `yaml:"callback" json:"callback"`
// the destination messages will be delivered to
Expand All @@ -337,14 +337,14 @@ type STOMP struct {
// Ignored if Direct is not true
// If 0 or 1 is provided no rollup occurs and each notification is delivered
// separately.
Rollup int `yaml:"rollup" json:"rollup"`
Rollup int `yaml:"rollup,omitempty" json:"rollup,omitempty"`
// Configures the STOMP delivery to deliver notifications directly to
// the configured Destination.
//
// If true "Callback" is ignored.
// If false a notifier.Callback is delivered to the queue and clients
// utilize the pagination API to retrieve.
Direct bool `yaml:"direct" json:"direct"`
Direct bool `yaml:"direct,omitempty" json:"direct,omitempty"`
}

func (c *STOMP) validate(mode Mode) ([]Warning, error) {
Expand Down
5 changes: 2 additions & 3 deletions config/updaters.go
Expand Up @@ -13,9 +13,8 @@ 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]interface{} `yaml:"config" json:"config"`
// A slice of strings representing which
// updaters will be used.
Config map[string]interface{} `yaml:"config,omitempty" json:"config,omitempty"`
// A slice of strings representing which updaters will be used.
//
// If nil all default UpdaterSets will be used
//
Expand Down

0 comments on commit f0e077e

Please sign in to comment.