Skip to content

Commit

Permalink
Documentation: add config reference cross-checking
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 23, 2022
1 parent 9a74ac8 commit 9258a31
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 7 deletions.
52 changes: 45 additions & 7 deletions Documentation/reference/config.md
Expand Up @@ -110,6 +110,14 @@ metrics:
Note: the above just lists every key for completeness. Copy-pasting the above as
a starting point for configuration will result in some options not having their
defaults set normally.
<!---
The following are purposefully omitted. See comments in the config package for
more information.
# `$.tls.root_ca`
# `$.updaters.filter`
# `$.notifier.webhook.signed`
-->

### `$.http_listen_addr`
A string in `<host>:<port>` format where `<host>` can be an empty string.
Expand Down Expand Up @@ -147,6 +155,11 @@ A key file for the TLS certificate. Encryption is not supported on the key.
### `$.indexer`
Indexer provides Clair Indexer node configuration.

#### `$.indexer.airgap`
Boolean.

Disables scanners that have signaled they expect to talk to the Internet.

#### `$.indexer.connstring`
A Postgres connection string.

Expand All @@ -155,6 +168,17 @@ Accepts a format as a url (e.g.,
or a libpq connection string (e.g.,
`user=pqgotest dbname=pqgotest sslmode=verify-full`).

#### `$.indexer.index_report_request_concurrency`
Integer.

Rate limits the number of 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.

#### `$.indexer.scanlock_retry`
A positive integer representing seconds.

Expand All @@ -174,15 +198,29 @@ A boolean value.
Whether Indexer nodes handle migrations to their database.

#### `$.indexer.scanner`
A map with the name of a particular scanner and arbitrary yaml as a value.
Indexer configurations.

Scanner allows for passing configuration options to layer scanners.
The scanner will have this configuration passed to it on construction if
designed to do so.

#### `$.indexer.scanner.dist`
A map with the name of a particular scanner and arbitrary yaml as a value.

#### `$.indexer.scanner.package`
A map with the name of a particular scanner and arbitrary yaml as a value.

#### `$.indexer.scanner.repo`
A map with the name of a particular scanner and arbitrary yaml as a value.

### `$.matcher`
Matcher provides Clair matcher node configuration.

#### `$.matcher.cache_age`
Duration string.

Controls how long clients should be hinted to cache responses for.

#### `$.matcher.connstring`
A Postgres connection string.

Expand Down Expand Up @@ -411,7 +449,7 @@ bool value

Whether the configured queue uses an auto_delete policy.

#### `$.notifier.amqp.exchange.routing_key`
#### `$.notifier.amqp.routing_key`
string value

The name of the routing key each notification will be sent with.
Expand Down Expand Up @@ -500,15 +538,15 @@ string value

The filesystem path where a tls private key can be read.

#### `$.notifier.stomp.tls.user`
Configures login information for connecting to a STOMP broker.
#### `$.notifier.stomp.user`
Configures login details for the STOMP broker.

#### `$.notifier.stomp.tls.login`
#### `$.notifier.stomp.user.login`
string value

The STOMP login to connect with.

#### `$.notifier.stomp.tls.passcode`
#### `$.notifier.stomp.user.passcode`
string value

The STOMP passcode to connect with.
Expand Down Expand Up @@ -581,7 +619,7 @@ An address in `<host>:<post>` syntax where traces can be submitted.
#### `$.trace.jaeger.collector.username`
a string value

#### `$.trace.jaeger.collector.passwordd`
#### `$.trace.jaeger.collector.password`
a string value

#### `$.trace.jaeger.service_name`
Expand Down
74 changes: 74 additions & 0 deletions Documentation/reference_test.go
@@ -0,0 +1,74 @@
package Documentation

import (
"bufio"
"fmt"
"os"
"reflect"
"regexp"
"sort"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/quay/clair/config"
)

func TestConfigReference(t *testing.T) {
f, err := os.Open("reference/config.md")
if err != nil {
t.Fatal(err)
}
defer f.Close()

header := regexp.MustCompile("^#+ `\\$[^`]+`")
var got []string
s := bufio.NewScanner(f)
for s.Scan() {
if header.Match(s.Bytes()) {
got = append(got, strings.Trim(s.Text(), " #`"))
}
}
if err := s.Err(); err != nil {
t.Error(err)
}
var want []string
if err := walk(&want, "$", reflect.TypeOf(config.Config{})); err != nil {
t.Error(err)
}
sort.Strings(want)
sort.Strings(got)
if !cmp.Equal(got, want) {
t.Error(cmp.Diff(got, want))
}
}

type walkFunc func(interface{}) ([]string, error)

func walk(ws *[]string, path string, t reflect.Type) error {
// Dereference the pointer, if this is a pointer.
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
if t.Kind() == reflect.Struct {
for i, lim := 0, t.NumField(); i < lim; i++ {
f := t.Field(i)
var n string
switch t := f.Tag.Get("json"); t {
case "-", "":
continue
default:
if i := strings.IndexByte(t, ','); i != -1 {
t = t[:i]
}
n = t
}
p := fmt.Sprintf(`%s.%s`, path, n)
*ws = append(*ws, p)
if err := walk(ws, p, t.Field(i).Type); err != nil {
return err
}
}
}
return nil
}

0 comments on commit 9258a31

Please sign in to comment.