forked from fabiolb/fabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_source.go
40 lines (34 loc) · 847 Bytes
/
path_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cert
import (
"crypto/tls"
"crypto/x509"
"path/filepath"
"time"
)
const (
DefaultCertPath = "cert"
DefaultClientCAPath = "clientca"
)
type PathSource struct {
Path string
CertPath string
ClientCAPath string
CAUpgradeCN string
Refresh time.Duration
}
func (s PathSource) LoadClientCAs() (*x509.CertPool, error) {
path := makePath(s.Path, s.ClientCAPath, DefaultClientCAPath)
return newCertPool(path, s.CAUpgradeCN, loadPath)
}
func (s PathSource) Certificates() chan []tls.Certificate {
path := makePath(s.Path, s.CertPath, DefaultCertPath)
ch := make(chan []tls.Certificate, 1)
go watch(ch, s.Refresh, path, loadPath)
return ch
}
func makePath(parent, child, defaultChild string) string {
if child == "" {
return filepath.Join(parent, defaultChild)
}
return filepath.Join(parent, child)
}