-
Notifications
You must be signed in to change notification settings - Fork 3
/
provider_configuration_parameter.go
168 lines (134 loc) · 5.96 KB
/
provider_configuration_parameter.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
package scalr
import (
"context"
"errors"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ ProviderConfigurationParameters = (*providerConfigurationParameters)(nil)
// ProviderConfigurationParameters describes all the provider configurartion parameter related methods that the Scalr API supports.
type ProviderConfigurationParameters interface {
List(ctx context.Context, configurationID string, options ProviderConfigurationParametersListOptions) (*ProviderConfigurationParametersList, error)
Create(ctx context.Context, configurationID string, options ProviderConfigurationParameterCreateOptions) (*ProviderConfigurationParameter, error)
Read(ctx context.Context, parameterID string) (*ProviderConfigurationParameter, error)
Delete(ctx context.Context, parameterID string) error
Update(ctx context.Context, parameterID string, options ProviderConfigurationParameterUpdateOptions) (*ProviderConfigurationParameter, error)
}
// providerConfigurationParameters implements ProviderConfigurationParameters.
type providerConfigurationParameters struct {
client *Client
}
// ProviderConfigurationParametersList represents a list of provider configuration parameters.
type ProviderConfigurationParametersList struct {
*Pagination
Items []*ProviderConfigurationParameter
}
// ProviderConfigurationParameter represents a Scalr provider configuration parameter.
type ProviderConfigurationParameter struct {
ID string `jsonapi:"primary,provider-configuration-parameters"`
Key string `jsonapi:"attr,key"`
Sensitive bool `jsonapi:"attr,sensitive"`
Value string `jsonapi:"attr,value"`
Description string `jsonapi:"attr,description"`
}
// ProviderConfigurationParametersListOptions represents the options for listing provider configuration parameters.
type ProviderConfigurationParametersListOptions struct {
ListOptions
Sort string `url:"sort,omitempty"`
}
// List all the parameters of the provider configuration.
func (s *providerConfigurationParameters) List(ctx context.Context, configurationID string, options ProviderConfigurationParametersListOptions) (*ProviderConfigurationParametersList, error) {
if !validStringID(&configurationID) {
return nil, errors.New("invalid value for provider configuration ID")
}
url_path := fmt.Sprintf("provider-configurations/%s/parameters", url.QueryEscape(configurationID))
req, err := s.client.newRequest("GET", url_path, &options)
if err != nil {
return nil, err
}
parametersList := &ProviderConfigurationParametersList{}
err = s.client.do(ctx, req, parametersList)
if err != nil {
return nil, err
}
return parametersList, nil
}
// ProviderConfigurationParameterCreateOptions represents the options for creating a new provider configuration parameter.
type ProviderConfigurationParameterCreateOptions struct {
ID string `jsonapi:"primary,provider-configuration-parameters"`
Key *string `jsonapi:"attr,key"`
Sensitive *bool `jsonapi:"attr,sensitive,omitempty"`
Value *string `jsonapi:"attr,value"`
Description *string `jsonapi:"attr,description,omitempty"`
}
// Create is used to create a new provider configuration parameter.
func (s *providerConfigurationParameters) Create(ctx context.Context, configurationID string, options ProviderConfigurationParameterCreateOptions) (*ProviderConfigurationParameter, error) {
options.ID = ""
url_path := fmt.Sprintf("provider-configurations/%s/parameters", url.QueryEscape(configurationID))
req, err := s.client.newRequest("POST", url_path, &options)
if err != nil {
return nil, err
}
parameter := &ProviderConfigurationParameter{}
err = s.client.do(ctx, req, parameter)
if err != nil {
return nil, err
}
return parameter, nil
}
// Read a provider configuration parameter by parameter ID.
func (s *providerConfigurationParameters) Read(ctx context.Context, parameterID string) (*ProviderConfigurationParameter, error) {
if !validStringID(¶meterID) {
return nil, errors.New("invalid value for provider configuration parameter ID")
}
url_path := fmt.Sprintf("provider-configuration-parameters/%s", url.QueryEscape(parameterID))
req, err := s.client.newRequest("GET", url_path, nil)
if err != nil {
return nil, err
}
parameter := &ProviderConfigurationParameter{}
err = s.client.do(ctx, req, parameter)
if err != nil {
return nil, err
}
return parameter, nil
}
// ProviderConfigurationParameterUpdateOptions represents the options for updating a provider configuration.
type ProviderConfigurationParameterUpdateOptions struct {
ID string `jsonapi:"primary,provider-configuration-parameters"`
Key *string `jsonapi:"attr,key,omitempty"`
Sensitive *bool `jsonapi:"attr,sensitive,omitempty"`
Value *string `jsonapi:"attr,value,omitempty"`
Description *string `jsonapi:"attr,description,omitempty"`
}
// Update an existing provider configuration parameter.
func (s *providerConfigurationParameters) Update(ctx context.Context, parameterID string, options ProviderConfigurationParameterUpdateOptions) (*ProviderConfigurationParameter, error) {
options.ID = ""
if !validStringID(¶meterID) {
return nil, errors.New("invalid value for provider configuration parameter ID")
}
url_path := fmt.Sprintf("provider-configuration-parameters/%s", url.QueryEscape(parameterID))
req, err := s.client.newRequest("PATCH", url_path, &options)
if err != nil {
return nil, err
}
parameter := &ProviderConfigurationParameter{}
err = s.client.do(ctx, req, parameter)
if err != nil {
return nil, err
}
return parameter, nil
}
// Delete deletes a provider configuration parameter by its ID.
func (s *providerConfigurationParameters) Delete(ctx context.Context, parameterID string) error {
if !validStringID(¶meterID) {
return errors.New("invalid value for provider parameter ID")
}
url_path := fmt.Sprintf("provider-configuration-parameters/%s", url.QueryEscape(parameterID))
req, err := s.client.newRequest("DELETE", url_path, nil)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}