-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
88 lines (74 loc) · 2 KB
/
settings.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
78
79
80
81
82
83
84
85
86
87
88
package backr
import (
"context"
"time"
)
type key int
const settingsKey key = 0
// Settings represents the settings that can be configured with CLI
type Settings struct {
StateStorage StateStorageSettings
WatchDirs []string
BackupRootDir string
TimeSpec BackupTimeSpec
StartupTime time.Time
// ConfigRefreshRate int
// SwiftUploadEnabled bool
S3 *S3Settings
ApiListen string
PrivateAPIListen string
SecretFilepath string
}
// S3Settings represents the settings needed to use S3 API
type S3Settings struct {
Bucket string
Endpoint string
AccessKey string
SecretKey string
UseTLS bool
}
type StateStorageType string
const (
StateStorageEtcd StateStorageType = "etcd"
StateStorageLocal StateStorageType = "local"
)
type StateStorageSettings struct {
EtcdEndpoints *string
LocalPath *string
}
func (st *StateStorageSettings) GetType() StateStorageType {
if st.LocalPath != nil && *st.LocalPath != "" {
return StateStorageLocal
}
return StateStorageEtcd
}
// BackupTimeSpec specifies the time options for performing backup
type BackupTimeSpec struct {
Hour int
Minute int
Period time.Duration
}
// NewDefaultSettings returns default options
func NewDefaultSettings() Settings {
return Settings{
BackupRootDir: "backups",
// SwiftUploadEnabled: false,
TimeSpec: BackupTimeSpec{
Hour: 1,
Minute: 0,
Period: time.Duration(24) * time.Hour, // unit of 1 day for ttl and minAge (WARNING: cannot be less (scheduling issues))
},
StartupTime: time.Now(),
ApiListen: ":22257",
PrivateAPIListen: "127.0.0.1:22258",
}
}
// NewContextWithSettings returns a context with associated options
func NewContextWithSettings(ctx context.Context, settings Settings) context.Context {
return context.WithValue(ctx, settingsKey, settings)
}
// SettingsFromContext returns the options associated to a context
func SettingsFromContext(ctx context.Context) (Settings, bool) {
options, ok := ctx.Value(settingsKey).(Settings)
return options, ok
}