-
Notifications
You must be signed in to change notification settings - Fork 84
/
saas_reg_config.go
41 lines (34 loc) · 945 Bytes
/
saas_reg_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
package config
import (
"strings"
"github.com/pkg/errors"
)
// SaasRegConfig is a saas reg config
type SaasRegConfig struct {
ClientID string
ClientSecret string
TokenURL string
SaasRegistryURL string
}
// validate checks if all required fields are populated.
// In the end, the error message is aggregated by joining all error messages.
func (s *SaasRegConfig) validate() error {
errorMessages := make([]string, 0)
if s.ClientID == "" {
errorMessages = append(errorMessages, "Client ID is missing")
}
if s.ClientSecret == "" {
errorMessages = append(errorMessages, "Client Secret is missing")
}
if s.TokenURL == "" {
errorMessages = append(errorMessages, "Token URL is missing")
}
if s.SaasRegistryURL == "" {
errorMessages = append(errorMessages, "Saas Registry URL is missing")
}
errorMsg := strings.Join(errorMessages, ", ")
if errorMsg != "" {
return errors.New(errorMsg)
}
return nil
}