config: add top-level YAML namespace 'clair'

This enables Clair to use YAML configuration files that contain more
than just a Clair configuration.

Fixes #95.
pull/96/head
Jimmy Zelinskie 8 years ago
parent f6ba17dfc7
commit 4fc32d2271

@ -13,8 +13,8 @@
# limitations under the License.
# The values specified here are the default values that Clair uses if no configuration file is specified or if the keys are not defined.
---
database:
clair:
database:
# PostgreSQL Connection string
# http://www.postgresql.org/docs/9.4/static/libpq-connect.html
source:
@ -23,7 +23,7 @@ database:
# Values unlikely to change (e.g. namespaces) are cached in order to save prevent needless roundtrips to the database.
cacheSize: 16384
api:
api:
# API server port
port: 6060
@ -43,16 +43,17 @@ api:
# If you want to easily generate client certificates and CAs, try the following projects:
# https://github.com/coreos/etcd-ca
# https://github.com/cloudflare/cfssl
servername:
cafile:
keyfile:
certfile:
updater:
updater:
# Frequency the database will be updated with vulnerabilities from the default data sources
# The value 0 disables the updater entirely.
interval: 2h
notifier:
notifier:
# Number of attempts before the notification is marked as failed to be sent
attempts: 3
@ -65,8 +66,8 @@ notifier:
# Optional PKI configuration
# If you want to easily generate client certificates and CAs, try the following projects:
# https://github.com/coreos/etcd-ca
# https://github.com/cloudflare/cfssl
# https://github.com/coreos/etcd-ca
servername:
cafile:
keyfile:

@ -23,6 +23,12 @@ import (
"gopkg.in/yaml.v2"
)
// File represents a YAML configuration file that namespaces all Clair
// configuration under the top-level "clair" key.
type File struct {
Clair Config `yaml:"clair"`
}
// Config is the global configuration for an instance of Clair.
type Config struct {
Database *DatabaseConfig
@ -97,11 +103,14 @@ func Load(path string) (config *Config, err error) {
return
}
err = yaml.Unmarshal(d, config)
var cfgFile File
err = yaml.Unmarshal(d, &cfgFile)
if err != nil {
return
}
config = &cfgFile.Clair
// Generate a pagination key if none is provided.
if config.API.PaginationKey == "" {
var key fernet.Key
if err = key.Generate(); err != nil {

Loading…
Cancel
Save