Merge pull request #758 from containous/fix-multiple-certs-flag

Fix multiple certificates using flag
This commit is contained in:
Emile Vauge 2016-10-26 16:23:06 +02:00 committed by GitHub
commit 53b5d8ac33

View file

@ -28,7 +28,7 @@ type GlobalConfiguration struct {
AccessLogsFile string `description:"Access logs file"` AccessLogsFile string `description:"Access logs file"`
TraefikLogsFile string `description:"Traefik logs file"` TraefikLogsFile string `description:"Traefik logs file"`
LogLevel string `short:"l" description:"Log level"` LogLevel string `short:"l" description:"Log level"`
EntryPoints EntryPoints `description:"Entrypoints definition using format: --entryPoints='Name:http Address::8000 Redirect.EntryPoint:https' --entryPoints='Name:https Address::4442 TLS:tests/traefik.crt,tests/traefik.key'"` EntryPoints EntryPoints `description:"Entrypoints definition using format: --entryPoints='Name:http Address::8000 Redirect.EntryPoint:https' --entryPoints='Name:https Address::4442 TLS:tests/traefik.crt,tests/traefik.key;prod/traefik.crt,prod/traefik.key'"`
Cluster *types.Cluster `description:"Enable clustering"` Cluster *types.Cluster `description:"Enable clustering"`
Constraints types.Constraints `description:"Filter services by constraint, matching with service tags"` Constraints types.Constraints `description:"Filter services by constraint, matching with service tags"`
ACME *acme.ACME `description:"Enable ACME (Let's Encrypt): automatic SSL"` ACME *acme.ACME `description:"Enable ACME (Let's Encrypt): automatic SSL"`
@ -263,14 +263,20 @@ func (certs *Certificates) String() string {
if len(*certs) == 0 { if len(*certs) == 0 {
return "" return ""
} }
return (*certs)[0].CertFile + "," + (*certs)[0].KeyFile var result []string
for _, certificate := range *certs {
result = append(result, certificate.CertFile+","+certificate.KeyFile)
}
return strings.Join(result, ";")
} }
// Set is the method to set the flag value, part of the flag.Value interface. // Set is the method to set the flag value, part of the flag.Value interface.
// Set's argument is a string to be parsed to set the flag. // Set's argument is a string to be parsed to set the flag.
// It's a comma-separated list, so we split it. // It's a comma-separated list, so we split it.
func (certs *Certificates) Set(value string) error { func (certs *Certificates) Set(value string) error {
files := strings.Split(value, ",") certificates := strings.Split(value, ";")
for _, certificate := range certificates {
files := strings.Split(certificate, ",")
if len(files) != 2 { if len(files) != 2 {
return errors.New("Bad certificates format: " + value) return errors.New("Bad certificates format: " + value)
} }
@ -278,6 +284,7 @@ func (certs *Certificates) Set(value string) error {
CertFile: files[0], CertFile: files[0],
KeyFile: files[1], KeyFile: files[1],
}) })
}
return nil return nil
} }