Files
crockery/internal/store/store.go

62 lines
963 B
Go
Raw Normal View History

2018-03-05 12:19:04 +00:00
package store
import (
"context"
"crypto/tls"
2018-03-05 12:19:04 +00:00
)
type Interface interface {
Domain() string
TLS() tls.Certificate
TLSConfig() *tls.Config
SetDomain(string)
SetTLS(tls.Certificate)
2018-03-05 12:19:04 +00:00
}
func New(ctx context.Context, filename string) (Interface, error) {
return &concrete{
filename: filename,
}, nil
2018-03-05 12:19:04 +00:00
}
type concrete struct {
filename string
// TODO: these will eventually be persisted to the file in `filename`
2018-03-05 12:19:04 +00:00
domain string
cert tls.Certificate
2018-03-05 12:19:04 +00:00
}
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
}