certificate: Add Dir.Entries function
This commit is contained in:
parent
14d89f304a
commit
79a4dfd43f
@ -21,7 +21,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Dir represents a directory of certificates.
|
// Dir represents a directory of certificates.
|
||||||
// The zero value of Dir is an empty directory ready to use.
|
// The zero value for Dir is an empty directory ready to use.
|
||||||
//
|
//
|
||||||
// Dir is safe for concurrent use by multiple goroutines.
|
// Dir is safe for concurrent use by multiple goroutines.
|
||||||
type Dir struct {
|
type Dir struct {
|
||||||
@ -68,12 +68,21 @@ func (d *Dir) Lookup(scope string) (tls.Certificate, bool) {
|
|||||||
return cert, ok
|
return cert, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads certificates from the given path.
|
// Entries returns a map of hostnames to certificates.
|
||||||
// The path should lead to a directory containing certificates and private keys
|
func (d *Dir) Entries() map[string]tls.Certificate {
|
||||||
// in the form scope.crt and scope.key.
|
certs := map[string]tls.Certificate{}
|
||||||
// For example, the hostname "localhost" would have the corresponding files
|
for key := range d.certs {
|
||||||
// localhost.crt (certificate) and localhost.key (private key).
|
certs[key] = d.certs[key]
|
||||||
// New certificates will be written to this directory.
|
}
|
||||||
|
return certs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load loads certificates from the provided path.
|
||||||
|
// Add will write certificates to this path.
|
||||||
|
//
|
||||||
|
// The directory should contain certificates and private keys
|
||||||
|
// named scope.crt and scope.key respectively, where scope is
|
||||||
|
// the scope of the certificate.
|
||||||
func (d *Dir) Load(path string) error {
|
func (d *Dir) Load(path string) error {
|
||||||
matches, err := filepath.Glob(filepath.Join(path, "*.crt"))
|
matches, err := filepath.Glob(filepath.Join(path, "*.crt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -94,7 +103,8 @@ func (d *Dir) Load(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPath sets the directory that new certificates will be written to.
|
// SetPath sets the directory path.
|
||||||
|
// Add will write certificates to this path.
|
||||||
func (d *Dir) SetPath(path string) {
|
func (d *Dir) SetPath(path string) {
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
defer d.mu.Unlock()
|
defer d.mu.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user