forked from giantswarm/cert-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
73 lines (59 loc) · 1.5 KB
/
service.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ca
import (
"sync"
microerror "github.com/giantswarm/microkit/error"
micrologger "github.com/giantswarm/microkit/logger"
vaultapi "github.com/hashicorp/vault/api"
"github.com/spf13/viper"
"github.com/giantswarm/cert-operator/flag"
)
// Config represents the configuration used to create a CA service.
type Config struct {
// Dependencies.
Logger micrologger.Logger
VaultClient *vaultapi.Client
// Settings.
Flag *flag.Flag
Viper *viper.Viper
}
// DefaultConfig provides a default configuration to create a new CA service
// by best effort.
func DefaultConfig() Config {
return Config{
// Dependencies.
Logger: nil,
VaultClient: nil,
// Settings.
Flag: nil,
Viper: nil,
}
}
// New creates a new configured CA service.
func New(config Config) (*Service, error) {
// Dependencies.
if config.Logger == nil {
return nil, microerror.MaskAnyf(invalidConfigError, "logger must not be empty")
}
if config.VaultClient == nil {
return nil, microerror.MaskAnyf(invalidConfigError, "vault client must not be empty")
}
// Settings.
if config.Flag == nil {
return nil, microerror.MaskAnyf(invalidConfigError, "flag must not be empty")
}
if config.Viper == nil {
return nil, microerror.MaskAnyf(invalidConfigError, "viper must not be empty")
}
newService := &Service{
Config: config,
// Internals
bootOnce: sync.Once{},
}
return newService, nil
}
// Service implements the CA service interface.
type Service struct {
Config
// Internals.
bootOnce sync.Once
}