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/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// RegistrationsClient is the azure Stack
30type RegistrationsClient struct {
31	BaseClient
32}
33
34// NewRegistrationsClient creates an instance of the RegistrationsClient client.
35func NewRegistrationsClient(subscriptionID string) RegistrationsClient {
36	return NewRegistrationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewRegistrationsClientWithBaseURI creates an instance of the RegistrationsClient client using a custom endpoint.
40// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewRegistrationsClientWithBaseURI(baseURI string, subscriptionID string) RegistrationsClient {
42	return RegistrationsClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// CreateOrUpdate create or update an Azure Stack registration.
46// Parameters:
47// resourceGroup - name of the resource group.
48// registrationName - name of the Azure Stack registration.
49// tokenParameter - registration token
50func (client RegistrationsClient) CreateOrUpdate(ctx context.Context, resourceGroup string, registrationName string, tokenParameter RegistrationParameter) (result Registration, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.CreateOrUpdate")
53		defer func() {
54			sc := -1
55			if result.Response.Response != nil {
56				sc = result.Response.Response.StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	if err := validation.Validate([]validation.Validation{
62		{TargetValue: tokenParameter,
63			Constraints: []validation.Constraint{{Target: "tokenParameter.RegistrationParameterProperties", Name: validation.Null, Rule: false,
64				Chain: []validation.Constraint{{Target: "tokenParameter.RegistrationParameterProperties.RegistrationToken", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
65		return result, validation.NewError("azurestack.RegistrationsClient", "CreateOrUpdate", err.Error())
66	}
67
68	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroup, registrationName, tokenParameter)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "CreateOrUpdate", nil, "Failure preparing request")
71		return
72	}
73
74	resp, err := client.CreateOrUpdateSender(req)
75	if err != nil {
76		result.Response = autorest.Response{Response: resp}
77		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "CreateOrUpdate", resp, "Failure sending request")
78		return
79	}
80
81	result, err = client.CreateOrUpdateResponder(resp)
82	if err != nil {
83		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "CreateOrUpdate", resp, "Failure responding to request")
84	}
85
86	return
87}
88
89// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
90func (client RegistrationsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroup string, registrationName string, tokenParameter RegistrationParameter) (*http.Request, error) {
91	pathParameters := map[string]interface{}{
92		"registrationName": autorest.Encode("path", registrationName),
93		"resourceGroup":    autorest.Encode("path", resourceGroup),
94		"subscriptionId":   autorest.Encode("path", client.SubscriptionID),
95	}
96
97	const APIVersion = "2017-06-01"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100	}
101
102	preparer := autorest.CreatePreparer(
103		autorest.AsContentType("application/json; charset=utf-8"),
104		autorest.AsPut(),
105		autorest.WithBaseURL(client.BaseURI),
106		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}", pathParameters),
107		autorest.WithJSON(tokenParameter),
108		autorest.WithQueryParameters(queryParameters))
109	return preparer.Prepare((&http.Request{}).WithContext(ctx))
110}
111
112// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
113// http.Response Body if it receives an error.
114func (client RegistrationsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
115	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
116}
117
118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
119// closes the http.Response Body.
120func (client RegistrationsClient) CreateOrUpdateResponder(resp *http.Response) (result Registration, err error) {
121	err = autorest.Respond(
122		resp,
123		client.ByInspecting(),
124		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
125		autorest.ByUnmarshallingJSON(&result),
126		autorest.ByClosing())
127	result.Response = autorest.Response{Response: resp}
128	return
129}
130
131// Delete delete the requested Azure Stack registration.
132// Parameters:
133// resourceGroup - name of the resource group.
134// registrationName - name of the Azure Stack registration.
135func (client RegistrationsClient) Delete(ctx context.Context, resourceGroup string, registrationName string) (result autorest.Response, err error) {
136	if tracing.IsEnabled() {
137		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.Delete")
138		defer func() {
139			sc := -1
140			if result.Response != nil {
141				sc = result.Response.StatusCode
142			}
143			tracing.EndSpan(ctx, sc, err)
144		}()
145	}
146	req, err := client.DeletePreparer(ctx, resourceGroup, registrationName)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Delete", nil, "Failure preparing request")
149		return
150	}
151
152	resp, err := client.DeleteSender(req)
153	if err != nil {
154		result.Response = resp
155		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Delete", resp, "Failure sending request")
156		return
157	}
158
159	result, err = client.DeleteResponder(resp)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Delete", resp, "Failure responding to request")
162	}
163
164	return
165}
166
167// DeletePreparer prepares the Delete request.
168func (client RegistrationsClient) DeletePreparer(ctx context.Context, resourceGroup string, registrationName string) (*http.Request, error) {
169	pathParameters := map[string]interface{}{
170		"registrationName": autorest.Encode("path", registrationName),
171		"resourceGroup":    autorest.Encode("path", resourceGroup),
172		"subscriptionId":   autorest.Encode("path", client.SubscriptionID),
173	}
174
175	const APIVersion = "2017-06-01"
176	queryParameters := map[string]interface{}{
177		"api-version": APIVersion,
178	}
179
180	preparer := autorest.CreatePreparer(
181		autorest.AsDelete(),
182		autorest.WithBaseURL(client.BaseURI),
183		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}", pathParameters),
184		autorest.WithQueryParameters(queryParameters))
185	return preparer.Prepare((&http.Request{}).WithContext(ctx))
186}
187
188// DeleteSender sends the Delete request. The method will close the
189// http.Response Body if it receives an error.
190func (client RegistrationsClient) DeleteSender(req *http.Request) (*http.Response, error) {
191	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
192}
193
194// DeleteResponder handles the response to the Delete request. The method always
195// closes the http.Response Body.
196func (client RegistrationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
197	err = autorest.Respond(
198		resp,
199		client.ByInspecting(),
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
201		autorest.ByClosing())
202	result.Response = resp
203	return
204}
205
206// Get returns the properties of an Azure Stack registration.
207// Parameters:
208// resourceGroup - name of the resource group.
209// registrationName - name of the Azure Stack registration.
210func (client RegistrationsClient) Get(ctx context.Context, resourceGroup string, registrationName string) (result Registration, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.Get")
213		defer func() {
214			sc := -1
215			if result.Response.Response != nil {
216				sc = result.Response.Response.StatusCode
217			}
218			tracing.EndSpan(ctx, sc, err)
219		}()
220	}
221	req, err := client.GetPreparer(ctx, resourceGroup, registrationName)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Get", nil, "Failure preparing request")
224		return
225	}
226
227	resp, err := client.GetSender(req)
228	if err != nil {
229		result.Response = autorest.Response{Response: resp}
230		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Get", resp, "Failure sending request")
231		return
232	}
233
234	result, err = client.GetResponder(resp)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Get", resp, "Failure responding to request")
237	}
238
239	return
240}
241
242// GetPreparer prepares the Get request.
243func (client RegistrationsClient) GetPreparer(ctx context.Context, resourceGroup string, registrationName string) (*http.Request, error) {
244	pathParameters := map[string]interface{}{
245		"registrationName": autorest.Encode("path", registrationName),
246		"resourceGroup":    autorest.Encode("path", resourceGroup),
247		"subscriptionId":   autorest.Encode("path", client.SubscriptionID),
248	}
249
250	const APIVersion = "2017-06-01"
251	queryParameters := map[string]interface{}{
252		"api-version": APIVersion,
253	}
254
255	preparer := autorest.CreatePreparer(
256		autorest.AsGet(),
257		autorest.WithBaseURL(client.BaseURI),
258		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}", pathParameters),
259		autorest.WithQueryParameters(queryParameters))
260	return preparer.Prepare((&http.Request{}).WithContext(ctx))
261}
262
263// GetSender sends the Get request. The method will close the
264// http.Response Body if it receives an error.
265func (client RegistrationsClient) GetSender(req *http.Request) (*http.Response, error) {
266	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
267}
268
269// GetResponder handles the response to the Get request. The method always
270// closes the http.Response Body.
271func (client RegistrationsClient) GetResponder(resp *http.Response) (result Registration, err error) {
272	err = autorest.Respond(
273		resp,
274		client.ByInspecting(),
275		azure.WithErrorUnlessStatusCode(http.StatusOK),
276		autorest.ByUnmarshallingJSON(&result),
277		autorest.ByClosing())
278	result.Response = autorest.Response{Response: resp}
279	return
280}
281
282// GetActivationKey returns Azure Stack Activation Key.
283// Parameters:
284// resourceGroup - name of the resource group.
285// registrationName - name of the Azure Stack registration.
286func (client RegistrationsClient) GetActivationKey(ctx context.Context, resourceGroup string, registrationName string) (result ActivationKeyResult, err error) {
287	if tracing.IsEnabled() {
288		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.GetActivationKey")
289		defer func() {
290			sc := -1
291			if result.Response.Response != nil {
292				sc = result.Response.Response.StatusCode
293			}
294			tracing.EndSpan(ctx, sc, err)
295		}()
296	}
297	req, err := client.GetActivationKeyPreparer(ctx, resourceGroup, registrationName)
298	if err != nil {
299		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "GetActivationKey", nil, "Failure preparing request")
300		return
301	}
302
303	resp, err := client.GetActivationKeySender(req)
304	if err != nil {
305		result.Response = autorest.Response{Response: resp}
306		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "GetActivationKey", resp, "Failure sending request")
307		return
308	}
309
310	result, err = client.GetActivationKeyResponder(resp)
311	if err != nil {
312		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "GetActivationKey", resp, "Failure responding to request")
313	}
314
315	return
316}
317
318// GetActivationKeyPreparer prepares the GetActivationKey request.
319func (client RegistrationsClient) GetActivationKeyPreparer(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.AsPost(),
333		autorest.WithBaseURL(client.BaseURI),
334		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}/getactivationkey", pathParameters),
335		autorest.WithQueryParameters(queryParameters))
336	return preparer.Prepare((&http.Request{}).WithContext(ctx))
337}
338
339// GetActivationKeySender sends the GetActivationKey request. The method will close the
340// http.Response Body if it receives an error.
341func (client RegistrationsClient) GetActivationKeySender(req *http.Request) (*http.Response, error) {
342	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
343}
344
345// GetActivationKeyResponder handles the response to the GetActivationKey request. The method always
346// closes the http.Response Body.
347func (client RegistrationsClient) GetActivationKeyResponder(resp *http.Response) (result ActivationKeyResult, 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// List returns a list of all registrations.
359// Parameters:
360// resourceGroup - name of the resource group.
361func (client RegistrationsClient) List(ctx context.Context, resourceGroup string) (result RegistrationListPage, err error) {
362	if tracing.IsEnabled() {
363		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.List")
364		defer func() {
365			sc := -1
366			if result.rl.Response.Response != nil {
367				sc = result.rl.Response.Response.StatusCode
368			}
369			tracing.EndSpan(ctx, sc, err)
370		}()
371	}
372	result.fn = client.listNextResults
373	req, err := client.ListPreparer(ctx, resourceGroup)
374	if err != nil {
375		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "List", nil, "Failure preparing request")
376		return
377	}
378
379	resp, err := client.ListSender(req)
380	if err != nil {
381		result.rl.Response = autorest.Response{Response: resp}
382		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "List", resp, "Failure sending request")
383		return
384	}
385
386	result.rl, err = client.ListResponder(resp)
387	if err != nil {
388		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "List", resp, "Failure responding to request")
389	}
390
391	return
392}
393
394// ListPreparer prepares the List request.
395func (client RegistrationsClient) ListPreparer(ctx context.Context, resourceGroup string) (*http.Request, error) {
396	pathParameters := map[string]interface{}{
397		"resourceGroup":  autorest.Encode("path", resourceGroup),
398		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
399	}
400
401	const APIVersion = "2017-06-01"
402	queryParameters := map[string]interface{}{
403		"api-version": APIVersion,
404	}
405
406	preparer := autorest.CreatePreparer(
407		autorest.AsGet(),
408		autorest.WithBaseURL(client.BaseURI),
409		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations", pathParameters),
410		autorest.WithQueryParameters(queryParameters))
411	return preparer.Prepare((&http.Request{}).WithContext(ctx))
412}
413
414// ListSender sends the List request. The method will close the
415// http.Response Body if it receives an error.
416func (client RegistrationsClient) ListSender(req *http.Request) (*http.Response, error) {
417	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
418}
419
420// ListResponder handles the response to the List request. The method always
421// closes the http.Response Body.
422func (client RegistrationsClient) ListResponder(resp *http.Response) (result RegistrationList, err error) {
423	err = autorest.Respond(
424		resp,
425		client.ByInspecting(),
426		azure.WithErrorUnlessStatusCode(http.StatusOK),
427		autorest.ByUnmarshallingJSON(&result),
428		autorest.ByClosing())
429	result.Response = autorest.Response{Response: resp}
430	return
431}
432
433// listNextResults retrieves the next set of results, if any.
434func (client RegistrationsClient) listNextResults(ctx context.Context, lastResults RegistrationList) (result RegistrationList, err error) {
435	req, err := lastResults.registrationListPreparer(ctx)
436	if err != nil {
437		return result, autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "listNextResults", nil, "Failure preparing next results request")
438	}
439	if req == nil {
440		return
441	}
442	resp, err := client.ListSender(req)
443	if err != nil {
444		result.Response = autorest.Response{Response: resp}
445		return result, autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "listNextResults", resp, "Failure sending next results request")
446	}
447	result, err = client.ListResponder(resp)
448	if err != nil {
449		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "listNextResults", resp, "Failure responding to next results request")
450	}
451	return
452}
453
454// ListComplete enumerates all values, automatically crossing page boundaries as required.
455func (client RegistrationsClient) ListComplete(ctx context.Context, resourceGroup string) (result RegistrationListIterator, err error) {
456	if tracing.IsEnabled() {
457		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.List")
458		defer func() {
459			sc := -1
460			if result.Response().Response.Response != nil {
461				sc = result.page.Response().Response.Response.StatusCode
462			}
463			tracing.EndSpan(ctx, sc, err)
464		}()
465	}
466	result.page, err = client.List(ctx, resourceGroup)
467	return
468}
469
470// Update patch an Azure Stack registration.
471// Parameters:
472// resourceGroup - name of the resource group.
473// registrationName - name of the Azure Stack registration.
474// tokenParameter - registration token
475func (client RegistrationsClient) Update(ctx context.Context, resourceGroup string, registrationName string, tokenParameter RegistrationParameter) (result Registration, err error) {
476	if tracing.IsEnabled() {
477		ctx = tracing.StartSpan(ctx, fqdn+"/RegistrationsClient.Update")
478		defer func() {
479			sc := -1
480			if result.Response.Response != nil {
481				sc = result.Response.Response.StatusCode
482			}
483			tracing.EndSpan(ctx, sc, err)
484		}()
485	}
486	req, err := client.UpdatePreparer(ctx, resourceGroup, registrationName, tokenParameter)
487	if err != nil {
488		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Update", nil, "Failure preparing request")
489		return
490	}
491
492	resp, err := client.UpdateSender(req)
493	if err != nil {
494		result.Response = autorest.Response{Response: resp}
495		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Update", resp, "Failure sending request")
496		return
497	}
498
499	result, err = client.UpdateResponder(resp)
500	if err != nil {
501		err = autorest.NewErrorWithError(err, "azurestack.RegistrationsClient", "Update", resp, "Failure responding to request")
502	}
503
504	return
505}
506
507// UpdatePreparer prepares the Update request.
508func (client RegistrationsClient) UpdatePreparer(ctx context.Context, resourceGroup string, registrationName string, tokenParameter RegistrationParameter) (*http.Request, error) {
509	pathParameters := map[string]interface{}{
510		"registrationName": autorest.Encode("path", registrationName),
511		"resourceGroup":    autorest.Encode("path", resourceGroup),
512		"subscriptionId":   autorest.Encode("path", client.SubscriptionID),
513	}
514
515	const APIVersion = "2017-06-01"
516	queryParameters := map[string]interface{}{
517		"api-version": APIVersion,
518	}
519
520	preparer := autorest.CreatePreparer(
521		autorest.AsContentType("application/json; charset=utf-8"),
522		autorest.AsPatch(),
523		autorest.WithBaseURL(client.BaseURI),
524		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.AzureStack/registrations/{registrationName}", pathParameters),
525		autorest.WithJSON(tokenParameter),
526		autorest.WithQueryParameters(queryParameters))
527	return preparer.Prepare((&http.Request{}).WithContext(ctx))
528}
529
530// UpdateSender sends the Update request. The method will close the
531// http.Response Body if it receives an error.
532func (client RegistrationsClient) UpdateSender(req *http.Request) (*http.Response, error) {
533	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
534}
535
536// UpdateResponder handles the response to the Update request. The method always
537// closes the http.Response Body.
538func (client RegistrationsClient) UpdateResponder(resp *http.Response) (result Registration, err error) {
539	err = autorest.Respond(
540		resp,
541		client.ByInspecting(),
542		azure.WithErrorUnlessStatusCode(http.StatusOK),
543		autorest.ByUnmarshallingJSON(&result),
544		autorest.ByClosing())
545	result.Response = autorest.Response{Response: resp}
546	return
547}
548