-
Notifications
You must be signed in to change notification settings - Fork 510
/
options.go
191 lines (162 loc) · 4.69 KB
/
options.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package clouds
import (
"io"
"github.com/gophercloud/gophercloud"
)
type cloudOpts struct {
cloudName string
locations []string
cloudsyamlReader io.Reader
secureyamlReader io.Reader
applicationCredentialID string
applicationCredentialName string
applicationCredentialSecret string
authURL string
domainID string
domainName string
endpointType string
password string
projectID string
projectName string
region string
scope *gophercloud.AuthScope
token string
userID string
username string
caCertPath string
clientCertPath string
clientKeyPath string
insecure *bool
}
// ParseOption one of parse configuration returned by With* modifier
type ParseOption = func(*cloudOpts)
// WithCloudName allows to override the environment variable `OS_CLOUD`.
func WithCloudName(osCloud string) ParseOption {
return func(co *cloudOpts) {
co.cloudName = osCloud
}
}
// WithLocations is a functional option that sets the search locations for the
// clouds.yaml file (and its optional companion secure.yaml). Each location is
// a file path pointing to a possible `clouds.yaml`.
func WithLocations(locations ...string) ParseOption {
return func(co *cloudOpts) {
co.locations = locations
}
}
// WithCloudsYAML is a functional option that lets you pass a clouds.yaml file
// as an io.Reader interface. When this option is passed, FromCloudsYaml will
// not attempt to fetch any file from the file system. To add a secure.yaml,
// use in conjunction with WithSecureYAML.
func WithCloudsYAML(clouds io.Reader) ParseOption {
return func(co *cloudOpts) {
co.cloudsyamlReader = clouds
}
}
// WithSecureYAML is a functional option that lets you pass a secure.yaml file
// as an io.Reader interface, to complement the clouds.yaml that is either
// fetched from the filesystem, or passed with WithCloudsYAML.
func WithSecureYAML(secure io.Reader) ParseOption {
return func(co *cloudOpts) {
co.secureyamlReader = secure
}
}
func WithApplicationCredentialID(applicationCredentialID string) ParseOption {
return func(co *cloudOpts) {
co.applicationCredentialID = applicationCredentialID
}
}
func WithApplicationCredentialName(applicationCredentialName string) ParseOption {
return func(co *cloudOpts) {
co.applicationCredentialName = applicationCredentialName
}
}
func WithApplicationCredentialSecret(applicationCredentialSecret string) ParseOption {
return func(co *cloudOpts) {
co.applicationCredentialSecret = applicationCredentialSecret
}
}
func WithIdentityEndpoint(authURL string) ParseOption {
return func(co *cloudOpts) {
co.authURL = authURL
}
}
func WithDomainID(domainID string) ParseOption {
return func(co *cloudOpts) {
co.domainID = domainID
}
}
func WithDomainName(domainName string) ParseOption {
return func(co *cloudOpts) {
co.domainName = domainName
}
}
// WithRegion allows to override the endpoint type set in clouds.yaml or in the
// environment variable `OS_INTERFACE`.
func WithEndpointType(endpointType string) ParseOption {
return func(co *cloudOpts) {
co.endpointType = endpointType
}
}
func WithPassword(password string) ParseOption {
return func(co *cloudOpts) {
co.password = password
}
}
func WithProjectID(projectID string) ParseOption {
return func(co *cloudOpts) {
co.projectID = projectID
}
}
func WithProjectName(projectName string) ParseOption {
return func(co *cloudOpts) {
co.projectName = projectName
}
}
// WithRegion allows to override the region set in clouds.yaml or in the
// environment variable `OS_REGION_NAME`
func WithRegion(region string) ParseOption {
return func(co *cloudOpts) {
co.region = region
}
}
func WithScope(scope *gophercloud.AuthScope) ParseOption {
return func(co *cloudOpts) {
co.scope = scope
}
}
func WithToken(token string) ParseOption {
return func(co *cloudOpts) {
co.token = token
}
}
func WithUserID(userID string) ParseOption {
return func(co *cloudOpts) {
co.userID = userID
}
}
func WithUsername(username string) ParseOption {
return func(co *cloudOpts) {
co.username = username
}
}
func WithCACertPath(caCertPath string) ParseOption {
return func(co *cloudOpts) {
co.caCertPath = caCertPath
}
}
func WithClientCertPath(clientCertPath string) ParseOption {
return func(co *cloudOpts) {
co.clientCertPath = clientCertPath
}
}
func WithClientKeyPath(clientKeyPath string) ParseOption {
return func(co *cloudOpts) {
co.clientKeyPath = clientKeyPath
}
}
func WithInsecure(insecure bool) ParseOption {
return func(co *cloudOpts) {
co.insecure = &insecure
}
}