Hack in command-line specification of domain, cert and key

This commit is contained in:
2018-03-05 19:53:48 +00:00
parent 811b90224f
commit bf1ca421aa
6 changed files with 107 additions and 8 deletions

View File

@@ -2,20 +2,60 @@ package store
import (
"context"
"crypto/tls"
)
type Interface interface {
Domain() string
TLS() tls.Certificate
TLSConfig() *tls.Config
SetDomain(string)
SetTLS(tls.Certificate)
}
func New(ctx context.Context, filename string) (Interface, error) {
return &concrete{domain: "example.com"}, nil
return &concrete{
filename: filename,
}, nil
}
type concrete struct {
filename string
// TODO: these will eventually be persisted to the file in `filename`
domain string
cert tls.Certificate
}
func (c *concrete) Domain() string {
return c.domain
}
func (c *concrete) TLS() tls.Certificate {
return c.cert
}
func (c *concrete) TLSConfig() *tls.Config {
return &tls.Config{
GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
certCopy := c.TLS()
return &certCopy, nil
},
ServerName: c.Domain(),
}
}
func (c *concrete) SetDomain(domain string) {
c.domain = domain
return
}
func (c *concrete) SetTLS(cert tls.Certificate) {
c.cert = cert
return
}