|
@@ -3,7 +3,6 @@ package opts
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
"net"
|
|
"net"
|
|
- "os"
|
|
|
|
"regexp"
|
|
"regexp"
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
@@ -152,34 +151,6 @@ type ValidatorFctType func(val string) (string, error)
|
|
// ValidatorFctListType defines a validator function that returns a validated 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)
|
|
type ValidatorFctListType func(val string) ([]string, error)
|
|
|
|
|
|
-// 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"} {
|
|
|
|
- if s == str {
|
|
|
|
- return s, nil
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR")
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// ValidateEnv validates an environment variable and returns it.
|
|
|
|
-// If no value is specified, it returns the current value using os.Getenv.
|
|
|
|
-//
|
|
|
|
-// As on ParseEnvFile and related to #16585, environment variable names
|
|
|
|
-// are not validate what so ever, it's up to application inside docker
|
|
|
|
-// to validate them or not.
|
|
|
|
-func ValidateEnv(val string) (string, error) {
|
|
|
|
- arr := strings.Split(val, "=")
|
|
|
|
- if len(arr) > 1 {
|
|
|
|
- return val, nil
|
|
|
|
- }
|
|
|
|
- if !doesEnvExist(val) {
|
|
|
|
- return val, nil
|
|
|
|
- }
|
|
|
|
- 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) {
|
|
func ValidateIPAddress(val string) (string, error) {
|
|
var ip = net.ParseIP(strings.TrimSpace(val))
|
|
var ip = net.ParseIP(strings.TrimSpace(val))
|
|
@@ -189,15 +160,6 @@ func ValidateIPAddress(val string) (string, error) {
|
|
return "", fmt.Errorf("%s is not an ip address", val)
|
|
return "", fmt.Errorf("%s is not an ip address", val)
|
|
}
|
|
}
|
|
|
|
|
|
-// ValidateMACAddress validates a MAC address.
|
|
|
|
-func ValidateMACAddress(val string) (string, error) {
|
|
|
|
- _, err := net.ParseMAC(strings.TrimSpace(val))
|
|
|
|
- if err != nil {
|
|
|
|
- return "", err
|
|
|
|
- }
|
|
|
|
- return val, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// ValidateDNSSearch validates domain for resolvconf search configuration.
|
|
// ValidateDNSSearch validates domain for resolvconf search configuration.
|
|
// A zero length domain is represented by a dot (.).
|
|
// A zero length domain is represented by a dot (.).
|
|
func ValidateDNSSearch(val string) (string, error) {
|
|
func ValidateDNSSearch(val string) (string, error) {
|
|
@@ -218,20 +180,6 @@ func validateDomain(val string) (string, error) {
|
|
return "", fmt.Errorf("%s is not a valid domain", val)
|
|
return "", fmt.Errorf("%s is not a valid domain", val)
|
|
}
|
|
}
|
|
|
|
|
|
-// 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)
|
|
|
|
- if len(arr) != 2 || len(arr[0]) == 0 {
|
|
|
|
- return "", fmt.Errorf("bad format for add-host: %q", val)
|
|
|
|
- }
|
|
|
|
- if _, err := ValidateIPAddress(arr[1]); err != nil {
|
|
|
|
- return "", fmt.Errorf("invalid IP address in add-host: %q", arr[1])
|
|
|
|
- }
|
|
|
|
- return val, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// ValidateLabel validates that the specified string is a valid label, and returns it.
|
|
// ValidateLabel validates that the specified string is a valid label, and returns it.
|
|
// Labels are in the form on key=value.
|
|
// Labels are in the form on key=value.
|
|
func ValidateLabel(val string) (string, error) {
|
|
func ValidateLabel(val string) (string, error) {
|
|
@@ -240,13 +188,3 @@ func ValidateLabel(val string) (string, error) {
|
|
}
|
|
}
|
|
return val, nil
|
|
return val, nil
|
|
}
|
|
}
|
|
-
|
|
|
|
-func doesEnvExist(name string) bool {
|
|
|
|
- for _, entry := range os.Environ() {
|
|
|
|
- parts := strings.SplitN(entry, "=", 2)
|
|
|
|
- if parts[0] == name {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false
|
|
|
|
-}
|
|
|