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.
|
// Add adds a certificate for the given scope to the store.
|
||||||
// It tries to parse the certificate if it is not already parsed.
|
// 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 {
|
if c.store == nil {
|
||||||
c.store = map[string]tls.Certificate{}
|
c.store = map[string]tls.Certificate{}
|
||||||
}
|
}
|
||||||
|
@ -39,15 +39,18 @@ func (c *CertificateStore) Add(scope string, cert tls.Certificate) error {
|
||||||
cert.Leaf = parsed
|
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 {
|
if c.dir {
|
||||||
// Write certificates
|
|
||||||
certPath := filepath.Join(c.path, scope+".crt")
|
certPath := filepath.Join(c.path, scope+".crt")
|
||||||
keyPath := filepath.Join(c.path, scope+".key")
|
keyPath := filepath.Join(c.path, scope+".key")
|
||||||
if err := WriteCertificate(cert, certPath, keyPath); err != nil {
|
if err := WriteCertificate(cert, certPath, keyPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.store[scope] = cert
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +85,12 @@ func (c *CertificateStore) Load(path string) error {
|
||||||
return nil
|
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.
|
// CertificateOptions configures the creation of a certificate.
|
||||||
type CertificateOptions struct {
|
type CertificateOptions struct {
|
||||||
// Subject Alternate Name values.
|
// Subject Alternate Name values.
|
||||||
|
|
|
@ -160,8 +160,9 @@ func (s *Server) getCertificateFor(hostname string) (*tls.Certificate, error) {
|
||||||
if s.CreateCertificate != nil {
|
if s.CreateCertificate != nil {
|
||||||
cert, err := s.CreateCertificate(hostname)
|
cert, err := s.CreateCertificate(hostname)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := s.Certificates.Add(hostname, cert); err != nil {
|
s.Certificates.Add(hostname, cert)
|
||||||
s.logf("gemini: Failed to add new certificate for %s: %s", hostname, err)
|
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
|
return &cert, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user