-
Notifications
You must be signed in to change notification settings - Fork 12
/
custom_api_sender.go
46 lines (36 loc) · 1.17 KB
/
custom_api_sender.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
package config
import (
"github.com/antham/envh"
)
type customAPISenderConfigurator struct {
config *envh.EnvTree
}
func (g *customAPISenderConfigurator) process(config *CHYLE) (bool, error) {
if g.isDisabled() {
return false, nil
}
config.FEATURES.SENDERS.ENABLED = true
config.FEATURES.SENDERS.CUSTOMAPI = true
for _, f := range []func() error{
g.validateCredentials,
g.validateMandatoryFields,
g.validateURL,
} {
if err := f(); err != nil {
return false, err
}
}
return false, nil
}
func (g *customAPISenderConfigurator) isDisabled() bool {
return !g.config.IsExistingSubTree("CHYLE", "SENDERS", "CUSTOMAPI")
}
func (g *customAPISenderConfigurator) validateCredentials() error {
return validateEnvironmentVariablesDefinition(g.config, [][]string{{"CHYLE", "SENDERS", "CUSTOMAPI", "CREDENTIALS", "TOKEN"}})
}
func (g *customAPISenderConfigurator) validateMandatoryFields() error {
return validateEnvironmentVariablesDefinition(g.config, [][]string{{"CHYLE", "SENDERS", "CUSTOMAPI", "ENDPOINT", "URL"}})
}
func (g *customAPISenderConfigurator) validateURL() error {
return validateURL(g.config, []string{"CHYLE", "SENDERS", "CUSTOMAPI", "ENDPOINT", "URL"})
}