-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings.go
141 lines (120 loc) · 4.47 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
// 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.
//
// 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 {
SettingsTTLDays int64 `json:"settings_ttl_days"`
RPC *JSONRPCServerSettings `json:"rpc,omitempty"`
}
type AppointmentsSettings struct {
DataTTLDays int64 `json:"data_ttl_days,omitempty"`
RPC *JSONRPCServerSettings `json:"rpc,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"`
}
type NotificationSettings struct {
RPC *JSONRPCServerSettings `json:"rpc"`
Mail *MailSettings `json:"mail"`
Secret []byte `json:"secret"`
Keys []*crypto.Key `json:"keys"`
}
func (a *AppointmentsSettings) Key(name string) *crypto.Key {
return key(a.Keys, name)
}
func (n *NotificationSettings) Key(name string) *crypto.Key {
return key(n.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 {
Admin *AdminSettings `json:"admin,omitempty"`
Definitions *Definitions `json:"definitions,omitempty"`
Storage *StorageSettings `json:"storage,omitempty"`
Appointments *AppointmentsSettings `json:"appointments,omitempty"`
Notification *NotificationSettings `json:"notification"`
Database *DatabaseSettings `json:"database,omitempty"`
Meter *MeterSettings `json:"meter,omitempty"`
DatabaseObj Database `json:"-"`
MeterObj Meter `json:"-"`
}
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"`
TLS *TLSSettings `json:"tls,omitempty"`
BindAddress string `json:"bind_address"`
}
// Settings for the JSON-RPC server
type HTTPServerSettings struct {
TLS *TLSSettings `json:"tls,omitempty"`
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"`
}