2017-11-09 11:16:03 +00:00
|
|
|
package tls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2017-12-08 10:02:03 +00:00
|
|
|
)
|
|
|
|
|
2019-03-14 08:30:04 +00:00
|
|
|
const certificateHeader = "-----BEGIN CERTIFICATE-----\n"
|
2017-11-09 11:16:03 +00:00
|
|
|
|
2017-11-10 09:30:04 +00:00
|
|
|
// ClientCA defines traefik CA files for a entryPoint
|
|
|
|
// and it indicates if they are mandatory or have just to be analyzed if provided
|
|
|
|
type ClientCA struct {
|
2018-08-29 09:36:03 +00:00
|
|
|
Files FilesOrContents
|
2017-11-10 09:30:04 +00:00
|
|
|
Optional bool
|
|
|
|
}
|
|
|
|
|
2017-11-09 11:16:03 +00:00
|
|
|
// TLS configures TLS for an entry point
|
|
|
|
type TLS struct {
|
2019-03-14 08:30:04 +00:00
|
|
|
MinVersion string `export:"true"`
|
|
|
|
CipherSuites []string
|
|
|
|
ClientCA ClientCA
|
|
|
|
SniStrict bool `export:"true"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store holds the options for a given Store
|
|
|
|
type Store struct {
|
2018-07-06 08:30:03 +00:00
|
|
|
DefaultCertificate *Certificate
|
2017-11-09 11:16:03 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 09:36:03 +00:00
|
|
|
// FilesOrContents hold the CA we want to have in root
|
|
|
|
type FilesOrContents []FileOrContent
|
2017-11-09 11:16:03 +00:00
|
|
|
|
|
|
|
// Configuration allows mapping a TLS certificate to a list of entrypoints
|
|
|
|
type Configuration struct {
|
2019-03-14 08:30:04 +00:00
|
|
|
Stores []string
|
2017-11-09 11:16:03 +00:00
|
|
|
Certificate *Certificate
|
|
|
|
}
|
|
|
|
|
|
|
|
// String is the method to format the flag's value, part of the flag.Value interface.
|
|
|
|
// The String method's output will be used in diagnostics.
|
2018-08-29 09:36:03 +00:00
|
|
|
func (r *FilesOrContents) String() string {
|
2017-11-09 11:16:03 +00:00
|
|
|
sliceOfString := make([]string, len([]FileOrContent(*r)))
|
|
|
|
for key, value := range *r {
|
|
|
|
sliceOfString[key] = value.String()
|
|
|
|
}
|
|
|
|
return strings.Join(sliceOfString, ",")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// It's a comma-separated list, so we split it.
|
2018-08-29 09:36:03 +00:00
|
|
|
func (r *FilesOrContents) Set(value string) error {
|
|
|
|
filesOrContents := strings.Split(value, ",")
|
|
|
|
if len(filesOrContents) == 0 {
|
|
|
|
return fmt.Errorf("bad FilesOrContents format: %s", value)
|
2017-11-09 11:16:03 +00:00
|
|
|
}
|
2018-08-29 09:36:03 +00:00
|
|
|
for _, fileOrContent := range filesOrContents {
|
|
|
|
*r = append(*r, FileOrContent(fileOrContent))
|
2017-11-09 11:16:03 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-29 09:36:03 +00:00
|
|
|
// Get return the FilesOrContents list
|
|
|
|
func (r *FilesOrContents) Get() interface{} {
|
2017-12-18 08:14:03 +00:00
|
|
|
return *r
|
2017-11-09 11:16:03 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 09:36:03 +00:00
|
|
|
// SetValue sets the FilesOrContents with val
|
|
|
|
func (r *FilesOrContents) SetValue(val interface{}) {
|
|
|
|
*r = val.(FilesOrContents)
|
2017-11-09 11:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Type is type of the struct
|
2018-08-29 09:36:03 +00:00
|
|
|
func (r *FilesOrContents) Type() string {
|
|
|
|
return "filesorcontents"
|
2017-11-09 11:16:03 +00:00
|
|
|
}
|