/
reservationssummaries_client.go
241 lines (227 loc) · 12.2 KB
/
reservationssummaries_client.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
//go:build go1.18
// +build go1.18
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
package armconsumption
import (
"context"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"net/http"
"net/url"
"strings"
)
// ReservationsSummariesClient contains the methods for the ReservationsSummaries group.
// Don't use this type directly, use NewReservationsSummariesClient() instead.
type ReservationsSummariesClient struct {
internal *arm.Client
}
// NewReservationsSummariesClient creates a new instance of ReservationsSummariesClient with the specified values.
// - credential - used to authorize requests. Usually a credential from azidentity.
// - options - pass nil to accept the default values.
func NewReservationsSummariesClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*ReservationsSummariesClient, error) {
cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
if err != nil {
return nil, err
}
client := &ReservationsSummariesClient{
internal: cl,
}
return client, nil
}
// NewListPager - Lists the reservations summaries for the defined scope daily or monthly grain.
//
// Generated from API version 2021-10-01
// - resourceScope - The scope associated with reservations summaries operations. This includes '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}'
// for BillingAccount scope (legacy), and
// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for BillingProfile
// scope (modern).
// - grain - Can be daily or monthly
// - options - ReservationsSummariesClientListOptions contains the optional parameters for the ReservationsSummariesClient.NewListPager
// method.
func (client *ReservationsSummariesClient) NewListPager(resourceScope string, grain Datagrain, options *ReservationsSummariesClientListOptions) *runtime.Pager[ReservationsSummariesClientListResponse] {
return runtime.NewPager(runtime.PagingHandler[ReservationsSummariesClientListResponse]{
More: func(page ReservationsSummariesClientListResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *ReservationsSummariesClientListResponse) (ReservationsSummariesClientListResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ReservationsSummariesClient.NewListPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listCreateRequest(ctx, resourceScope, grain, options)
}, nil)
if err != nil {
return ReservationsSummariesClientListResponse{}, err
}
return client.listHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listCreateRequest creates the List request.
func (client *ReservationsSummariesClient) listCreateRequest(ctx context.Context, resourceScope string, grain Datagrain, options *ReservationsSummariesClientListOptions) (*policy.Request, error) {
urlPath := "/{resourceScope}/providers/Microsoft.Consumption/reservationSummaries"
urlPath = strings.ReplaceAll(urlPath, "{resourceScope}", resourceScope)
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("grain", string(grain))
if options != nil && options.StartDate != nil {
reqQP.Set("startDate", *options.StartDate)
}
if options != nil && options.EndDate != nil {
reqQP.Set("endDate", *options.EndDate)
}
if options != nil && options.Filter != nil {
reqQP.Set("$filter", *options.Filter)
}
if options != nil && options.ReservationID != nil {
reqQP.Set("reservationId", *options.ReservationID)
}
if options != nil && options.ReservationOrderID != nil {
reqQP.Set("reservationOrderId", *options.ReservationOrderID)
}
reqQP.Set("api-version", "2021-10-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listHandleResponse handles the List response.
func (client *ReservationsSummariesClient) listHandleResponse(resp *http.Response) (ReservationsSummariesClientListResponse, error) {
result := ReservationsSummariesClientListResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.ReservationSummariesListResult); err != nil {
return ReservationsSummariesClientListResponse{}, err
}
return result, nil
}
// NewListByReservationOrderPager - Lists the reservations summaries for daily or monthly grain.
//
// Generated from API version 2021-10-01
// - reservationOrderID - Order Id of the reservation
// - grain - Can be daily or monthly
// - options - ReservationsSummariesClientListByReservationOrderOptions contains the optional parameters for the ReservationsSummariesClient.NewListByReservationOrderPager
// method.
func (client *ReservationsSummariesClient) NewListByReservationOrderPager(reservationOrderID string, grain Datagrain, options *ReservationsSummariesClientListByReservationOrderOptions) *runtime.Pager[ReservationsSummariesClientListByReservationOrderResponse] {
return runtime.NewPager(runtime.PagingHandler[ReservationsSummariesClientListByReservationOrderResponse]{
More: func(page ReservationsSummariesClientListByReservationOrderResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *ReservationsSummariesClientListByReservationOrderResponse) (ReservationsSummariesClientListByReservationOrderResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ReservationsSummariesClient.NewListByReservationOrderPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listByReservationOrderCreateRequest(ctx, reservationOrderID, grain, options)
}, nil)
if err != nil {
return ReservationsSummariesClientListByReservationOrderResponse{}, err
}
return client.listByReservationOrderHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listByReservationOrderCreateRequest creates the ListByReservationOrder request.
func (client *ReservationsSummariesClient) listByReservationOrderCreateRequest(ctx context.Context, reservationOrderID string, grain Datagrain, options *ReservationsSummariesClientListByReservationOrderOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Capacity/reservationorders/{reservationOrderId}/providers/Microsoft.Consumption/reservationSummaries"
if reservationOrderID == "" {
return nil, errors.New("parameter reservationOrderID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{reservationOrderId}", url.PathEscape(reservationOrderID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("grain", string(grain))
if options != nil && options.Filter != nil {
reqQP.Set("$filter", *options.Filter)
}
reqQP.Set("api-version", "2021-10-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listByReservationOrderHandleResponse handles the ListByReservationOrder response.
func (client *ReservationsSummariesClient) listByReservationOrderHandleResponse(resp *http.Response) (ReservationsSummariesClientListByReservationOrderResponse, error) {
result := ReservationsSummariesClientListByReservationOrderResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.ReservationSummariesListResult); err != nil {
return ReservationsSummariesClientListByReservationOrderResponse{}, err
}
return result, nil
}
// NewListByReservationOrderAndReservationPager - Lists the reservations summaries for daily or monthly grain.
//
// Generated from API version 2021-10-01
// - reservationOrderID - Order Id of the reservation
// - reservationID - Id of the reservation
// - grain - Can be daily or monthly
// - options - ReservationsSummariesClientListByReservationOrderAndReservationOptions contains the optional parameters for the
// ReservationsSummariesClient.NewListByReservationOrderAndReservationPager method.
func (client *ReservationsSummariesClient) NewListByReservationOrderAndReservationPager(reservationOrderID string, reservationID string, grain Datagrain, options *ReservationsSummariesClientListByReservationOrderAndReservationOptions) *runtime.Pager[ReservationsSummariesClientListByReservationOrderAndReservationResponse] {
return runtime.NewPager(runtime.PagingHandler[ReservationsSummariesClientListByReservationOrderAndReservationResponse]{
More: func(page ReservationsSummariesClientListByReservationOrderAndReservationResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *ReservationsSummariesClientListByReservationOrderAndReservationResponse) (ReservationsSummariesClientListByReservationOrderAndReservationResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "ReservationsSummariesClient.NewListByReservationOrderAndReservationPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listByReservationOrderAndReservationCreateRequest(ctx, reservationOrderID, reservationID, grain, options)
}, nil)
if err != nil {
return ReservationsSummariesClientListByReservationOrderAndReservationResponse{}, err
}
return client.listByReservationOrderAndReservationHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listByReservationOrderAndReservationCreateRequest creates the ListByReservationOrderAndReservation request.
func (client *ReservationsSummariesClient) listByReservationOrderAndReservationCreateRequest(ctx context.Context, reservationOrderID string, reservationID string, grain Datagrain, options *ReservationsSummariesClientListByReservationOrderAndReservationOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Capacity/reservationorders/{reservationOrderId}/reservations/{reservationId}/providers/Microsoft.Consumption/reservationSummaries"
if reservationOrderID == "" {
return nil, errors.New("parameter reservationOrderID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{reservationOrderId}", url.PathEscape(reservationOrderID))
if reservationID == "" {
return nil, errors.New("parameter reservationID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{reservationId}", url.PathEscape(reservationID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("grain", string(grain))
if options != nil && options.Filter != nil {
reqQP.Set("$filter", *options.Filter)
}
reqQP.Set("api-version", "2021-10-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listByReservationOrderAndReservationHandleResponse handles the ListByReservationOrderAndReservation response.
func (client *ReservationsSummariesClient) listByReservationOrderAndReservationHandleResponse(resp *http.Response) (ReservationsSummariesClientListByReservationOrderAndReservationResponse, error) {
result := ReservationsSummariesClientListByReservationOrderAndReservationResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.ReservationSummariesListResult); err != nil {
return ReservationsSummariesClientListByReservationOrderAndReservationResponse{}, err
}
return result, nil
}