/
instance_config.go
55 lines (47 loc) · 1.28 KB
/
instance_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
45
46
47
48
49
50
51
52
53
54
55
package config
import (
"strings"
"github.com/kyma-incubator/compass/components/director/pkg/oauth"
"github.com/pkg/errors"
)
// InstanceConfig is a service instance config
type InstanceConfig struct {
ClientID string
ClientSecret string
URL string
TokenURL string
Cert string
Key string
}
// validate checks if all required fields are populated based on Oauth Mode.
// In the end, the error message is aggregated by joining all error messages.
func (i *InstanceConfig) validate(oauthMode oauth.AuthMode) error {
errorMessages := make([]string, 0)
if i.ClientID == "" {
errorMessages = append(errorMessages, "Client ID is missing")
}
if i.TokenURL == "" {
errorMessages = append(errorMessages, "Token URL is missing")
}
if i.URL == "" {
errorMessages = append(errorMessages, "URL is missing")
}
switch oauthMode {
case oauth.Standard:
if i.ClientSecret == "" {
errorMessages = append(errorMessages, "Client Secret is missing")
}
case oauth.Mtls:
if i.Cert == "" {
errorMessages = append(errorMessages, "Certificate is missing")
}
if i.Key == "" {
errorMessages = append(errorMessages, "Key is missing")
}
}
errorMsg := strings.Join(errorMessages, ", ")
if errorMsg != "" {
return errors.New(errorMsg)
}
return nil
}