1package azurestack
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// CustomerSubscriptionsClient is the azure Stack
29type CustomerSubscriptionsClient struct {
30	BaseClient
31}
32
33// NewCustomerSubscriptionsClient creates an instance of the CustomerSubscriptionsClient client.
34func NewCustomerSubscriptionsClient(subscriptionID string) CustomerSubscriptionsClient {
35	return NewCustomerSubscriptionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewCustomerSubscriptionsClientWithBaseURI creates an instance of the CustomerSubscriptionsClient client using a
39// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
40// Azure stack).
41func NewCustomerSubscriptionsClientWithBaseURI(baseURI string, subscriptionID string) CustomerSubscriptionsClient {
42	return CustomerSubscriptionsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Create creates a new customer subscription under a registration.
46// Parameters:
47// resourceGroup - name of the resource group.
48// registrationName - name of the Azure Stack registration.
49// customerSubscriptionName - name of the product.
50// customerCreationParameters - parameters use to create a customer subscription.
51func (client CustomerSubscriptionsClient) Create(ctx context.Context, resourceGroup string, registrationName string, customerSubscriptionName string, customerCreationParameters CustomerSubscription) (result CustomerSubscription, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/CustomerSubscriptionsClient.Create")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	req, err := client.CreatePreparer(ctx, resourceGroup, registrationName, customerSubscriptionName, customerCreationParameters)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Create", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.CreateSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Create", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.CreateResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Create", resp, "Failure responding to request")
78	}
79
80	return
81}
82
83// CreatePreparer prepares the Create request.
84func (client CustomerSubscriptionsClient) CreatePreparer(ctx context.Context, resourceGroup string, registrationName string, customerSubscriptionName string, customerCreationParameters CustomerSubscription) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"customerSubscriptionName": autorest.Encode("path", customerSubscriptionName),
87		"registrationName":         autorest.Encode("path", registrationName),
88		"resourceGroup":            autorest.Encode("path", resourceGroup),
89		"subscriptionId":           autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2017-06-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsContentType("application/json; charset=utf-8"),
99		autorest.AsPut(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}/customerSubscriptions/{customerSubscriptionName}", pathParameters),
102		autorest.WithJSON(customerCreationParameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// CreateSender sends the Create request. The method will close the
108// http.Response Body if it receives an error.
109func (client CustomerSubscriptionsClient) CreateSender(req *http.Request) (*http.Response, error) {
110	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111}
112
113// CreateResponder handles the response to the Create request. The method always
114// closes the http.Response Body.
115func (client CustomerSubscriptionsClient) CreateResponder(resp *http.Response) (result CustomerSubscription, err error) {
116	err = autorest.Respond(
117		resp,
118		client.ByInspecting(),
119		azure.WithErrorUnlessStatusCode(http.StatusOK),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// Delete deletes a customer subscription under a registration.
127// Parameters:
128// resourceGroup - name of the resource group.
129// registrationName - name of the Azure Stack registration.
130// customerSubscriptionName - name of the product.
131func (client CustomerSubscriptionsClient) Delete(ctx context.Context, resourceGroup string, registrationName string, customerSubscriptionName string) (result autorest.Response, err error) {
132	if tracing.IsEnabled() {
133		ctx = tracing.StartSpan(ctx, fqdn+"/CustomerSubscriptionsClient.Delete")
134		defer func() {
135			sc := -1
136			if result.Response != nil {
137				sc = result.Response.StatusCode
138			}
139			tracing.EndSpan(ctx, sc, err)
140		}()
141	}
142	req, err := client.DeletePreparer(ctx, resourceGroup, registrationName, customerSubscriptionName)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Delete", nil, "Failure preparing request")
145		return
146	}
147
148	resp, err := client.DeleteSender(req)
149	if err != nil {
150		result.Response = resp
151		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Delete", resp, "Failure sending request")
152		return
153	}
154
155	result, err = client.DeleteResponder(resp)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Delete", resp, "Failure responding to request")
158	}
159
160	return
161}
162
163// DeletePreparer prepares the Delete request.
164func (client CustomerSubscriptionsClient) DeletePreparer(ctx context.Context, resourceGroup string, registrationName string, customerSubscriptionName string) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"customerSubscriptionName": autorest.Encode("path", customerSubscriptionName),
167		"registrationName":         autorest.Encode("path", registrationName),
168		"resourceGroup":            autorest.Encode("path", resourceGroup),
169		"subscriptionId":           autorest.Encode("path", client.SubscriptionID),
170	}
171
172	const APIVersion = "2017-06-01"
173	queryParameters := map[string]interface{}{
174		"api-version": APIVersion,
175	}
176
177	preparer := autorest.CreatePreparer(
178		autorest.AsDelete(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}/customerSubscriptions/{customerSubscriptionName}", pathParameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// DeleteSender sends the Delete request. The method will close the
186// http.Response Body if it receives an error.
187func (client CustomerSubscriptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
188	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
189}
190
191// DeleteResponder handles the response to the Delete request. The method always
192// closes the http.Response Body.
193func (client CustomerSubscriptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
194	err = autorest.Respond(
195		resp,
196		client.ByInspecting(),
197		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
198		autorest.ByClosing())
199	result.Response = resp
200	return
201}
202
203// Get returns the specified product.
204// Parameters:
205// resourceGroup - name of the resource group.
206// registrationName - name of the Azure Stack registration.
207// customerSubscriptionName - name of the product.
208func (client CustomerSubscriptionsClient) Get(ctx context.Context, resourceGroup string, registrationName string, customerSubscriptionName string) (result CustomerSubscription, err error) {
209	if tracing.IsEnabled() {
210		ctx = tracing.StartSpan(ctx, fqdn+"/CustomerSubscriptionsClient.Get")
211		defer func() {
212			sc := -1
213			if result.Response.Response != nil {
214				sc = result.Response.Response.StatusCode
215			}
216			tracing.EndSpan(ctx, sc, err)
217		}()
218	}
219	req, err := client.GetPreparer(ctx, resourceGroup, registrationName, customerSubscriptionName)
220	if err != nil {
221		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Get", nil, "Failure preparing request")
222		return
223	}
224
225	resp, err := client.GetSender(req)
226	if err != nil {
227		result.Response = autorest.Response{Response: resp}
228		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Get", resp, "Failure sending request")
229		return
230	}
231
232	result, err = client.GetResponder(resp)
233	if err != nil {
234		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "Get", resp, "Failure responding to request")
235	}
236
237	return
238}
239
240// GetPreparer prepares the Get request.
241func (client CustomerSubscriptionsClient) GetPreparer(ctx context.Context, resourceGroup string, registrationName string, customerSubscriptionName string) (*http.Request, error) {
242	pathParameters := map[string]interface{}{
243		"customerSubscriptionName": autorest.Encode("path", customerSubscriptionName),
244		"registrationName":         autorest.Encode("path", registrationName),
245		"resourceGroup":            autorest.Encode("path", resourceGroup),
246		"subscriptionId":           autorest.Encode("path", client.SubscriptionID),
247	}
248
249	const APIVersion = "2017-06-01"
250	queryParameters := map[string]interface{}{
251		"api-version": APIVersion,
252	}
253
254	preparer := autorest.CreatePreparer(
255		autorest.AsGet(),
256		autorest.WithBaseURL(client.BaseURI),
257		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}/customerSubscriptions/{customerSubscriptionName}", pathParameters),
258		autorest.WithQueryParameters(queryParameters))
259	return preparer.Prepare((&http.Request{}).WithContext(ctx))
260}
261
262// GetSender sends the Get request. The method will close the
263// http.Response Body if it receives an error.
264func (client CustomerSubscriptionsClient) GetSender(req *http.Request) (*http.Response, error) {
265	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
266}
267
268// GetResponder handles the response to the Get request. The method always
269// closes the http.Response Body.
270func (client CustomerSubscriptionsClient) GetResponder(resp *http.Response) (result CustomerSubscription, err error) {
271	err = autorest.Respond(
272		resp,
273		client.ByInspecting(),
274		azure.WithErrorUnlessStatusCode(http.StatusOK),
275		autorest.ByUnmarshallingJSON(&result),
276		autorest.ByClosing())
277	result.Response = autorest.Response{Response: resp}
278	return
279}
280
281// List returns a list of products.
282// Parameters:
283// resourceGroup - name of the resource group.
284// registrationName - name of the Azure Stack registration.
285func (client CustomerSubscriptionsClient) List(ctx context.Context, resourceGroup string, registrationName string) (result CustomerSubscriptionListPage, err error) {
286	if tracing.IsEnabled() {
287		ctx = tracing.StartSpan(ctx, fqdn+"/CustomerSubscriptionsClient.List")
288		defer func() {
289			sc := -1
290			if result.csl.Response.Response != nil {
291				sc = result.csl.Response.Response.StatusCode
292			}
293			tracing.EndSpan(ctx, sc, err)
294		}()
295	}
296	result.fn = client.listNextResults
297	req, err := client.ListPreparer(ctx, resourceGroup, registrationName)
298	if err != nil {
299		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "List", nil, "Failure preparing request")
300		return
301	}
302
303	resp, err := client.ListSender(req)
304	if err != nil {
305		result.csl.Response = autorest.Response{Response: resp}
306		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "List", resp, "Failure sending request")
307		return
308	}
309
310	result.csl, err = client.ListResponder(resp)
311	if err != nil {
312		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "List", resp, "Failure responding to request")
313	}
314
315	return
316}
317
318// ListPreparer prepares the List request.
319func (client CustomerSubscriptionsClient) ListPreparer(ctx context.Context, resourceGroup string, registrationName string) (*http.Request, error) {
320	pathParameters := map[string]interface{}{
321		"registrationName": autorest.Encode("path", registrationName),
322		"resourceGroup":    autorest.Encode("path", resourceGroup),
323		"subscriptionId":   autorest.Encode("path", client.SubscriptionID),
324	}
325
326	const APIVersion = "2017-06-01"
327	queryParameters := map[string]interface{}{
328		"api-version": APIVersion,
329	}
330
331	preparer := autorest.CreatePreparer(
332		autorest.AsGet(),
333		autorest.WithBaseURL(client.BaseURI),
334		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}/customerSubscriptions", pathParameters),
335		autorest.WithQueryParameters(queryParameters))
336	return preparer.Prepare((&http.Request{}).WithContext(ctx))
337}
338
339// ListSender sends the List request. The method will close the
340// http.Response Body if it receives an error.
341func (client CustomerSubscriptionsClient) ListSender(req *http.Request) (*http.Response, error) {
342	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
343}
344
345// ListResponder handles the response to the List request. The method always
346// closes the http.Response Body.
347func (client CustomerSubscriptionsClient) ListResponder(resp *http.Response) (result CustomerSubscriptionList, err error) {
348	err = autorest.Respond(
349		resp,
350		client.ByInspecting(),
351		azure.WithErrorUnlessStatusCode(http.StatusOK),
352		autorest.ByUnmarshallingJSON(&result),
353		autorest.ByClosing())
354	result.Response = autorest.Response{Response: resp}
355	return
356}
357
358// listNextResults retrieves the next set of results, if any.
359func (client CustomerSubscriptionsClient) listNextResults(ctx context.Context, lastResults CustomerSubscriptionList) (result CustomerSubscriptionList, err error) {
360	req, err := lastResults.customerSubscriptionListPreparer(ctx)
361	if err != nil {
362		return result, autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "listNextResults", nil, "Failure preparing next results request")
363	}
364	if req == nil {
365		return
366	}
367	resp, err := client.ListSender(req)
368	if err != nil {
369		result.Response = autorest.Response{Response: resp}
370		return result, autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "listNextResults", resp, "Failure sending next results request")
371	}
372	result, err = client.ListResponder(resp)
373	if err != nil {
374		err = autorest.NewErrorWithError(err, "azurestack.CustomerSubscriptionsClient", "listNextResults", resp, "Failure responding to next results request")
375	}
376	return
377}
378
379// ListComplete enumerates all values, automatically crossing page boundaries as required.
380func (client CustomerSubscriptionsClient) ListComplete(ctx context.Context, resourceGroup string, registrationName string) (result CustomerSubscriptionListIterator, err error) {
381	if tracing.IsEnabled() {
382		ctx = tracing.StartSpan(ctx, fqdn+"/CustomerSubscriptionsClient.List")
383		defer func() {
384			sc := -1
385			if result.Response().Response.Response != nil {
386				sc = result.page.Response().Response.Response.StatusCode
387			}
388			tracing.EndSpan(ctx, sc, err)
389		}()
390	}
391	result.page, err = client.List(ctx, resourceGroup, registrationName)
392	return
393}
394