-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprovider_configuration.go
252 lines (220 loc) · 11.6 KB
/
provider_configuration.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package scalr
import (
"context"
"errors"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ ProviderConfigurations = (*providerConfigurations)(nil)
// ProviderConfigurations describes all the provider configuration related methods that the Scalr API supports.
type ProviderConfigurations interface {
List(ctx context.Context, options ProviderConfigurationsListOptions) (*ProviderConfigurationsList, error)
Create(ctx context.Context, options ProviderConfigurationCreateOptions) (*ProviderConfiguration, error)
Read(ctx context.Context, configurationID string) (*ProviderConfiguration, error)
Delete(ctx context.Context, configurationID string) error
Update(ctx context.Context, configurationID string, options ProviderConfigurationUpdateOptions) (*ProviderConfiguration, error)
}
// providerConfigurations implements ProviderConfigurations.
type providerConfigurations struct {
client *Client
}
// ProviderConfigurationsList represents a list of provider configurations.
type ProviderConfigurationsList struct {
*Pagination
Items []*ProviderConfiguration
}
// ProviderConfiguration represents a Scalr provider configuration.
type ProviderConfiguration struct {
ID string `jsonapi:"primary,provider-configurations"`
Name string `jsonapi:"attr,name"`
ProviderName string `jsonapi:"attr,provider-name"`
ExportShellVariables bool `jsonapi:"attr,export-shell-variables"`
IsShared bool `jsonapi:"attr,is-shared"`
IsCustom bool `jsonapi:"attr,is-custom"`
AwsAccessKey string `jsonapi:"attr,aws-access-key"`
AwsSecretKey string `jsonapi:"attr,aws-secret-key"`
AwsAccountType string `jsonapi:"attr,aws-account-type"`
AwsCredentialsType string `jsonapi:"attr,aws-credentials-type"`
AwsTrustedEntityType string `jsonapi:"attr,aws-trusted-entity-type"`
AwsRoleArn string `jsonapi:"attr,aws-role-arn"`
AwsExternalId string `jsonapi:"attr,aws-external-id"`
AwsAudience string `jsonapi:"attr,aws-audience"`
AzurermClientId string `jsonapi:"attr,azurerm-client-id"`
AzurermClientSecret string `jsonapi:"attr,azurerm-client-secret"`
AzurermSubscriptionId string `jsonapi:"attr,azurerm-subscription-id"`
AzurermTenantId string `jsonapi:"attr,azurerm-tenant-id"`
AzurermAuthType string `jsonapi:"attr,azurerm-auth-type"`
AzurermAudience string `jsonapi:"attr,azurerm-audience"`
GoogleAuthType string `jsonapi:"attr,google-auth-type"`
GoogleServiceAccountEmail string `jsonapi:"attr,google-service-account-email"`
GoogleWorkloadProviderName string `jsonapi:"attr,google-workload-provider-name"`
GoogleProject string `jsonapi:"attr,google-project"`
GoogleCredentials string `jsonapi:"attr,google-credentials"`
GoogleUseDefaultProject bool `jsonapi:"attr,google-use-default-project"`
ScalrHostname string `jsonapi:"attr,scalr-hostname"`
ScalrToken string `jsonapi:"attr,scalr-token"`
Account *Account `jsonapi:"relation,account"`
Parameters []*ProviderConfigurationParameter `jsonapi:"relation,parameters"`
Environments []*Environment `jsonapi:"relation,environments"`
Owners []*Team `jsonapi:"relation,owners"`
}
// ProviderConfigurationsListOptions represents the options for listing provider configurations.
type ProviderConfigurationsListOptions struct {
ListOptions
Sort string `url:"sort,omitempty"`
Include string `url:"include,omitempty"`
Filter *ProviderConfigurationFilter `url:"filter,omitempty"`
}
// ProviderConfigurationFilter represents the options for filtering provider configurations.
type ProviderConfigurationFilter struct {
ProviderConfiguration string `url:"provider-configuration,omitempty"`
ProviderName string `url:"provider-name,omitempty"`
Name string `url:"name,omitempty"`
AccountID string `url:"account,omitempty"`
}
// List all the provider configurations within a scalr account.
func (s *providerConfigurations) List(ctx context.Context, options ProviderConfigurationsListOptions) (*ProviderConfigurationsList, error) {
req, err := s.client.newRequest("GET", "provider-configurations", &options)
if err != nil {
return nil, err
}
pcfgl := &ProviderConfigurationsList{}
err = s.client.do(ctx, req, pcfgl)
if err != nil {
return nil, err
}
return pcfgl, nil
}
// ProviderConfigurationCreateOptions represents the options for creating a new provider configuration.
type ProviderConfigurationCreateOptions struct {
ID string `jsonapi:"primary,provider-configurations"`
Name *string `jsonapi:"attr,name"`
ProviderName *string `jsonapi:"attr,provider-name"`
ExportShellVariables *bool `jsonapi:"attr,export-shell-variables,omitempty"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
IsCustom *bool `jsonapi:"attr,is-custom,omitempty"`
AwsAccessKey *string `jsonapi:"attr,aws-access-key,omitempty"`
AwsSecretKey *string `jsonapi:"attr,aws-secret-key,omitempty"`
AwsAccountType *string `jsonapi:"attr,aws-account-type"`
AwsCredentialsType *string `jsonapi:"attr,aws-credentials-type"`
AwsTrustedEntityType *string `jsonapi:"attr,aws-trusted-entity-type"`
AwsAudience *string `jsonapi:"attr,aws-audience"`
AwsRoleArn *string `jsonapi:"attr,aws-role-arn"`
AwsExternalId *string `jsonapi:"attr,aws-external-id"`
AzurermClientId *string `jsonapi:"attr,azurerm-client-id,omitempty"`
AzurermClientSecret *string `jsonapi:"attr,azurerm-client-secret,omitempty"`
AzurermSubscriptionId *string `jsonapi:"attr,azurerm-subscription-id,omitempty"`
AzurermTenantId *string `jsonapi:"attr,azurerm-tenant-id,omitempty"`
AzurermAuthType *string `jsonapi:"attr,azurerm-auth-type,omitempty"`
AzurermAudience *string `jsonapi:"attr,azurerm-audience,omitempty"`
GoogleAuthType *string `jsonapi:"attr,google-auth-type,omitempty"`
GoogleServiceAccountEmail *string `jsonapi:"attr,google-service-account-email,omitempty"`
GoogleWorkloadProviderName *string `jsonapi:"attr,google-workload-provider-name,omitempty"`
GoogleProject *string `jsonapi:"attr,google-project,omitempty"`
GoogleCredentials *string `jsonapi:"attr,google-credentials,omitempty"`
GoogleUseDefaultProject *bool `jsonapi:"attr,google-use-default-project,omitempty"`
ScalrHostname *string `jsonapi:"attr,scalr-hostname,omitempty"`
ScalrToken *string `jsonapi:"attr,scalr-token,omitempty"`
Account *Account `jsonapi:"relation,account,omitempty"`
Environments []*Environment `jsonapi:"relation,environments,omitempty"`
Owners []*Team `jsonapi:"relation,owners"`
}
// Create is used to create a new provider configuration.
func (s *providerConfigurations) Create(ctx context.Context, options ProviderConfigurationCreateOptions) (*ProviderConfiguration, error) {
options.ID = ""
req, err := s.client.newRequest("POST", "provider-configurations", &options)
if err != nil {
return nil, err
}
pcfg := &ProviderConfiguration{}
err = s.client.do(ctx, req, pcfg)
if err != nil {
return nil, err
}
return pcfg, nil
}
// Read a provider configuration by configuration ID.
func (s *providerConfigurations) Read(ctx context.Context, configurationID string) (*ProviderConfiguration, error) {
if !validStringID(&configurationID) {
return nil, errors.New("invalid value for provider configuration ID")
}
options := struct {
Include string `url:"include"`
}{
Include: "parameters",
}
url_path := fmt.Sprintf("provider-configurations/%s", url.QueryEscape(configurationID))
req, err := s.client.newRequest("GET", url_path, options)
if err != nil {
return nil, err
}
config := &ProviderConfiguration{}
err = s.client.do(ctx, req, config)
if err != nil {
return nil, err
}
return config, nil
}
// ProviderConfigurationUpdateOptions represents the options for updating a provider configuration.
type ProviderConfigurationUpdateOptions struct {
ID string `jsonapi:"primary,provider-configurations"`
Name *string `jsonapi:"attr,name"`
IsShared *bool `jsonapi:"attr,is-shared,omitempty"`
Environments []*Environment `jsonapi:"relation,environments"`
ExportShellVariables *bool `jsonapi:"attr,export-shell-variables"`
AwsAccessKey *string `jsonapi:"attr,aws-access-key"`
AwsSecretKey *string `jsonapi:"attr,aws-secret-key"`
AwsAccountType *string `jsonapi:"attr,aws-account-type"`
AwsCredentialsType *string `jsonapi:"attr,aws-credentials-type"`
AwsTrustedEntityType *string `jsonapi:"attr,aws-trusted-entity-type"`
AwsRoleArn *string `jsonapi:"attr,aws-role-arn"`
AwsExternalId *string `jsonapi:"attr,aws-external-id"`
AwsAudience *string `jsonapi:"attr,aws-audience"`
AzurermAuthType *string `jsonapi:"attr,azurerm-auth-type"`
AzurermAudience *string `jsonapi:"attr,azurerm-audience"`
AzurermClientId *string `jsonapi:"attr,azurerm-client-id"`
AzurermClientSecret *string `jsonapi:"attr,azurerm-client-secret"`
AzurermSubscriptionId *string `jsonapi:"attr,azurerm-subscription-id"`
AzurermTenantId *string `jsonapi:"attr,azurerm-tenant-id"`
GoogleAuthType *string `jsonapi:"attr,google-auth-type"`
GoogleServiceAccountEmail *string `jsonapi:"attr,google-service-account-email"`
GoogleWorkloadProviderName *string `jsonapi:"attr,google-workload-provider-name"`
GoogleProject *string `jsonapi:"attr,google-project"`
GoogleCredentials *string `jsonapi:"attr,google-credentials"`
GoogleUseDefaultProject *bool `jsonapi:"attr,google-use-default-project,omitempty"`
ScalrHostname *string `jsonapi:"attr,scalr-hostname"`
ScalrToken *string `jsonapi:"attr,scalr-token"`
Owners []*Team `jsonapi:"relation,owners"`
}
// Update an existing provider configuration.
func (s *providerConfigurations) Update(ctx context.Context, configurationID string, options ProviderConfigurationUpdateOptions) (*ProviderConfiguration, error) {
if !validStringID(&configurationID) {
return nil, errors.New("invalid value for provider configuration ID")
}
// Make sure we don't send a user provided ID.
options.ID = ""
url_path := fmt.Sprintf("provider-configurations/%s", url.QueryEscape(configurationID))
req, err := s.client.newRequest("PATCH", url_path, &options)
if err != nil {
return nil, err
}
configuration := &ProviderConfiguration{}
err = s.client.do(ctx, req, configuration)
if err != nil {
return nil, err
}
return configuration, nil
}
// Delete deletes a provider configuration by its ID.
func (s *providerConfigurations) Delete(ctx context.Context, configurationID string) error {
if !validStringID(&configurationID) {
return errors.New("invalid value for provider configuration ID")
}
url_path := fmt.Sprintf("provider-configurations/%s", url.QueryEscape(configurationID))
req, err := s.client.newRequest("DELETE", url_path, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}