-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.go
48 lines (40 loc) · 1.06 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
45
46
47
48
// this file holds configuration for both STACKIT and Auth clients
// once the Auth client is retired, related code will be removed
package client
import (
"errors"
"net/url"
"github.com/SchwarzIT/community-stackit-go-client/pkg/consts"
)
// Config is the STACKIT client configuration
type Config struct {
BaseUrl *url.URL
ServiceAccountToken string
ServiceAccountEmail string
}
// Validate verifies that the given config is valid
func (c *Config) Validate() error {
if c.BaseUrl == nil {
c.SetURL("") // set default
}
if c.ServiceAccountToken == "" {
return errors.New("Service Account Access Token cannot be empty")
}
if c.ServiceAccountEmail == "" {
return errors.New("Service Account Email cannot be empty")
}
return nil
}
// SetURL sets a given url string as the base url in the config
// if the given value is empty, the default base URL will be used
func (c *Config) SetURL(value string) error {
if value == "" {
value = consts.DEFAULT_BASE_URL
}
u, err := url.Parse(value)
if err != nil {
return err
}
c.BaseUrl = u
return nil
}