-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
44 lines (39 loc) · 1.29 KB
/
config.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
package main
import (
"errors"
"go.wasmcloud.dev/provider"
)
type CouchbaseConnectionArgs struct {
Username string
Password string
BucketName string
ConnectionString string
ScopeName string
CollectionName string
}
// Construct Couchbase connection args from config and secrets
func validateCouchbaseConfig(config map[string]string, secrets map[string]provider.SecretValue) (CouchbaseConnectionArgs, error) {
connectionArgs := CouchbaseConnectionArgs{}
if username, ok := config["username"]; !ok || username == "" {
return connectionArgs, errors.New("username config is required")
} else {
connectionArgs.Username = username
}
if bucketName, ok := config["bucketName"]; !ok || bucketName == "" {
return connectionArgs, errors.New("bucketName config is required")
} else {
connectionArgs.BucketName = bucketName
}
if connectionString, ok := config["connectionString"]; !ok || connectionString == "" {
return connectionArgs, errors.New("connectionString config is required")
} else {
connectionArgs.ConnectionString = connectionString
}
password := secrets["password"].String.Reveal()
if password == "" {
return connectionArgs, errors.New("password secret is required")
} else {
connectionArgs.Password = password
}
return connectionArgs, nil
}