-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
77 lines (64 loc) · 2.22 KB
/
config.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
74
75
76
77
package registry
import (
"strings"
"time"
"github.com/k0kubun/pp"
"github.com/rai-project/config"
"github.com/rai-project/libkv/store"
"github.com/rai-project/serializer"
_ "github.com/rai-project/serializer/bson"
_ "github.com/rai-project/serializer/json"
_ "github.com/rai-project/serializer/jsonpb"
"github.com/rai-project/vipertags"
)
type registryConfig struct {
ProviderString string `json:"provider" config:"registry.provider"`
Provider store.Backend `json:"-" config:"-"`
Endpoints []string `json:"endpoints" config:"registry.endpoints" env:"REGISTRY_ENDPOINTS"`
Username string `json:"username" config:"registry.username"`
Password string `json:"-" config:"registry.password"`
Timeout time.Duration `json:"timeout" config:"registry.timeout" default:"10s"`
HeaderTimeoutPerRequest time.Duration `json:"header_timeout_per_request" config:"registry.header_timeout_per_request"`
Bucket string `json:"bucket" config:"registry.bucket"`
AutoSync bool `json:"auto_Sync" config:"registry.auto_sync" default:"true"`
Certificate string `json:"certificate" config:"registry.certificate"`
Serializer serializer.Serializer `json:"-" config:"-"`
SerializerName string `json:"serializer_name" config:"registry.serializer" default:"jsonpb"`
done chan struct{} `json:"-" config:"-"`
}
var (
Config = ®istryConfig{
done: make(chan struct{}),
}
)
func (registryConfig) ConfigName() string {
return "Registry"
}
func (a *registryConfig) SetDefaults() {
vipertags.SetDefaults(a)
}
func (a *registryConfig) Read() {
defer close(a.done)
config.App.Wait()
vipertags.Fill(a)
if a.Certificate != "" {
a.Certificate = decrypt(a.Certificate)
}
a.Provider = getProvider(a.ProviderString)
if strings.TrimSpace(a.Bucket) == "" {
a.Bucket = config.App.Name
}
a.Serializer, _ = serializer.FromName(a.SerializerName)
}
func (c registryConfig) Wait() {
<-c.done
}
func (c registryConfig) String() string {
return pp.Sprintln(c)
}
func (c registryConfig) Debug() {
log.Debug("Registry Config = ", c)
}
func init() {
config.Register(Config)
}