1 package subscriptions
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/tracing"
14 "net/http"
15 )
16
17
18
19
20 type Client struct {
21 BaseClient
22 }
23
24
25 func NewClient() Client {
26 return NewClientWithBaseURI(DefaultBaseURI)
27 }
28
29
30
31 func NewClientWithBaseURI(baseURI string) Client {
32 return Client{NewWithBaseURI(baseURI)}
33 }
34
35
36
37
38 func (client Client) Get(ctx context.Context, subscriptionID string) (result Subscription, err error) {
39 if tracing.IsEnabled() {
40 ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get")
41 defer func() {
42 sc := -1
43 if result.Response.Response != nil {
44 sc = result.Response.Response.StatusCode
45 }
46 tracing.EndSpan(ctx, sc, err)
47 }()
48 }
49 req, err := client.GetPreparer(ctx, subscriptionID)
50 if err != nil {
51 err = autorest.NewErrorWithError(err, "subscriptions.Client", "Get", nil, "Failure preparing request")
52 return
53 }
54
55 resp, err := client.GetSender(req)
56 if err != nil {
57 result.Response = autorest.Response{Response: resp}
58 err = autorest.NewErrorWithError(err, "subscriptions.Client", "Get", resp, "Failure sending request")
59 return
60 }
61
62 result, err = client.GetResponder(resp)
63 if err != nil {
64 err = autorest.NewErrorWithError(err, "subscriptions.Client", "Get", resp, "Failure responding to request")
65 return
66 }
67
68 return
69 }
70
71
72 func (client Client) GetPreparer(ctx context.Context, subscriptionID string) (*http.Request, error) {
73 pathParameters := map[string]interface{}{
74 "subscriptionId": autorest.Encode("path", subscriptionID),
75 }
76
77 const APIVersion = "2021-01-01"
78 queryParameters := map[string]interface{}{
79 "api-version": APIVersion,
80 }
81
82 preparer := autorest.CreatePreparer(
83 autorest.AsGet(),
84 autorest.WithBaseURL(client.BaseURI),
85 autorest.WithPathParameters("/subscriptions/{subscriptionId}", pathParameters),
86 autorest.WithQueryParameters(queryParameters))
87 return preparer.Prepare((&http.Request{}).WithContext(ctx))
88 }
89
90
91
92 func (client Client) GetSender(req *http.Request) (*http.Response, error) {
93 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
94 }
95
96
97
98 func (client Client) GetResponder(resp *http.Response) (result Subscription, err error) {
99 err = autorest.Respond(
100 resp,
101 azure.WithErrorUnlessStatusCode(http.StatusOK),
102 autorest.ByUnmarshallingJSON(&result),
103 autorest.ByClosing())
104 result.Response = autorest.Response{Response: resp}
105 return
106 }
107
108
109 func (client Client) List(ctx context.Context) (result ListResultPage, err error) {
110 if tracing.IsEnabled() {
111 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
112 defer func() {
113 sc := -1
114 if result.lr.Response.Response != nil {
115 sc = result.lr.Response.Response.StatusCode
116 }
117 tracing.EndSpan(ctx, sc, err)
118 }()
119 }
120 result.fn = client.listNextResults
121 req, err := client.ListPreparer(ctx)
122 if err != nil {
123 err = autorest.NewErrorWithError(err, "subscriptions.Client", "List", nil, "Failure preparing request")
124 return
125 }
126
127 resp, err := client.ListSender(req)
128 if err != nil {
129 result.lr.Response = autorest.Response{Response: resp}
130 err = autorest.NewErrorWithError(err, "subscriptions.Client", "List", resp, "Failure sending request")
131 return
132 }
133
134 result.lr, err = client.ListResponder(resp)
135 if err != nil {
136 err = autorest.NewErrorWithError(err, "subscriptions.Client", "List", resp, "Failure responding to request")
137 return
138 }
139 if result.lr.hasNextLink() && result.lr.IsEmpty() {
140 err = result.NextWithContext(ctx)
141 return
142 }
143
144 return
145 }
146
147
148 func (client Client) ListPreparer(ctx context.Context) (*http.Request, error) {
149 const APIVersion = "2021-01-01"
150 queryParameters := map[string]interface{}{
151 "api-version": APIVersion,
152 }
153
154 preparer := autorest.CreatePreparer(
155 autorest.AsGet(),
156 autorest.WithBaseURL(client.BaseURI),
157 autorest.WithPath("/subscriptions"),
158 autorest.WithQueryParameters(queryParameters))
159 return preparer.Prepare((&http.Request{}).WithContext(ctx))
160 }
161
162
163
164 func (client Client) ListSender(req *http.Request) (*http.Response, error) {
165 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
166 }
167
168
169
170 func (client Client) ListResponder(resp *http.Response) (result ListResult, err error) {
171 err = autorest.Respond(
172 resp,
173 azure.WithErrorUnlessStatusCode(http.StatusOK),
174 autorest.ByUnmarshallingJSON(&result),
175 autorest.ByClosing())
176 result.Response = autorest.Response{Response: resp}
177 return
178 }
179
180
181 func (client Client) listNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) {
182 req, err := lastResults.listResultPreparer(ctx)
183 if err != nil {
184 return result, autorest.NewErrorWithError(err, "subscriptions.Client", "listNextResults", nil, "Failure preparing next results request")
185 }
186 if req == nil {
187 return
188 }
189 resp, err := client.ListSender(req)
190 if err != nil {
191 result.Response = autorest.Response{Response: resp}
192 return result, autorest.NewErrorWithError(err, "subscriptions.Client", "listNextResults", resp, "Failure sending next results request")
193 }
194 result, err = client.ListResponder(resp)
195 if err != nil {
196 err = autorest.NewErrorWithError(err, "subscriptions.Client", "listNextResults", resp, "Failure responding to next results request")
197 }
198 return
199 }
200
201
202 func (client Client) ListComplete(ctx context.Context) (result ListResultIterator, err error) {
203 if tracing.IsEnabled() {
204 ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
205 defer func() {
206 sc := -1
207 if result.Response().Response.Response != nil {
208 sc = result.page.Response().Response.Response.StatusCode
209 }
210 tracing.EndSpan(ctx, sc, err)
211 }()
212 }
213 result.page, err = client.List(ctx)
214 return
215 }
216
217
218
219
220
221
222 func (client Client) ListLocations(ctx context.Context, subscriptionID string, includeExtendedLocations *bool) (result LocationListResult, err error) {
223 if tracing.IsEnabled() {
224 ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListLocations")
225 defer func() {
226 sc := -1
227 if result.Response.Response != nil {
228 sc = result.Response.Response.StatusCode
229 }
230 tracing.EndSpan(ctx, sc, err)
231 }()
232 }
233 req, err := client.ListLocationsPreparer(ctx, subscriptionID, includeExtendedLocations)
234 if err != nil {
235 err = autorest.NewErrorWithError(err, "subscriptions.Client", "ListLocations", nil, "Failure preparing request")
236 return
237 }
238
239 resp, err := client.ListLocationsSender(req)
240 if err != nil {
241 result.Response = autorest.Response{Response: resp}
242 err = autorest.NewErrorWithError(err, "subscriptions.Client", "ListLocations", resp, "Failure sending request")
243 return
244 }
245
246 result, err = client.ListLocationsResponder(resp)
247 if err != nil {
248 err = autorest.NewErrorWithError(err, "subscriptions.Client", "ListLocations", resp, "Failure responding to request")
249 return
250 }
251
252 return
253 }
254
255
256 func (client Client) ListLocationsPreparer(ctx context.Context, subscriptionID string, includeExtendedLocations *bool) (*http.Request, error) {
257 pathParameters := map[string]interface{}{
258 "subscriptionId": autorest.Encode("path", subscriptionID),
259 }
260
261 const APIVersion = "2021-01-01"
262 queryParameters := map[string]interface{}{
263 "api-version": APIVersion,
264 }
265 if includeExtendedLocations != nil {
266 queryParameters["includeExtendedLocations"] = autorest.Encode("query", *includeExtendedLocations)
267 }
268
269 preparer := autorest.CreatePreparer(
270 autorest.AsGet(),
271 autorest.WithBaseURL(client.BaseURI),
272 autorest.WithPathParameters("/subscriptions/{subscriptionId}/locations", pathParameters),
273 autorest.WithQueryParameters(queryParameters))
274 return preparer.Prepare((&http.Request{}).WithContext(ctx))
275 }
276
277
278
279 func (client Client) ListLocationsSender(req *http.Request) (*http.Response, error) {
280 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
281 }
282
283
284
285 func (client Client) ListLocationsResponder(resp *http.Response) (result LocationListResult, err error) {
286 err = autorest.Respond(
287 resp,
288 azure.WithErrorUnlessStatusCode(http.StatusOK),
289 autorest.ByUnmarshallingJSON(&result),
290 autorest.ByClosing())
291 result.Response = autorest.Response{Response: resp}
292 return
293 }
294
View as plain text