-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.go
161 lines (138 loc) · 5.35 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Kiebitz - Privacy-Friendly Appointment Scheduling
// Copyright (C) 2021-2021 The Kiebitz Authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. Additional terms
// as defined in section 7 of the license (e.g. regarding attribution)
// are specified at https://kiebitz.eu/en/docs/open-source/additional-terms.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package services
import (
"github.com/kiebitz-oss/services/crypto"
)
type RPCSettings struct {
BindAddress string `json:"bind_address"`
}
type StorageSettings struct {
Keys []*crypto.Key `json:"keys,omitempty"`
SettingsTTLDays int64 `json:"settings_ttl_days"`
HTTP *HTTPServerSettings `json:"http,omitempty"`
JSONRPC *JSONRPCServerSettings `json:"jsonrpc,omitempty"`
REST *RESTServerSettings `json:"rest,omitempty"`
}
type AppointmentsSettings struct {
DataTTLDays int64 `json:"data_ttl_days,omitempty"`
HTTP *HTTPServerSettings `json:"http,omitempty"`
REST *RESTServerSettings `json:"rest,omitempty"`
JSONRPC *JSONRPCServerSettings `json:"jsonrpc,omitempty"`
Keys []*crypto.Key `json:"keys,omitempty"`
Secret []byte `json:"secret,omitempty"`
ProviderCodesEnabled bool `json:"provider_codes_enabled,omitempty"`
UserCodesEnabled bool `json:"user_codes_enabled,omitempty"`
UserCodesReuseLimit int64 `json:"user_codes_reuse_limit"`
ProviderCodesReuseLimit int64 `json:"provider_codes_reuse_limit"`
ResponseMaxProvider int64 `json:"response_max_provider"`
ResponseMaxAppointment int64 `json:"response_max_appointment"`
}
func (a *AppointmentsSettings) Key(name string) *crypto.Key {
return Key(a.Keys, name)
}
func Key(keys []*crypto.Key, name string) *crypto.Key {
for _, key := range keys {
if key.Name == name {
return key
}
}
return nil
}
func (s *SigningSettings) Key(name string) *crypto.Key {
return Key(s.Keys, name)
}
type SigningSettings struct {
Keys []*crypto.Key `json:"keys"`
}
type DatabaseSettings struct {
Type string `json:"type"`
Settings interface{}
}
type MeterSettings struct {
Type string `json:"type"`
Settings interface{}
}
type Settings struct {
Test bool `json:"test,omitempty"`
Admin *AdminSettings `json:"admin,omitempty"`
Definitions *Definitions `json:"definitions,omitempty"`
Storage *StorageSettings `json:"storage,omitempty"`
Appointments *AppointmentsSettings `json:"appointments,omitempty"`
Database *DatabaseSettings `json:"database,omitempty"`
Meter *MeterSettings `json:"meter,omitempty"`
Metrics *MetricSettings `json:"metrics,omitempty"`
DatabaseObj Database `json:"-"`
MeterObj Meter `json:"-"`
MetricsObj MetricsServer `json:"-"`
}
type MetricsServer interface {
Start() error
Stop() error
}
type AdminSettings struct {
Signing *SigningSettings `json:"signing,omitempty"`
Client *ClientSettings `json:"client,omitempty"`
}
type ClientSettings struct {
StorageEndpoint string `json:"storage_endpoint"`
AppointmentsEndpoint string `json:"appointments_endpoint"`
}
type TLSSettings struct {
CACertificateFile string `json:"ca_certificate_file"`
CertificateFile string `json:"certificate_file"`
KeyFile string `json:"key_file"`
}
type CorsSettings struct {
AllowedHeaders []string `json:"allowed_headers"`
AllowedHosts []string `json:"allowed_hosts"`
AllowedMethods []string `json:"allowed_methods"`
}
// Settings for the JSON-RPC server
type JSONRPCServerSettings struct {
Cors *CorsSettings `json:"cors,omitempty"`
HTTP *HTTPServerSettings `json:"http,omitempty"`
}
// Settings for the JSON-RPC server
type RESTServerSettings struct {
Cors *CorsSettings `json:"cors,omitempty"`
HTTP *HTTPServerSettings `json:"http,omitempty"`
}
type HTTPServerSettings struct {
TLS *TLSSettings `json:"tls,omitempty"`
BindAddress string `json:"bind_address"`
TCPRateLimits []*RateLimit `json:"tcp_rate_limits"`
}
type RateLimit struct {
TimeWindow *TimeWindow `json:"timeWindow"`
Type string `json:"type"`
Limit int64 `json:"limit"`
}
type MetricSettings struct {
BindAddress string `json:"bind_address"`
}
type MailSettings struct {
SmtpHost string `json:"smtp_host"`
SmtpPort int64 `json:"smtp_port"`
SmtpUser string `json:"smtp_user"`
SmtpPassword string `json:"smtp_password"`
Sender string `json:"sender"`
MailSubject string `json:"mail_subject"`
MailTemplate string `json:"mail_template"`
MailDelay int64 `json:"mail_delay"`
}