Add (*CertificateStore).Write function
This commit is contained in:
parent
85f8e84bd5
commit
3dee6dcff3
15
cert.go
15
cert.go
@ -28,7 +28,7 @@ type CertificateStore struct {
|
||||
|
||||
// Add adds a certificate for the given scope to the store.
|
||||
// It tries to parse the certificate if it is not already parsed.
|
||||
func (c *CertificateStore) Add(scope string, cert tls.Certificate) error {
|
||||
func (c *CertificateStore) Add(scope string, cert tls.Certificate) {
|
||||
if c.store == nil {
|
||||
c.store = map[string]tls.Certificate{}
|
||||
}
|
||||
@ -39,15 +39,18 @@ func (c *CertificateStore) Add(scope string, cert tls.Certificate) error {
|
||||
cert.Leaf = parsed
|
||||
}
|
||||
}
|
||||
c.store[scope] = cert
|
||||
}
|
||||
|
||||
// Write writes the provided certificate to the certificate directory.
|
||||
func (c *CertificateStore) Write(scope string, cert tls.Certificate) error {
|
||||
if c.dir {
|
||||
// Write certificates
|
||||
certPath := filepath.Join(c.path, scope+".crt")
|
||||
keyPath := filepath.Join(c.path, scope+".key")
|
||||
if err := WriteCertificate(cert, certPath, keyPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
c.store[scope] = cert
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -82,6 +85,12 @@ func (c *CertificateStore) Load(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetOutput sets the directory that new certificates will be written to.
|
||||
func (c *CertificateStore) SetOutput(path string) {
|
||||
c.dir = true
|
||||
c.path = path
|
||||
}
|
||||
|
||||
// CertificateOptions configures the creation of a certificate.
|
||||
type CertificateOptions struct {
|
||||
// Subject Alternate Name values.
|
||||
|
@ -160,8 +160,9 @@ func (s *Server) getCertificateFor(hostname string) (*tls.Certificate, error) {
|
||||
if s.CreateCertificate != nil {
|
||||
cert, err := s.CreateCertificate(hostname)
|
||||
if err == nil {
|
||||
if err := s.Certificates.Add(hostname, cert); err != nil {
|
||||
s.logf("gemini: Failed to add new certificate for %s: %s", hostname, err)
|
||||
s.Certificates.Add(hostname, cert)
|
||||
if err := s.Certificates.Write(hostname, cert); err != nil {
|
||||
s.logf("gemini: Failed to write new certificate for %s: %s", hostname, err)
|
||||
}
|
||||
}
|
||||
return &cert, err
|
||||
@ -262,7 +263,7 @@ type ResponseWriter struct {
|
||||
b *bufio.Writer
|
||||
bodyAllowed bool
|
||||
wroteHeader bool
|
||||
mediatype string
|
||||
mediatype string
|
||||
}
|
||||
|
||||
func newResponseWriter(conn net.Conn) *ResponseWriter {
|
||||
|
Loading…
Reference in New Issue
Block a user