-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurationsService.go
79 lines (68 loc) · 2.03 KB
/
ConfigurationsService.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
package ServerConfig
import (
"encoding/json"
"github.com/rs/zerolog/log"
"golang.org/x/exp/slices"
"io/ioutil"
"net/http"
)
type ConfigurationService struct {
DomainAndBuckets map[string]string `json:"DomainAndBuckets"`
DomainSettings map[string]Settings
ContactFormApi ContactFormApi
SuperChatApi SuperChatApi
UserApi UserApi
CheckSum string
}
type ContactFormApi struct {
ValidDomains []string
DomainAndServicesettings map[string]Servicesettings `json:"DomainAndServicesettings"`
}
type SuperChatApi struct {
ValidDomains []string
DomainAndServicesettings map[string]Servicesettings `json:"DomainAndServicesettings"`
}
type UserApi struct {
ValidDomains []string
DomainAndServicesettings map[string]Servicesettings `json:"DomainAndServicesettings"`
}
type Servicesettings struct {
MessageExpiryInDays int
EmailNotificationEnabled int
PublishToIndexer int
}
type Settings struct {
BaseSecretKey string
GlobalKey string //change this to deactivate and force issuing new token
TokenValidityInMins int
MessageExpiryInDays int
EmailNotificationEnabled int
PublishToIndexer int
EnableUsrTokenAuthentication int
}
type config_server_response struct {
Response ConfigurationService `json:"Response"`
}
func LoadConfigurationFromServer(url string) (ConfigurationService, error) {
var config = ConfigurationService{}
var serverResponse = config_server_response{}
resp, err := http.Get(url)
if err != nil {
log.Error().Msgf("LoadConfigurationFromServer :%v", err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error().Msgf("LoadConfigurationFromServer :%v", err)
return config, err
}
err = json.Unmarshal(body, &serverResponse)
config = serverResponse.Response
if err != nil {
println(err)
return config, err
}
return config, err
}
func IsValidDomain(domain string, validDomainsForTheService []string) bool {
return slices.Contains(validDomainsForTheService, domain)
}