2014-10-27 23:16:19 +00:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
import (
|
2017-02-16 02:57:21 +00:00
|
|
|
"errors"
|
2014-10-27 23:16:19 +00:00
|
|
|
"fmt"
|
2014-12-02 01:32:31 +00:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2015-01-28 23:55:18 +00:00
|
|
|
"net/http"
|
2014-12-17 22:18:58 +00:00
|
|
|
"reflect"
|
2014-10-27 23:16:19 +00:00
|
|
|
"strings"
|
2015-01-28 23:55:18 +00:00
|
|
|
"time"
|
2014-10-27 23:16:19 +00:00
|
|
|
)
|
|
|
|
|
2014-11-04 17:41:32 +00:00
|
|
|
// Configuration is a versioned registry configuration, intended to be provided by a yaml file, and
|
2015-08-17 20:41:50 +00:00
|
|
|
// optionally modified by environment variables.
|
|
|
|
//
|
|
|
|
// Note that yaml field names should never include _ characters, since this is the separator used
|
|
|
|
// in environment variable names.
|
2014-10-27 23:16:19 +00:00
|
|
|
type Configuration struct {
|
2014-11-04 17:41:32 +00:00
|
|
|
// Version is the version which defines the format of the rest of the configuration
|
2014-11-13 01:19:19 +00:00
|
|
|
Version Version `yaml:"version"`
|
2014-11-04 17:41:32 +00:00
|
|
|
|
2015-03-24 03:13:35 +00:00
|
|
|
// Log supports setting various parameters related to the logging
|
|
|
|
// subsystem.
|
|
|
|
Log struct {
|
2016-09-14 00:23:27 +00:00
|
|
|
// AccessLog configures access logging.
|
|
|
|
AccessLog struct {
|
|
|
|
// Disabled disables access logging.
|
|
|
|
Disabled bool `yaml:"disabled,omitempty"`
|
|
|
|
} `yaml:"accesslog,omitempty"`
|
|
|
|
|
2015-03-24 03:13:35 +00:00
|
|
|
// Level is the granularity at which registry operations are logged.
|
2018-08-14 22:23:04 +00:00
|
|
|
Level Loglevel `yaml:"level,omitempty"`
|
2015-03-24 03:13:35 +00:00
|
|
|
|
|
|
|
// Formatter overrides the default formatter with another. Options
|
|
|
|
// include "text", "json" and "logstash".
|
2015-04-08 00:39:20 +00:00
|
|
|
Formatter string `yaml:"formatter,omitempty"`
|
2015-03-25 00:12:04 +00:00
|
|
|
|
|
|
|
// Fields allows users to specify static string fields to include in
|
|
|
|
// the logger context.
|
2015-04-08 00:39:20 +00:00
|
|
|
Fields map[string]interface{} `yaml:"fields,omitempty"`
|
2015-04-17 12:19:20 +00:00
|
|
|
|
2016-06-22 04:40:21 +00:00
|
|
|
// Hooks allows users to configure the log hooks, to enabling the
|
2015-04-17 12:19:20 +00:00
|
|
|
// sequent handling behavior, when defined levels of log message emit.
|
|
|
|
Hooks []LogHook `yaml:"hooks,omitempty"`
|
2015-03-24 03:13:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 22:23:04 +00:00
|
|
|
// Loglevel is the level at which registry operations are logged.
|
|
|
|
//
|
|
|
|
// Deprecated: Use Log.Level instead.
|
2015-04-08 00:39:20 +00:00
|
|
|
Loglevel Loglevel `yaml:"loglevel,omitempty"`
|
2014-11-04 17:41:32 +00:00
|
|
|
|
|
|
|
// Storage is the configuration for the registry's storage driver
|
2014-11-13 01:19:19 +00:00
|
|
|
Storage Storage `yaml:"storage"`
|
2014-12-02 01:32:31 +00:00
|
|
|
|
2014-12-18 20:30:19 +00:00
|
|
|
// Auth allows configuration of various authorization methods that may be
|
|
|
|
// used to gate requests.
|
2015-02-11 00:56:19 +00:00
|
|
|
Auth Auth `yaml:"auth,omitempty"`
|
2014-12-18 20:30:19 +00:00
|
|
|
|
2015-03-03 16:57:52 +00:00
|
|
|
// Middleware lists all middlewares to be used by the registry.
|
2015-03-06 15:45:16 +00:00
|
|
|
Middleware map[string][]Middleware `yaml:"middleware,omitempty"`
|
2015-01-09 01:29:22 +00:00
|
|
|
|
2014-12-13 01:49:06 +00:00
|
|
|
// Reporting is the configuration for error reporting
|
2015-02-11 00:56:19 +00:00
|
|
|
Reporting Reporting `yaml:"reporting,omitempty"`
|
2014-12-13 01:49:06 +00:00
|
|
|
|
2014-12-02 01:32:31 +00:00
|
|
|
// HTTP contains configuration parameters for the registry's http
|
|
|
|
// interface.
|
|
|
|
HTTP struct {
|
|
|
|
// Addr specifies the bind address for the registry instance.
|
2015-02-11 00:56:19 +00:00
|
|
|
Addr string `yaml:"addr,omitempty"`
|
2015-01-05 07:59:29 +00:00
|
|
|
|
2015-05-05 08:25:42 +00:00
|
|
|
// Net specifies the net portion of the bind address. A default empty value means tcp.
|
|
|
|
Net string `yaml:"net,omitempty"`
|
|
|
|
|
2015-09-18 18:03:15 +00:00
|
|
|
// Host specifies an externally-reachable address for the registry, as a fully
|
|
|
|
// qualified URL.
|
|
|
|
Host string `yaml:"host,omitempty"`
|
|
|
|
|
2015-02-24 22:59:01 +00:00
|
|
|
Prefix string `yaml:"prefix,omitempty"`
|
|
|
|
|
2015-01-05 07:59:29 +00:00
|
|
|
// Secret specifies the secret key which HMAC tokens are created with.
|
2015-02-11 00:56:19 +00:00
|
|
|
Secret string `yaml:"secret,omitempty"`
|
2015-02-02 22:38:47 +00:00
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
// RelativeURLs specifies that relative URLs should be returned in
|
|
|
|
// Location headers
|
|
|
|
RelativeURLs bool `yaml:"relativeurls,omitempty"`
|
|
|
|
|
2015-02-02 22:38:47 +00:00
|
|
|
// TLS instructs the http server to listen with a TLS configuration.
|
|
|
|
// This only support simple tls configuration with a cert and key.
|
|
|
|
// Mostly, this is useful for testing situations or simple deployments
|
|
|
|
// that require tls. If more complex configurations are required, use
|
|
|
|
// a proxy or make a proposal to add support here.
|
|
|
|
TLS struct {
|
|
|
|
// Certificate specifies the path to an x509 certificate file to
|
|
|
|
// be used for TLS.
|
2015-02-11 00:56:19 +00:00
|
|
|
Certificate string `yaml:"certificate,omitempty"`
|
2015-02-02 22:38:47 +00:00
|
|
|
|
|
|
|
// Key specifies the path to the x509 key file, which should
|
|
|
|
// contain the private portion for the file specified in
|
|
|
|
// Certificate.
|
2015-02-11 00:56:19 +00:00
|
|
|
Key string `yaml:"key,omitempty"`
|
2015-03-20 15:19:07 +00:00
|
|
|
|
|
|
|
// Specifies the CA certs for client authentication
|
|
|
|
// A file may contain multiple CA certificates encoded as PEM
|
|
|
|
ClientCAs []string `yaml:"clientcas,omitempty"`
|
2016-06-13 18:30:42 +00:00
|
|
|
|
|
|
|
// LetsEncrypt is used to configuration setting up TLS through
|
|
|
|
// Let's Encrypt instead of manually specifying certificate and
|
|
|
|
// key. If a TLS certificate is specified, the Let's Encrypt
|
|
|
|
// section will not be used.
|
|
|
|
LetsEncrypt struct {
|
|
|
|
// CacheFile specifies cache file to use for lets encrypt
|
|
|
|
// certificates and keys.
|
|
|
|
CacheFile string `yaml:"cachefile,omitempty"`
|
|
|
|
|
|
|
|
// Email is the email to use during Let's Encrypt registration
|
|
|
|
Email string `yaml:"email,omitempty"`
|
2018-02-01 20:16:58 +00:00
|
|
|
|
|
|
|
// Hosts specifies the hosts which are allowed to obtain Let's
|
|
|
|
// Encrypt certificates.
|
|
|
|
Hosts []string `yaml:"hosts,omitempty"`
|
2016-06-13 18:30:42 +00:00
|
|
|
} `yaml:"letsencrypt,omitempty"`
|
2015-02-11 00:56:19 +00:00
|
|
|
} `yaml:"tls,omitempty"`
|
2015-01-28 23:45:25 +00:00
|
|
|
|
2015-08-10 21:20:52 +00:00
|
|
|
// Headers is a set of headers to include in HTTP responses. A common
|
|
|
|
// use case for this would be security headers such as
|
|
|
|
// Strict-Transport-Security. The map keys are the header names, and
|
|
|
|
// the values are the associated header payloads.
|
|
|
|
Headers http.Header `yaml:"headers,omitempty"`
|
|
|
|
|
2015-01-28 23:45:25 +00:00
|
|
|
// Debug configures the http debug interface, if specified. This can
|
|
|
|
// include services such as pprof, expvar and other data that should
|
|
|
|
// not be exposed externally. Left disabled by default.
|
|
|
|
Debug struct {
|
|
|
|
// Addr specifies the bind address for the debug server.
|
2015-02-11 00:56:19 +00:00
|
|
|
Addr string `yaml:"addr,omitempty"`
|
2017-11-17 00:43:38 +00:00
|
|
|
// Prometheus configures the Prometheus telemetry endpoint.
|
|
|
|
Prometheus struct {
|
|
|
|
Enabled bool `yaml:"enabled,omitempty"`
|
|
|
|
Path string `yaml:"path,omitempty"`
|
|
|
|
} `yaml:"prometheus,omitempty"`
|
2015-02-11 00:56:19 +00:00
|
|
|
} `yaml:"debug,omitempty"`
|
2016-07-14 19:48:03 +00:00
|
|
|
|
|
|
|
// HTTP2 configuration options
|
|
|
|
HTTP2 struct {
|
2017-02-16 02:57:21 +00:00
|
|
|
// Specifies whether the registry should disallow clients attempting
|
2016-07-14 19:48:03 +00:00
|
|
|
// to connect via http2. If set to true, only http/1.1 is supported.
|
|
|
|
Disabled bool `yaml:"disabled,omitempty"`
|
|
|
|
} `yaml:"http2,omitempty"`
|
2015-02-11 00:56:19 +00:00
|
|
|
} `yaml:"http,omitempty"`
|
2015-01-28 23:55:18 +00:00
|
|
|
|
|
|
|
// Notifications specifies configuration about various endpoint to which
|
|
|
|
// registry events are dispatched.
|
2015-02-11 00:56:19 +00:00
|
|
|
Notifications Notifications `yaml:"notifications,omitempty"`
|
2015-04-01 23:27:24 +00:00
|
|
|
|
|
|
|
// Redis configures the redis pool available to the registry webapp.
|
|
|
|
Redis struct {
|
|
|
|
// Addr specifies the the redis instance available to the application.
|
|
|
|
Addr string `yaml:"addr,omitempty"`
|
|
|
|
|
|
|
|
// Password string to use when making a connection.
|
|
|
|
Password string `yaml:"password,omitempty"`
|
|
|
|
|
|
|
|
// DB specifies the database to connect to on the redis instance.
|
|
|
|
DB int `yaml:"db,omitempty"`
|
|
|
|
|
|
|
|
DialTimeout time.Duration `yaml:"dialtimeout,omitempty"` // timeout for connect
|
|
|
|
ReadTimeout time.Duration `yaml:"readtimeout,omitempty"` // timeout for reads of data
|
|
|
|
WriteTimeout time.Duration `yaml:"writetimeout,omitempty"` // timeout for writes of data
|
|
|
|
|
|
|
|
// Pool configures the behavior of the redis connection pool.
|
|
|
|
Pool struct {
|
|
|
|
// MaxIdle sets the maximum number of idle connections.
|
|
|
|
MaxIdle int `yaml:"maxidle,omitempty"`
|
|
|
|
|
|
|
|
// MaxActive sets the maximum number of connections that should be
|
|
|
|
// opened before blocking a connection request.
|
|
|
|
MaxActive int `yaml:"maxactive,omitempty"`
|
|
|
|
|
|
|
|
// IdleTimeout sets the amount time to wait before closing
|
|
|
|
// inactive connections.
|
|
|
|
IdleTimeout time.Duration `yaml:"idletimeout,omitempty"`
|
|
|
|
} `yaml:"pool,omitempty"`
|
|
|
|
} `yaml:"redis,omitempty"`
|
2015-07-29 18:12:01 +00:00
|
|
|
|
2015-08-19 00:19:46 +00:00
|
|
|
Health Health `yaml:"health,omitempty"`
|
|
|
|
|
2015-07-29 18:12:01 +00:00
|
|
|
Proxy Proxy `yaml:"proxy,omitempty"`
|
2016-02-10 23:20:39 +00:00
|
|
|
|
|
|
|
// Compatibility is used for configurations of working with older or deprecated features.
|
|
|
|
Compatibility struct {
|
|
|
|
// Schema1 configures how schema1 manifests will be handled
|
|
|
|
Schema1 struct {
|
|
|
|
// TrustKey is the signing key to use for adding the signature to
|
|
|
|
// schema1 manifests.
|
|
|
|
TrustKey string `yaml:"signingkeyfile,omitempty"`
|
|
|
|
} `yaml:"schema1,omitempty"`
|
|
|
|
} `yaml:"compatibility,omitempty"`
|
2016-07-08 22:44:52 +00:00
|
|
|
|
|
|
|
// Validation configures validation options for the registry.
|
|
|
|
Validation struct {
|
2016-11-02 14:18:33 +00:00
|
|
|
// Enabled enables the other options in this section. This field is
|
|
|
|
// deprecated in favor of Disabled.
|
2016-07-08 22:44:52 +00:00
|
|
|
Enabled bool `yaml:"enabled,omitempty"`
|
2016-11-02 14:18:33 +00:00
|
|
|
// Disabled disables the other options in this section.
|
|
|
|
Disabled bool `yaml:"disabled,omitempty"`
|
2016-07-08 22:44:52 +00:00
|
|
|
// Manifests configures manifest validation.
|
|
|
|
Manifests struct {
|
|
|
|
// URLs configures validation for URLs in pushed manifests.
|
|
|
|
URLs struct {
|
|
|
|
// Allow specifies regular expressions (https://godoc.org/regexp/syntax)
|
|
|
|
// that URLs in pushed manifests must match.
|
|
|
|
Allow []string `yaml:"allow,omitempty"`
|
|
|
|
// Deny specifies regular expressions (https://godoc.org/regexp/syntax)
|
|
|
|
// that URLs in pushed manifests must not match.
|
|
|
|
Deny []string `yaml:"deny,omitempty"`
|
|
|
|
} `yaml:"urls,omitempty"`
|
|
|
|
} `yaml:"manifests,omitempty"`
|
|
|
|
} `yaml:"validation,omitempty"`
|
2016-11-22 00:36:36 +00:00
|
|
|
|
|
|
|
// Policy configures registry policy options.
|
|
|
|
Policy struct {
|
|
|
|
// Repository configures policies for repositories
|
|
|
|
Repository struct {
|
|
|
|
// Classes is a list of repository classes which the
|
|
|
|
// registry allows content for. This class is matched
|
|
|
|
// against the configuration media type inside uploaded
|
|
|
|
// manifests. When non-empty, the registry will enforce
|
|
|
|
// the class in authorized resources.
|
|
|
|
Classes []string `yaml:"classes"`
|
|
|
|
} `yaml:"repository,omitempty"`
|
|
|
|
} `yaml:"policy,omitempty"`
|
2014-10-27 23:16:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 12:19:20 +00:00
|
|
|
// LogHook is composed of hook Level and Type.
|
|
|
|
// After hooks configuration, it can execute the next handling automatically,
|
|
|
|
// when defined levels of log message emitted.
|
|
|
|
// Example: hook can sending an email notification when error log happens in app.
|
|
|
|
type LogHook struct {
|
|
|
|
// Disable lets user select to enable hook or not.
|
|
|
|
Disabled bool `yaml:"disabled,omitempty"`
|
|
|
|
|
|
|
|
// Type allows user to select which type of hook handler they want.
|
|
|
|
Type string `yaml:"type,omitempty"`
|
|
|
|
|
|
|
|
// Levels set which levels of log message will let hook executed.
|
|
|
|
Levels []string `yaml:"levels,omitempty"`
|
|
|
|
|
2017-02-16 02:57:21 +00:00
|
|
|
// MailOptions allows user to configure email parameters.
|
2015-04-17 12:19:20 +00:00
|
|
|
MailOptions MailOptions `yaml:"options,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MailOptions provides the configuration sections to user, for specific handler.
|
|
|
|
type MailOptions struct {
|
|
|
|
SMTP struct {
|
|
|
|
// Addr defines smtp host address
|
|
|
|
Addr string `yaml:"addr,omitempty"`
|
|
|
|
|
|
|
|
// Username defines user name to smtp host
|
|
|
|
Username string `yaml:"username,omitempty"`
|
|
|
|
|
|
|
|
// Password defines password of login user
|
|
|
|
Password string `yaml:"password,omitempty"`
|
|
|
|
|
2016-06-22 04:40:21 +00:00
|
|
|
// Insecure defines if smtp login skips the secure certification.
|
2015-04-17 12:19:20 +00:00
|
|
|
Insecure bool `yaml:"insecure,omitempty"`
|
|
|
|
} `yaml:"smtp,omitempty"`
|
|
|
|
|
|
|
|
// From defines mail sending address
|
|
|
|
From string `yaml:"from,omitempty"`
|
|
|
|
|
|
|
|
// To defines mail receiving address
|
|
|
|
To []string `yaml:"to,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-08-20 00:57:18 +00:00
|
|
|
// FileChecker is a type of entry in the health section for checking files.
|
2015-08-19 00:19:46 +00:00
|
|
|
type FileChecker struct {
|
2015-08-20 00:57:18 +00:00
|
|
|
// Interval is the duration in between checks
|
2015-08-19 00:19:46 +00:00
|
|
|
Interval time.Duration `yaml:"interval,omitempty"`
|
|
|
|
// File is the path to check
|
|
|
|
File string `yaml:"file,omitempty"`
|
|
|
|
// Threshold is the number of times a check must fail to trigger an
|
|
|
|
// unhealthy state
|
|
|
|
Threshold int `yaml:"threshold,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-08-20 00:57:18 +00:00
|
|
|
// HTTPChecker is a type of entry in the health section for checking HTTP URIs.
|
2015-08-19 00:19:46 +00:00
|
|
|
type HTTPChecker struct {
|
2015-08-20 00:57:18 +00:00
|
|
|
// Timeout is the duration to wait before timing out the HTTP request
|
2016-05-24 17:42:29 +00:00
|
|
|
Timeout time.Duration `yaml:"timeout,omitempty"`
|
2015-08-20 00:57:18 +00:00
|
|
|
// StatusCode is the expected status code
|
|
|
|
StatusCode int
|
|
|
|
// Interval is the duration in between checks
|
2015-08-19 00:19:46 +00:00
|
|
|
Interval time.Duration `yaml:"interval,omitempty"`
|
|
|
|
// URI is the HTTP URI to check
|
|
|
|
URI string `yaml:"uri,omitempty"`
|
2015-08-20 01:23:58 +00:00
|
|
|
// Headers lists static headers that should be added to all requests
|
|
|
|
Headers http.Header `yaml:"headers"`
|
2015-08-19 00:19:46 +00:00
|
|
|
// Threshold is the number of times a check must fail to trigger an
|
|
|
|
// unhealthy state
|
|
|
|
Threshold int `yaml:"threshold,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-08-20 00:57:18 +00:00
|
|
|
// TCPChecker is a type of entry in the health section for checking TCP servers.
|
|
|
|
type TCPChecker struct {
|
|
|
|
// Timeout is the duration to wait before timing out the TCP connection
|
2016-05-24 17:42:29 +00:00
|
|
|
Timeout time.Duration `yaml:"timeout,omitempty"`
|
2015-08-20 00:57:18 +00:00
|
|
|
// Interval is the duration in between checks
|
|
|
|
Interval time.Duration `yaml:"interval,omitempty"`
|
|
|
|
// Addr is the TCP address to check
|
|
|
|
Addr string `yaml:"addr,omitempty"`
|
|
|
|
// Threshold is the number of times a check must fail to trigger an
|
|
|
|
// unhealthy state
|
|
|
|
Threshold int `yaml:"threshold,omitempty"`
|
|
|
|
}
|
|
|
|
|
2015-08-19 00:19:46 +00:00
|
|
|
// Health provides the configuration section for health checks.
|
|
|
|
type Health struct {
|
2015-08-20 00:57:18 +00:00
|
|
|
// FileCheckers is a list of paths to check
|
2015-08-19 00:19:46 +00:00
|
|
|
FileCheckers []FileChecker `yaml:"file,omitempty"`
|
2015-08-20 00:57:18 +00:00
|
|
|
// HTTPCheckers is a list of URIs to check
|
2015-08-19 00:19:46 +00:00
|
|
|
HTTPCheckers []HTTPChecker `yaml:"http,omitempty"`
|
2015-08-20 00:57:18 +00:00
|
|
|
// TCPCheckers is a list of URIs to check
|
|
|
|
TCPCheckers []TCPChecker `yaml:"tcp,omitempty"`
|
2015-08-19 21:12:51 +00:00
|
|
|
// StorageDriver configures a health check on the configured storage
|
|
|
|
// driver
|
|
|
|
StorageDriver struct {
|
|
|
|
// Enabled turns on the health check for the storage driver
|
|
|
|
Enabled bool `yaml:"enabled,omitempty"`
|
2015-08-20 00:57:18 +00:00
|
|
|
// Interval is the duration in between checks
|
2015-08-19 21:12:51 +00:00
|
|
|
Interval time.Duration `yaml:"interval,omitempty"`
|
|
|
|
// Threshold is the number of times a check must fail to trigger an
|
|
|
|
// unhealthy state
|
|
|
|
Threshold int `yaml:"threshold,omitempty"`
|
|
|
|
} `yaml:"storagedriver,omitempty"`
|
2015-08-19 00:19:46 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 23:44:07 +00:00
|
|
|
// v0_1Configuration is a Version 0.1 Configuration struct
|
2014-11-04 17:41:32 +00:00
|
|
|
// This is currently aliased to Configuration, as it is the current version
|
2014-11-17 23:44:07 +00:00
|
|
|
type v0_1Configuration Configuration
|
2014-11-04 17:41:32 +00:00
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface
|
2017-01-20 16:05:33 +00:00
|
|
|
// Unmarshals a string of the form X.Y into a Version, validating that X and Y can represent unsigned integers
|
2014-11-04 17:41:32 +00:00
|
|
|
func (version *Version) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var versionString string
|
|
|
|
err := unmarshal(&versionString)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
newVersion := Version(versionString)
|
|
|
|
if _, err := newVersion.major(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := newVersion.minor(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*version = newVersion
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentVersion is the most recent Version that can be parsed
|
|
|
|
var CurrentVersion = MajorMinorVersion(0, 1)
|
|
|
|
|
|
|
|
// Loglevel is the level at which operations are logged
|
|
|
|
// This can be error, warn, info, or debug
|
|
|
|
type Loglevel string
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Umarshaler interface
|
|
|
|
// Unmarshals a string into a Loglevel, lowercasing the string and validating that it represents a
|
|
|
|
// valid loglevel
|
|
|
|
func (loglevel *Loglevel) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var loglevelString string
|
|
|
|
err := unmarshal(&loglevelString)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
loglevelString = strings.ToLower(loglevelString)
|
|
|
|
switch loglevelString {
|
|
|
|
case "error", "warn", "info", "debug":
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("Invalid loglevel %s Must be one of [error, warn, info, debug]", loglevelString)
|
|
|
|
}
|
|
|
|
|
|
|
|
*loglevel = Loglevel(loglevelString)
|
|
|
|
return nil
|
2014-10-27 23:16:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 20:30:19 +00:00
|
|
|
// Parameters defines a key-value parameters mapping
|
|
|
|
type Parameters map[string]interface{}
|
|
|
|
|
2014-10-30 00:42:23 +00:00
|
|
|
// Storage defines the configuration for registry object storage
|
2014-11-04 17:41:32 +00:00
|
|
|
type Storage map[string]Parameters
|
2014-10-30 00:42:23 +00:00
|
|
|
|
2014-11-04 17:41:32 +00:00
|
|
|
// Type returns the storage driver type, such as filesystem or s3
|
|
|
|
func (storage Storage) Type() string {
|
2015-08-17 20:41:50 +00:00
|
|
|
var storageType []string
|
|
|
|
|
2014-11-04 17:41:32 +00:00
|
|
|
// Return only key in this map
|
|
|
|
for k := range storage {
|
2015-04-02 23:38:01 +00:00
|
|
|
switch k {
|
2015-04-17 01:34:29 +00:00
|
|
|
case "maintenance":
|
|
|
|
// allow configuration of maintenance
|
2015-04-02 23:38:01 +00:00
|
|
|
case "cache":
|
|
|
|
// allow configuration of caching
|
2015-05-27 17:52:22 +00:00
|
|
|
case "delete":
|
|
|
|
// allow configuration of delete
|
2015-07-24 06:16:27 +00:00
|
|
|
case "redirect":
|
|
|
|
// allow configuration of redirect
|
2015-04-02 23:38:01 +00:00
|
|
|
default:
|
2015-08-17 20:41:50 +00:00
|
|
|
storageType = append(storageType, k)
|
2015-04-02 23:38:01 +00:00
|
|
|
}
|
2014-11-04 17:41:32 +00:00
|
|
|
}
|
2015-08-17 20:41:50 +00:00
|
|
|
if len(storageType) > 1 {
|
|
|
|
panic("multiple storage drivers specified in configuration or environment: " + strings.Join(storageType, ", "))
|
|
|
|
}
|
|
|
|
if len(storageType) == 1 {
|
|
|
|
return storageType[0]
|
|
|
|
}
|
2014-11-04 17:41:32 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parameters returns the Parameters map for a Storage configuration
|
|
|
|
func (storage Storage) Parameters() Parameters {
|
|
|
|
return storage[storage.Type()]
|
|
|
|
}
|
|
|
|
|
|
|
|
// setParameter changes the parameter at the provided key to the new value
|
2014-12-18 03:06:55 +00:00
|
|
|
func (storage Storage) setParameter(key string, value interface{}) {
|
2014-11-04 17:41:32 +00:00
|
|
|
storage[storage.Type()][key] = value
|
2014-10-27 23:16:19 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 17:41:32 +00:00
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface
|
|
|
|
// Unmarshals a single item map into a Storage or a string into a Storage type with no parameters
|
|
|
|
func (storage *Storage) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var storageMap map[string]Parameters
|
|
|
|
err := unmarshal(&storageMap)
|
|
|
|
if err == nil {
|
|
|
|
if len(storageMap) > 1 {
|
|
|
|
types := make([]string, 0, len(storageMap))
|
|
|
|
for k := range storageMap {
|
2015-04-02 23:38:01 +00:00
|
|
|
switch k {
|
2015-04-17 01:34:29 +00:00
|
|
|
case "maintenance":
|
|
|
|
// allow for configuration of maintenance
|
2015-04-02 23:38:01 +00:00
|
|
|
case "cache":
|
|
|
|
// allow configuration of caching
|
2015-05-27 17:52:22 +00:00
|
|
|
case "delete":
|
|
|
|
// allow configuration of delete
|
2015-07-24 06:16:27 +00:00
|
|
|
case "redirect":
|
|
|
|
// allow configuration of redirect
|
2015-04-02 23:38:01 +00:00
|
|
|
default:
|
|
|
|
types = append(types, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(types) > 1 {
|
|
|
|
return fmt.Errorf("Must provide exactly one storage type. Provided: %v", types)
|
2014-11-04 17:41:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*storage = storageMap
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var storageType string
|
|
|
|
err = unmarshal(&storageType)
|
|
|
|
if err == nil {
|
|
|
|
*storage = Storage{storageType: Parameters{}}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalYAML implements the yaml.Marshaler interface
|
2014-10-27 23:16:19 +00:00
|
|
|
func (storage Storage) MarshalYAML() (interface{}, error) {
|
2014-11-13 01:19:19 +00:00
|
|
|
if storage.Parameters() == nil {
|
2014-12-18 20:30:19 +00:00
|
|
|
return storage.Type(), nil
|
2014-11-04 17:41:32 +00:00
|
|
|
}
|
|
|
|
return map[string]Parameters(storage), nil
|
2014-10-27 23:16:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 20:30:19 +00:00
|
|
|
// Auth defines the configuration for registry authorization.
|
|
|
|
type Auth map[string]Parameters
|
|
|
|
|
2016-06-08 14:43:28 +00:00
|
|
|
// Type returns the auth type, such as htpasswd or token
|
2014-12-18 20:30:19 +00:00
|
|
|
func (auth Auth) Type() string {
|
|
|
|
// Return only key in this map
|
|
|
|
for k := range auth {
|
|
|
|
return k
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parameters returns the Parameters map for an Auth configuration
|
|
|
|
func (auth Auth) Parameters() Parameters {
|
|
|
|
return auth[auth.Type()]
|
|
|
|
}
|
|
|
|
|
|
|
|
// setParameter changes the parameter at the provided key to the new value
|
|
|
|
func (auth Auth) setParameter(key string, value interface{}) {
|
|
|
|
auth[auth.Type()][key] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface
|
|
|
|
// Unmarshals a single item map into a Storage or a string into a Storage type with no parameters
|
|
|
|
func (auth *Auth) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var m map[string]Parameters
|
|
|
|
err := unmarshal(&m)
|
|
|
|
if err == nil {
|
|
|
|
if len(m) > 1 {
|
|
|
|
types := make([]string, 0, len(m))
|
|
|
|
for k := range m {
|
|
|
|
types = append(types, k)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(stevvooe): May want to change this slightly for
|
|
|
|
// authorization to allow multiple challenges.
|
|
|
|
return fmt.Errorf("must provide exactly one type. Provided: %v", types)
|
|
|
|
|
|
|
|
}
|
|
|
|
*auth = m
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var authType string
|
|
|
|
err = unmarshal(&authType)
|
|
|
|
if err == nil {
|
|
|
|
*auth = Auth{authType: Parameters{}}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalYAML implements the yaml.Marshaler interface
|
|
|
|
func (auth Auth) MarshalYAML() (interface{}, error) {
|
|
|
|
if auth.Parameters() == nil {
|
|
|
|
return auth.Type(), nil
|
|
|
|
}
|
|
|
|
return map[string]Parameters(auth), nil
|
|
|
|
}
|
2014-11-04 17:41:32 +00:00
|
|
|
|
2015-01-28 23:55:18 +00:00
|
|
|
// Notifications configures multiple http endpoints.
|
|
|
|
type Notifications struct {
|
|
|
|
// Endpoints is a list of http configurations for endpoints that
|
|
|
|
// respond to webhook notifications. In the future, we may allow other
|
|
|
|
// kinds of endpoints, such as external queues.
|
2015-02-11 00:56:19 +00:00
|
|
|
Endpoints []Endpoint `yaml:"endpoints,omitempty"`
|
2015-01-28 23:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Endpoint describes the configuration of an http webhook notification
|
|
|
|
// endpoint.
|
|
|
|
type Endpoint struct {
|
2016-09-12 22:07:49 +00:00
|
|
|
Name string `yaml:"name"` // identifies the endpoint in the registry instance.
|
|
|
|
Disabled bool `yaml:"disabled"` // disables the endpoint
|
|
|
|
URL string `yaml:"url"` // post url for the endpoint.
|
|
|
|
Headers http.Header `yaml:"headers"` // static headers that should be added to all requests
|
|
|
|
Timeout time.Duration `yaml:"timeout"` // HTTP timeout
|
|
|
|
Threshold int `yaml:"threshold"` // circuit breaker threshold before backing off on failure
|
|
|
|
Backoff time.Duration `yaml:"backoff"` // backoff duration
|
|
|
|
IgnoredMediaTypes []string `yaml:"ignoredmediatypes"` // target media types to ignore
|
2018-01-18 10:26:54 +00:00
|
|
|
Ignore Ignore `yaml:"ignore"` // ignore event types
|
|
|
|
}
|
|
|
|
|
|
|
|
//Ignore configures mediaTypes and actions of the event, that it won't be propagated
|
|
|
|
type Ignore struct {
|
|
|
|
MediaTypes []string `yaml:"mediatypes"` // target media types to ignore
|
|
|
|
Actions []string `yaml:"actions"` // ignore action types
|
2015-01-28 23:55:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 01:49:06 +00:00
|
|
|
// Reporting defines error reporting methods.
|
|
|
|
type Reporting struct {
|
|
|
|
// Bugsnag configures error reporting for Bugsnag (bugsnag.com).
|
2015-02-11 00:56:19 +00:00
|
|
|
Bugsnag BugsnagReporting `yaml:"bugsnag,omitempty"`
|
2014-12-13 01:49:06 +00:00
|
|
|
// NewRelic configures error reporting for NewRelic (newrelic.com)
|
2015-02-11 00:56:19 +00:00
|
|
|
NewRelic NewRelicReporting `yaml:"newrelic,omitempty"`
|
2014-12-13 02:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BugsnagReporting configures error reporting for Bugsnag (bugsnag.com).
|
|
|
|
type BugsnagReporting struct {
|
|
|
|
// APIKey is the Bugsnag api key.
|
2015-02-11 00:56:19 +00:00
|
|
|
APIKey string `yaml:"apikey,omitempty"`
|
2014-12-13 02:05:37 +00:00
|
|
|
// ReleaseStage tracks where the registry is deployed.
|
|
|
|
// Examples: production, staging, development
|
2015-02-11 00:56:19 +00:00
|
|
|
ReleaseStage string `yaml:"releasestage,omitempty"`
|
2014-12-13 02:05:37 +00:00
|
|
|
// Endpoint is used for specifying an enterprise Bugsnag endpoint.
|
2015-02-11 00:56:19 +00:00
|
|
|
Endpoint string `yaml:"endpoint,omitempty"`
|
2014-12-13 02:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRelicReporting configures error reporting for NewRelic (newrelic.com)
|
|
|
|
type NewRelicReporting struct {
|
|
|
|
// LicenseKey is the NewRelic user license key
|
2015-02-11 00:56:19 +00:00
|
|
|
LicenseKey string `yaml:"licensekey,omitempty"`
|
2015-01-06 18:59:52 +00:00
|
|
|
// Name is the component name of the registry in NewRelic
|
2015-02-11 00:56:19 +00:00
|
|
|
Name string `yaml:"name,omitempty"`
|
2015-04-14 20:16:10 +00:00
|
|
|
// Verbose configures debug output to STDOUT
|
|
|
|
Verbose bool `yaml:"verbose,omitempty"`
|
2014-12-13 01:49:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 16:57:52 +00:00
|
|
|
// Middleware configures named middlewares to be applied at injection points.
|
|
|
|
type Middleware struct {
|
|
|
|
// Name the middleware registers itself as
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
// Flag to disable middleware easily
|
2015-03-09 17:55:52 +00:00
|
|
|
Disabled bool `yaml:"disabled,omitempty"`
|
2015-03-03 16:57:52 +00:00
|
|
|
// Map of parameters that will be passed to the middleware's initialization function
|
|
|
|
Options Parameters `yaml:"options"`
|
2015-01-09 00:55:40 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 18:12:01 +00:00
|
|
|
// Proxy configures the registry as a pull through cache
|
|
|
|
type Proxy struct {
|
|
|
|
// RemoteURL is the URL of the remote registry
|
|
|
|
RemoteURL string `yaml:"remoteurl"`
|
|
|
|
|
|
|
|
// Username of the hub user
|
|
|
|
Username string `yaml:"username"`
|
|
|
|
|
|
|
|
// Password of the hub user
|
|
|
|
Password string `yaml:"password"`
|
|
|
|
}
|
|
|
|
|
2014-10-30 00:42:23 +00:00
|
|
|
// Parse parses an input configuration yaml document into a Configuration struct
|
2014-11-04 17:41:32 +00:00
|
|
|
// This should generally be capable of handling old configuration format versions
|
2014-10-30 00:42:23 +00:00
|
|
|
//
|
2014-11-04 17:41:32 +00:00
|
|
|
// Environment variables may be used to override configuration parameters other than version,
|
|
|
|
// following the scheme below:
|
|
|
|
// Configuration.Abc may be replaced by the value of REGISTRY_ABC,
|
|
|
|
// Configuration.Abc.Xyz may be replaced by the value of REGISTRY_ABC_XYZ, and so forth
|
2014-12-02 01:32:31 +00:00
|
|
|
func Parse(rd io.Reader) (*Configuration, error) {
|
|
|
|
in, err := ioutil.ReadAll(rd)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-12-17 22:18:58 +00:00
|
|
|
p := NewParser("registry", []VersionedParseInfo{
|
|
|
|
{
|
|
|
|
Version: MajorMinorVersion(0, 1),
|
|
|
|
ParseAs: reflect.TypeOf(v0_1Configuration{}),
|
|
|
|
ConversionFunc: func(c interface{}) (interface{}, error) {
|
|
|
|
if v0_1, ok := c.(*v0_1Configuration); ok {
|
2018-08-14 22:23:04 +00:00
|
|
|
if v0_1.Log.Level == Loglevel("") {
|
|
|
|
if v0_1.Loglevel != Loglevel("") {
|
|
|
|
v0_1.Log.Level = v0_1.Loglevel
|
|
|
|
} else {
|
|
|
|
v0_1.Log.Level = Loglevel("info")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v0_1.Loglevel != Loglevel("") {
|
|
|
|
v0_1.Loglevel = Loglevel("")
|
2014-12-17 22:18:58 +00:00
|
|
|
}
|
|
|
|
if v0_1.Storage.Type() == "" {
|
2017-02-16 02:57:21 +00:00
|
|
|
return nil, errors.New("No storage configuration provided")
|
2014-12-17 22:18:58 +00:00
|
|
|
}
|
|
|
|
return (*Configuration)(v0_1), nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("Expected *v0_1Configuration, received %#v", c)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
config := new(Configuration)
|
|
|
|
err = p.Parse(in, config)
|
2014-10-27 23:16:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-12-17 22:18:58 +00:00
|
|
|
return config, nil
|
2014-10-27 23:16:19 +00:00
|
|
|
}
|