forked from IBM-Cloud/bluemix-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
85 lines (69 loc) · 2.07 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package bluemix
import (
"net/http"
"time"
"github.com/IBM-Bluemix/bluemix-go/bmxerror"
"github.com/IBM-Bluemix/bluemix-go/endpoints"
)
//ServiceName ..
type ServiceName string
const (
//AccountService ...
AccountService ServiceName = ServiceName("account")
//CfService ...
CfService ServiceName = ServiceName("cf")
//ClusterService ...
ClusterService ServiceName = ServiceName("cluster")
//UAAService ...
UAAService ServiceName = ServiceName("uaa")
//IAMService ...
IAMService ServiceName = ServiceName("iam")
)
//Config ...
type Config struct {
IBMID string
IBMIDPassword string
BluemixAPIKey string
IAMAccessToken string
IAMRefreshToken string
UAAAccessToken string
UAARefreshToken string
//Region is optional. If region is not provided then endpoint must be provided
Region string
//Endpoint is optional. If endpoint is not provided then endpoint must be obtained from region via EndpointLocator
Endpoint *string
//TokenProviderEndpoint is optional. If endpoint is not provided then endpoint must be obtained from region via EndpointLocator
TokenProviderEndpoint *string
EndpointLocator endpoints.EndpointLocator
MaxRetries *int
RetryDelay *time.Duration
HTTPTimeout time.Duration
Debug bool
HTTPClient *http.Client
SSLDisable bool
}
//Copy allows the configuration to be overriden or added
//Typically the endpoints etc
func (c *Config) Copy(cfgs ...*Config) *Config {
out := new(Config)
*out = *c
if len(cfgs) == 0 {
return out
}
for _, mergeInput := range cfgs {
if mergeInput.Endpoint != nil {
out.Endpoint = mergeInput.Endpoint
}
}
return out
}
//ValidateConfigForService ...
func (c *Config) ValidateConfigForService(svc ServiceName) error {
if (c.IBMID == "" || c.IBMIDPassword == "") && c.BluemixAPIKey == "" {
return bmxerror.New(ErrInsufficientCredentials, "Please check the documentation on how to configure the Bluemix credentials")
}
if c.Region == "" && (c.Endpoint == nil || *c.Endpoint == "") {
return bmxerror.New(ErrInvalidConfigurationCode, "Please provide region or endpoint")
}
return nil
}