feat(clusterconfig): ssl

This commit is contained in:
Mikaël Cluseau 2018-06-16 22:44:53 +11:00
parent 8b69526362
commit ae56301804
3 changed files with 46 additions and 5 deletions

View File

@ -0,0 +1,10 @@
package clustersconfig
type CertRequest struct {
Template `yaml:",inline"`
CA string
Profile string
Label string
PerHost bool `yaml:"per_host"`
}

View File

@ -12,11 +12,13 @@ import (
) )
type Config struct { type Config struct {
Hosts []*Host Hosts []*Host
Groups []*Group Groups []*Group
Clusters []*Cluster Clusters []*Cluster
Configs []*Template Configs []*Template
StaticPods []*Template `yaml:"static_pods"` StaticPods []*Template `yaml:"static_pods"`
SSLConfig string `yaml:"ssl_config"`
CertRequests []*CertRequest `yaml:"cert_requests"`
} }
func FromBytes(data []byte) (*Config, error) { func FromBytes(data []byte) (*Config, error) {
@ -109,6 +111,15 @@ func (c *Config) StaticPodsTemplate(name string) *Template {
return nil return nil
} }
func (c *Config) CSR(name string) *CertRequest {
for _, s := range c.CertRequests {
if s.Name == name {
return s
}
}
return nil
}
func (c *Config) SaveTo(path string) error { func (c *Config) SaveTo(path string) error {
ba, err := yaml.Marshal(c) ba, err := yaml.Marshal(c)
if err != nil { if err != nil {

View File

@ -2,6 +2,7 @@ package clustersconfig
import ( import (
"io/ioutil" "io/ioutil"
"os"
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -94,6 +95,25 @@ func FromDir(dirPath string) (*Config, error) {
return nil, err return nil, err
} }
if ba, err := ioutil.ReadFile(filepath.Join(dirPath, "ssl-config.json")); err == nil {
config.SSLConfig = string(ba)
} else if !os.IsNotExist(err) {
return nil, err
}
if ba, err := ioutil.ReadFile(filepath.Join(dirPath, "cert-requests.yaml")); err == nil {
reqs := make([]*CertRequest, 0)
if err = yaml.Unmarshal(ba, &reqs); err != nil {
return nil, err
}
config.CertRequests = reqs
} else if !os.IsNotExist(err) {
return nil, err
}
return config, nil return config, nil
} }