-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.go
49 lines (41 loc) · 1.39 KB
/
file.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
41
42
43
44
45
46
47
48
49
package certdepot
import (
"github.com/pkg/errors"
"github.com/square/certstrap/depot"
)
type fileDepot struct {
*depot.FileDepot
opts DepotOptions
}
// NewFileDepot creates a FileDepot wrapped with certdepot.Depot.
func NewFileDepot(dir string) (Depot, error) {
dt, err := depot.NewFileDepot(dir)
if err != nil {
return nil, errors.WithStack(err)
}
return &fileDepot{FileDepot: dt}, nil
}
// MakeFileDepot constructs a file-based depot implementation and
// allows users to specify options for the default CA name and
// expiration time.
func MakeFileDepot(dir string, opts DepotOptions) (Depot, error) {
dt, err := NewFileDepot(dir)
if err != nil {
return nil, errors.WithStack(err)
}
fd, ok := dt.(*fileDepot)
if !ok {
return nil, errors.New("internal error constructing depot")
}
fd.opts = opts
return fd, nil
}
func (fd *fileDepot) CheckWithError(tag *depot.Tag) (bool, error) { return fd.Check(tag), nil }
func (fd *fileDepot) Save(name string, creds *Credentials) error { return depotSave(fd, name, creds) }
func (fd *fileDepot) Find(name string) (*Credentials, error) { return depotFind(fd, name, fd.opts) }
func (fd *fileDepot) Generate(name string) (*Credentials, error) {
return depotGenerateDefault(fd, name, fd.opts)
}
func (fd *fileDepot) GenerateWithOptions(opts CertificateOptions) (*Credentials, error) {
return depotGenerate(fd, opts.CommonName, fd.opts, opts)
}