mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Finish linting opts and trust package.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
5572148477
commit
0bd016b1c3
10 changed files with 52 additions and 40 deletions
|
@ -669,7 +669,7 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo
|
|||
if err := system.MkdirAll(trustDir, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
trustService, err := trust.NewTrustStore(trustDir)
|
||||
trustService, err := trust.NewStore(trustDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create trust store: %s", err)
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func mkTestTagStore(root string, t *testing.T) *TagStore {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
trust, err := trust.NewTrustStore(root + "/trust")
|
||||
trust, err := trust.NewStore(root + "/trust")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ packages=(
|
|||
graph/tags
|
||||
image
|
||||
integration-cli
|
||||
opts
|
||||
pkg/archive
|
||||
pkg/broadcastwriter
|
||||
pkg/chrootarchive
|
||||
|
@ -97,6 +98,7 @@ packages=(
|
|||
pkg/version
|
||||
registry
|
||||
runconfig
|
||||
trust
|
||||
utils
|
||||
volume
|
||||
volume/local
|
||||
|
|
|
@ -9,13 +9,13 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// EnvironmentVariableRegexp A regexp to validate correct environment variables
|
||||
// EnvironmentVariableRegexp is a regexp to validate correct environment variables
|
||||
// Environment variables set by the user must have a name consisting solely of
|
||||
// alphabetics, numerics, and underscores - the first of which must not be numeric.
|
||||
EnvironmentVariableRegexp = regexp.MustCompile("^[[:alpha:]_][[:alpha:][:digit:]_]*$")
|
||||
)
|
||||
|
||||
// ParseEnvFile Read in a line delimited file with environment variables enumerated
|
||||
// ParseEnvFile reads a file with environment variables enumerated by lines
|
||||
func ParseEnvFile(filename string) ([]string, error) {
|
||||
fh, err := os.Open(filename)
|
||||
if err != nil {
|
||||
|
|
|
@ -4,4 +4,5 @@ package opts
|
|||
|
||||
import "fmt"
|
||||
|
||||
// DefaultHost constant defines the default host string used by docker on other hosts than Windows
|
||||
var DefaultHost = fmt.Sprintf("unix://%s", DefaultUnixSocket)
|
||||
|
|
|
@ -4,4 +4,5 @@ package opts
|
|||
|
||||
import "fmt"
|
||||
|
||||
// DefaultHost constant defines the default host string used by docker on Windows
|
||||
var DefaultHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort)
|
||||
|
|
10
opts/ip.go
10
opts/ip.go
|
@ -5,12 +5,14 @@ import (
|
|||
"net"
|
||||
)
|
||||
|
||||
// IPOpt type that hold an IP
|
||||
// IPOpt holds an IP. It is used to store values from CLI flags.
|
||||
type IPOpt struct {
|
||||
*net.IP
|
||||
}
|
||||
|
||||
// NewIPOpt returns a new IPOpt from a string of an IP.
|
||||
// NewIPOpt creates a new IPOpt from a reference net.IP and a
|
||||
// string representation of an IP. If the string is not a valid
|
||||
// IP it will fallback to the specified reference.
|
||||
func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt {
|
||||
o := &IPOpt{
|
||||
IP: ref,
|
||||
|
@ -20,7 +22,7 @@ func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt {
|
|||
}
|
||||
|
||||
// Set sets an IPv4 or IPv6 address from a given string. If the given
|
||||
// string is not parsable as an IP address it will return an error.
|
||||
// string is not parsable as an IP address it returns an error.
|
||||
func (o *IPOpt) Set(val string) error {
|
||||
ip := net.ParseIP(val)
|
||||
if ip == nil {
|
||||
|
@ -30,7 +32,7 @@ func (o *IPOpt) Set(val string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// String returns the IP address stored in the IPOpt. If IPOpt is a
|
||||
// String returns the IP address stored in the IPOpt. If stored IP is a
|
||||
// nil pointer, it returns an empty string.
|
||||
func (o *IPOpt) String() string {
|
||||
if *o.IP == nil {
|
||||
|
|
53
opts/opts.go
53
opts/opts.go
|
@ -27,18 +27,19 @@ var (
|
|||
DefaultUnixSocket = "/var/run/docker.sock"
|
||||
)
|
||||
|
||||
// ListOpts type that hold a list of values and a validation function.
|
||||
// ListOpts holds a list of values and a validation function.
|
||||
type ListOpts struct {
|
||||
values *[]string
|
||||
validator ValidatorFctType
|
||||
}
|
||||
|
||||
// NewListOpts Create a new ListOpts with the specified validator.
|
||||
// NewListOpts creates a new ListOpts with the specified validator.
|
||||
func NewListOpts(validator ValidatorFctType) ListOpts {
|
||||
var values []string
|
||||
return *NewListOptsRef(&values, validator)
|
||||
}
|
||||
|
||||
// NewListOptsRef creates a new ListOpts with the specified values and validator.
|
||||
func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
|
||||
return &ListOpts{
|
||||
values: values,
|
||||
|
@ -64,7 +65,7 @@ func (opts *ListOpts) Set(value string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Delete remove the given element from the slice.
|
||||
// Delete removes the specified element from the slice.
|
||||
func (opts *ListOpts) Delete(key string) {
|
||||
for i, k := range *opts.values {
|
||||
if k == key {
|
||||
|
@ -85,13 +86,13 @@ func (opts *ListOpts) GetMap() map[string]struct{} {
|
|||
return ret
|
||||
}
|
||||
|
||||
// GetAll returns the values' slice.
|
||||
// GetAll returns the values of slice.
|
||||
// FIXME: Can we remove this?
|
||||
func (opts *ListOpts) GetAll() []string {
|
||||
return (*opts.values)
|
||||
}
|
||||
|
||||
// Get checks the existence of the given key.
|
||||
// Get checks the existence of the specified key.
|
||||
func (opts *ListOpts) Get(key string) bool {
|
||||
for _, k := range *opts.values {
|
||||
if k == key {
|
||||
|
@ -106,7 +107,7 @@ func (opts *ListOpts) Len() int {
|
|||
return len((*opts.values))
|
||||
}
|
||||
|
||||
//MapOpts type that holds a map of values and a validation function.
|
||||
//MapOpts holds a map of values and a validation function.
|
||||
type MapOpts struct {
|
||||
values map[string]string
|
||||
validator ValidatorFctType
|
||||
|
@ -131,6 +132,7 @@ func (opts *MapOpts) Set(value string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetAll returns the values of MapOpts as a map.
|
||||
func (opts *MapOpts) GetAll() map[string]string {
|
||||
return opts.values
|
||||
}
|
||||
|
@ -139,6 +141,7 @@ func (opts *MapOpts) String() string {
|
|||
return fmt.Sprintf("%v", map[string]string((opts.values)))
|
||||
}
|
||||
|
||||
// NewMapOpts creates a new MapOpts with the specified map of values and a validator.
|
||||
func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts {
|
||||
if values == nil {
|
||||
values = make(map[string]string)
|
||||
|
@ -149,13 +152,13 @@ func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts {
|
|||
}
|
||||
}
|
||||
|
||||
// ValidatorFctType validator that return a validate string and/or an error
|
||||
// ValidatorFctType defines a validator function that returns a validated string and/or an error.
|
||||
type ValidatorFctType func(val string) (string, error)
|
||||
|
||||
// ValidatorFctListType validator that return a validate list of string and/or an error
|
||||
// ValidatorFctListType defines a validator function that returns a validated list of string and/or an error
|
||||
type ValidatorFctListType func(val string) ([]string, error)
|
||||
|
||||
// ValidateAttach Validates that the specified string is a valid attach option.
|
||||
// ValidateAttach validates that the specified string is a valid attach option.
|
||||
func ValidateAttach(val string) (string, error) {
|
||||
s := strings.ToLower(val)
|
||||
for _, str := range []string{"stdin", "stdout", "stderr"} {
|
||||
|
@ -166,7 +169,7 @@ func ValidateAttach(val string) (string, error) {
|
|||
return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR")
|
||||
}
|
||||
|
||||
// ValidateLink Validates that the specified string has a valid link format (containerName:alias).
|
||||
// ValidateLink validates that the specified string has a valid link format (containerName:alias).
|
||||
func ValidateLink(val string) (string, error) {
|
||||
if _, _, err := parsers.ParseLink(val); err != nil {
|
||||
return val, err
|
||||
|
@ -194,18 +197,18 @@ func ValidDeviceMode(mode string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// ValidateDevice Validate a path for devices
|
||||
// ValidateDevice validates a path for devices
|
||||
// It will make sure 'val' is in the form:
|
||||
// [host-dir:]container-path[:mode]
|
||||
// It will also validate the device mode.
|
||||
// It also validates the device mode.
|
||||
func ValidateDevice(val string) (string, error) {
|
||||
return validatePath(val, ValidDeviceMode)
|
||||
}
|
||||
|
||||
// ValidatePath Validate a path for volumes
|
||||
// ValidatePath validates a path for volumes
|
||||
// It will make sure 'val' is in the form:
|
||||
// [host-dir:]container-path[:rw|ro]
|
||||
// It will also validate the mount mode.
|
||||
// It also validates the mount mode.
|
||||
func ValidatePath(val string) (string, error) {
|
||||
return validatePath(val, volume.ValidMountMode)
|
||||
}
|
||||
|
@ -250,8 +253,8 @@ func validatePath(val string, validator func(string) bool) (string, error) {
|
|||
return val, nil
|
||||
}
|
||||
|
||||
// ValidateEnv Validate an environment variable and returns it
|
||||
// It will use EnvironmentVariableRegexp to ensure the name of the environment variable is valid.
|
||||
// ValidateEnv validates an environment variable and returns it.
|
||||
// It uses EnvironmentVariableRegexp to ensure the name of the environment variable is valid.
|
||||
// If no value is specified, it returns the current value using os.Getenv.
|
||||
func ValidateEnv(val string) (string, error) {
|
||||
arr := strings.Split(val, "=")
|
||||
|
@ -267,7 +270,7 @@ func ValidateEnv(val string) (string, error) {
|
|||
return fmt.Sprintf("%s=%s", val, os.Getenv(val)), nil
|
||||
}
|
||||
|
||||
// ValidateIPAddress Validates an Ip address
|
||||
// ValidateIPAddress validates an Ip address.
|
||||
func ValidateIPAddress(val string) (string, error) {
|
||||
var ip = net.ParseIP(strings.TrimSpace(val))
|
||||
if ip != nil {
|
||||
|
@ -276,7 +279,7 @@ func ValidateIPAddress(val string) (string, error) {
|
|||
return "", fmt.Errorf("%s is not an ip address", val)
|
||||
}
|
||||
|
||||
// ValidateMACAddress Validates a MAC address
|
||||
// ValidateMACAddress validates a MAC address.
|
||||
func ValidateMACAddress(val string) (string, error) {
|
||||
_, err := net.ParseMAC(strings.TrimSpace(val))
|
||||
if err != nil {
|
||||
|
@ -285,8 +288,8 @@ func ValidateMACAddress(val string) (string, error) {
|
|||
return val, nil
|
||||
}
|
||||
|
||||
// ValidateDNSSearch Validates domain for resolvconf search configuration.
|
||||
// A zero length domain is represented by .
|
||||
// ValidateDNSSearch validates domain for resolvconf search configuration.
|
||||
// A zero length domain is represented by a dot (.).
|
||||
func ValidateDNSSearch(val string) (string, error) {
|
||||
if val = strings.Trim(val, " "); val == "." {
|
||||
return val, nil
|
||||
|
@ -305,8 +308,8 @@ func validateDomain(val string) (string, error) {
|
|||
return "", fmt.Errorf("%s is not a valid domain", val)
|
||||
}
|
||||
|
||||
// ValidateExtraHost Validate that the given string is a valid extrahost and returns it
|
||||
// ExtraHost are in the form of name:ip where the ip has to be a valid ip (ipv4 or ipv6)
|
||||
// ValidateExtraHost validates that the specified string is a valid extrahost and returns it.
|
||||
// ExtraHost are in the form of name:ip where the ip has to be a valid ip (ipv4 or ipv6).
|
||||
func ValidateExtraHost(val string) (string, error) {
|
||||
// allow for IPv6 addresses in extra hosts by only splitting on first ":"
|
||||
arr := strings.SplitN(val, ":", 2)
|
||||
|
@ -319,8 +322,8 @@ func ValidateExtraHost(val string) (string, error) {
|
|||
return val, nil
|
||||
}
|
||||
|
||||
// ValidateLabel Validate that the given string is a valid label, and returns it
|
||||
// Labels are in the form on key=value
|
||||
// ValidateLabel validates that the specified string is a valid label, and returns it.
|
||||
// Labels are in the form on key=value.
|
||||
func ValidateLabel(val string) (string, error) {
|
||||
if strings.Count(val, "=") < 1 {
|
||||
return "", fmt.Errorf("bad attribute format: %s", val)
|
||||
|
@ -328,7 +331,7 @@ func ValidateLabel(val string) (string, error) {
|
|||
return val, nil
|
||||
}
|
||||
|
||||
// ValidateHost Validate that the given string is a valid host and returns it
|
||||
// ValidateHost validates that the specified string is a valid host and returns it.
|
||||
func ValidateHost(val string) (string, error) {
|
||||
host, err := parsers.ParseHost(DefaultHTTPHost, DefaultUnixSocket, val)
|
||||
if err != nil {
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
"github.com/docker/libtrust"
|
||||
)
|
||||
|
||||
// NotVerifiedError implements the error interface
|
||||
// NotVerifiedError reports a error when doing the key check.
|
||||
// For example if the graph is not verified or the key has expired.
|
||||
type NotVerifiedError string
|
||||
|
||||
func (e NotVerifiedError) Error() string {
|
||||
|
@ -52,7 +53,7 @@ func (t *Store) CheckKey(ns string, key []byte, perm uint16) (bool, error) {
|
|||
}
|
||||
|
||||
// UpdateBase retrieves updated base graphs. This function cannot error, it
|
||||
// should only log errors
|
||||
// should only log errors.
|
||||
func (t *Store) UpdateBase() {
|
||||
t.fetch()
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ import (
|
|||
"github.com/docker/libtrust/trustgraph"
|
||||
)
|
||||
|
||||
// Store defines a TrustStore
|
||||
// Store defines a TrustStore : stores trusted certificates and permissions
|
||||
// which are used to verify the signature keys on manifests.
|
||||
// Note: This is being deprecated by the notary work.
|
||||
type Store struct {
|
||||
path string
|
||||
caPool *x509.CertPool
|
||||
|
@ -39,9 +41,9 @@ const defaultFetchtime = 45 * time.Second
|
|||
|
||||
var baseEndpoints = map[string]string{"official": "https://dvjy3tqbc323p.cloudfront.net/trust/official.json"}
|
||||
|
||||
// NewTrustStore creates from a given path, if the path is not
|
||||
// NewStore creates a TrustStore from a given path, if the path is not
|
||||
// relative, it will be joined with the working directory.
|
||||
func NewTrustStore(path string) (*Store, error) {
|
||||
func NewStore(path string) (*Store, error) {
|
||||
abspath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in a new issue