-
Notifications
You must be signed in to change notification settings - Fork 5
/
verify.go
77 lines (71 loc) · 2.32 KB
/
verify.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
package initlib
import (
"errors"
"fmt"
eUtils "github.com/trimble-oss/tierceron/pkg/utils"
"github.com/trimble-oss/tierceron/pkg/validator"
helperkv "github.com/trimble-oss/tierceron/pkg/vaulthelper/kv"
)
// Runs the verification step from data in the seed file
// v is the data contained under the "verification:" tag
// Service name should match credentials in super-secrets
// to verify
// Example
// SpectrumDB:
// type: db
// SendGrid:
// type: SendGridKey
// KeyStore:
// type: KeyStore
func verify(config *eUtils.DriverConfig, mod *helperkv.Modifier, v map[interface{}]interface{}) ([]string, error) {
var isValid bool
var path string
config.Log.SetPrefix("[VERIFY]")
for service, info := range v {
vType := info.(map[interface{}]interface{})["type"].(string)
serviceData, err := mod.ReadData("super-secrets/" + service.(string))
if err != nil {
return nil, err
}
config.Log.Print(eUtils.SanitizeForLogging(fmt.Sprintf("Verifying %s as type %s\n", service, vType)))
switch vType {
case "db":
if url, ok := serviceData["url"].(string); ok {
if user, ok := serviceData["user"].(string); ok {
if pass, ok := serviceData["pass"].(string); ok {
isValid, err = validator.Heartbeat(config, url, user, pass)
eUtils.LogErrorObject(config, err, false)
} else {
eUtils.LogErrorObject(config, fmt.Errorf("password field is not a string value"), false)
}
} else {
eUtils.LogErrorObject(config, fmt.Errorf("username field is not a string value"), false)
}
} else {
eUtils.LogErrorObject(config, fmt.Errorf("URL field is not a string value"), false)
}
case "SendGridKey":
if key, ok := serviceData["SendGridApiKey"].(string); ok {
isValid, err = validator.ValidateSendGrid(key)
eUtils.LogErrorObject(config, err, false)
}
case "KeyStore":
// path := serviceData["path"].(string)
// pass := serviceData["pass"].(string)
isValid = false
default:
return nil, errors.New("Invalid verification type: " + vType)
}
// Log verification status and write to vault
config.Log.Printf("\tverified: %v\n", isValid)
path = "verification/" + service.(string)
warn, err := mod.Write(path, map[string]interface{}{
"type": vType,
"verified": isValid,
}, config.Log)
if len(warn) > 0 || err != nil {
return warn, err
}
}
return nil, nil
}