Files
crockery/internal/store/store.go

62 lines
963 B
Go

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{
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
}