-
Notifications
You must be signed in to change notification settings - Fork 8
/
plans.go
361 lines (304 loc) · 11.2 KB
/
plans.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Package plans provides primitives to interact with the openapi HTTP API.
//
// Code generated by dev.azure.com/schwarzit/schwarzit.odj.core/_git/stackit-client-generator.git version v1.0.23 DO NOT EDIT.
package plans
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"github.com/pkg/errors"
"github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/runtime"
openapiTypes "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/types"
contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts"
"github.com/SchwarzIT/community-stackit-go-client/pkg/validate"
)
const (
BearerAuthScopes = "bearerAuth.Scopes"
)
// Offerings defines model for Offerings.
type Offerings struct {
Description string `json:"description"`
DocumentationURL string `json:"documentationUrl"`
ImageURL string `json:"imageUrl"`
Name string `json:"name"`
Plans []PlanModelUI `json:"plans"`
Tags []string `json:"tags"`
}
// PermissionDenied defines model for PermissionDenied.
type PermissionDenied struct {
Detail string `json:"detail"`
}
// Plan defines model for Plan.
type Plan struct {
Message string `json:"message"`
Plans []PlanModelUI `json:"plans"`
}
// PlanModelUI defines model for PlanModelUI.
type PlanModelUI struct {
AlertMatchers int `json:"alertMatchers"`
AlertReceivers int `json:"alertReceivers"`
AlertRules int `json:"alertRules"`
Amount *float32 `json:"amount,omitempty"`
BucketSize int `json:"bucketSize"`
Description *string `json:"description,omitempty"`
GrafanaGlobalDashboards int `json:"grafanaGlobalDashboards"`
GrafanaGlobalOrgs int `json:"grafanaGlobalOrgs"`
GrafanaGlobalSessions int `json:"grafanaGlobalSessions"`
GrafanaGlobalUsers int `json:"grafanaGlobalUsers"`
ID openapiTypes.UUID `json:"id"`
IsFree *bool `json:"isFree,omitempty"`
IsPublic *bool `json:"isPublic,omitempty"`
LogsAlert int `json:"logsAlert"`
LogsStorage int `json:"logsStorage"`
Name *string `json:"name,omitempty"`
PlanID openapiTypes.UUID `json:"planId"`
SamplesPerScrape int `json:"samplesPerScrape"`
Schema *string `json:"schema,omitempty"`
TargetNumber int `json:"targetNumber"`
TracesStorage int `json:"tracesStorage"`
}
// RequestEditorFn is the function signature for the RequestEditor callback function
type RequestEditorFn func(ctx context.Context, req *http.Request) error
// Client which conforms to the OpenAPI3 specification for this service.
type Client struct {
// The endpoint of the server conforming to this interface, with scheme,
// https://api.deepmap.com for example. This can contain a path relative
// to the server, such as https://api.deepmap.com/dev-test, and all the
// paths in the swagger spec will be appended to the server.
Server string
// Doer for performing requests, typically a *http.Client with any
// customized settings, such as certificate chains.
Client contracts.BaseClientInterface
}
// NewRawClient Creates a new Client, with reasonable defaults
func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client {
// create a client with sane default values
client := Client{
Server: server,
Client: httpClient,
}
return &client
}
// The interface specification for the client above.
type rawClientInterface interface {
// ListOfferings request
ListOfferingsRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error)
// ListPlans request
ListPlansRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error)
}
func (c *Client) ListOfferingsRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewListOfferingsRequest(ctx, c.Server, projectID)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
func (c *Client) ListPlansRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewListPlansRequest(ctx, c.Server, projectID)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// NewListOfferingsRequest generates requests for ListOfferings
func NewListOfferingsRequest(ctx context.Context, server string, projectID string) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID)
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/projects/%s/offerings", pathParam0)
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
// NewListPlansRequest generates requests for ListPlans
func NewListPlansRequest(ctx context.Context, server string, projectID string) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID)
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/projects/%s/plans", pathParam0)
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error {
for _, r := range additionalEditors {
if err := r(ctx, req); err != nil {
return err
}
}
return nil
}
// ClientWithResponses builds on rawClientInterface to offer response payloads
type ClientWithResponses struct {
rawClientInterface
}
// NewClient creates a new ClientWithResponses, which wraps
// Client with return type handling
func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses {
return &ClientWithResponses{NewRawClient(server, httpClient)}
}
// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {
// ListOfferings request
ListOfferings(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*ListOfferingsResponse, error)
// ListPlans request
ListPlans(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*ListPlansResponse, error)
}
type ListOfferingsResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *Offerings
JSON403 *PermissionDenied
Error error // Aggregated error
}
// Status returns HTTPResponse.Status
func (r ListOfferingsResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r ListOfferingsResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
type ListPlansResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *Plan
JSON403 *PermissionDenied
Error error // Aggregated error
}
// Status returns HTTPResponse.Status
func (r ListPlansResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r ListPlansResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ListOfferings request returning *ListOfferingsResponse
func (c *ClientWithResponses) ListOfferings(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*ListOfferingsResponse, error) {
rsp, err := c.ListOfferingsRaw(ctx, projectID, reqEditors...)
if err != nil {
return nil, err
}
return c.ParseListOfferingsResponse(rsp)
}
// ListPlans request returning *ListPlansResponse
func (c *ClientWithResponses) ListPlans(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*ListPlansResponse, error) {
rsp, err := c.ListPlansRaw(ctx, projectID, reqEditors...)
if err != nil {
return nil, err
}
return c.ParseListPlansResponse(rsp)
}
// ParseListOfferingsResponse parses an HTTP response from a ListOfferings call
func (c *ClientWithResponses) ParseListOfferingsResponse(rsp *http.Response) (*ListOfferingsResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &ListOfferingsResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
response.Error = validate.DefaultResponseErrorHandler(rsp)
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest Offerings
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes)))
}
response.JSON200 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403:
var dest PermissionDenied
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes)))
}
response.JSON403 = &dest
}
return response, validate.ResponseObject(response)
}
// ParseListPlansResponse parses an HTTP response from a ListPlans call
func (c *ClientWithResponses) ParseListPlansResponse(rsp *http.Response) (*ListPlansResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &ListPlansResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
response.Error = validate.DefaultResponseErrorHandler(rsp)
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest Plan
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes)))
}
response.JSON200 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403:
var dest PermissionDenied
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes)))
}
response.JSON403 = &dest
}
return response, validate.ResponseObject(response)
}