-
Notifications
You must be signed in to change notification settings - Fork 0
/
credentials.go
58 lines (48 loc) · 988 Bytes
/
credentials.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
package eventuate
import (
"os"
"strings"
)
type Credentials struct {
apiKeyId string
apiKeySecret string
Space string
}
func NewCredentials(
apiKeyId string,
apiKeySecret string,
space string) (*Credentials, error) {
var (
missing []string = make([]string, 0)
)
switch {
case len(apiKeyId) == 0:
{
missing = append(missing, "apiKeyId")
}
fallthrough
case len(apiKeySecret) == 0:
{
missing = append(missing, "apiKeySecret")
return nil, AppError("NewCredentials: parameters missing: %s",
strings.Join(missing, ", "))
}
case len(space) == 0:
{
space = "default"
}
}
return &Credentials{
apiKeyId,
apiKeySecret,
space}, nil
}
func NewCredentialsFromEnv() (*Credentials, error) {
return NewCredentialsFromEnvAndSpace("default")
}
func NewCredentialsFromEnvAndSpace(space string) (*Credentials, error) {
return NewCredentials(
os.Getenv("EVENTUATE_API_KEY_ID"),
os.Getenv("EVENTUATE_API_KEY_SECRET"),
space)
}