1package subscription
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// AliasClient is the the subscription client
19type AliasClient struct {
20	BaseClient
21}
22
23// NewAliasClient creates an instance of the AliasClient client.
24func NewAliasClient() AliasClient {
25	return NewAliasClientWithBaseURI(DefaultBaseURI)
26}
27
28// NewAliasClientWithBaseURI creates an instance of the AliasClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAliasClientWithBaseURI(baseURI string) AliasClient {
31	return AliasClient{NewWithBaseURI(baseURI)}
32}
33
34// Create create Alias Subscription.
35// Parameters:
36// aliasName - alias Name
37func (client AliasClient) Create(ctx context.Context, aliasName string, body PutAliasRequest) (result AliasCreateFuture, err error) {
38	if tracing.IsEnabled() {
39		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.Create")
40		defer func() {
41			sc := -1
42			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
43				sc = result.FutureAPI.Response().StatusCode
44			}
45			tracing.EndSpan(ctx, sc, err)
46		}()
47	}
48	if err := validation.Validate([]validation.Validation{
49		{TargetValue: body,
50			Constraints: []validation.Constraint{{Target: "body.Properties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
51		return result, validation.NewError("subscription.AliasClient", "Create", err.Error())
52	}
53
54	req, err := client.CreatePreparer(ctx, aliasName, body)
55	if err != nil {
56		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Create", nil, "Failure preparing request")
57		return
58	}
59
60	result, err = client.CreateSender(req)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Create", nil, "Failure sending request")
63		return
64	}
65
66	return
67}
68
69// CreatePreparer prepares the Create request.
70func (client AliasClient) CreatePreparer(ctx context.Context, aliasName string, body PutAliasRequest) (*http.Request, error) {
71	pathParameters := map[string]interface{}{
72		"aliasName": autorest.Encode("path", aliasName),
73	}
74
75	const APIVersion = "2020-09-01"
76	queryParameters := map[string]interface{}{
77		"api-version": APIVersion,
78	}
79
80	preparer := autorest.CreatePreparer(
81		autorest.AsContentType("application/json; charset=utf-8"),
82		autorest.AsPut(),
83		autorest.WithBaseURL(client.BaseURI),
84		autorest.WithPathParameters("/providers/Microsoft.Subscription/aliases/{aliasName}", pathParameters),
85		autorest.WithJSON(body),
86		autorest.WithQueryParameters(queryParameters))
87	return preparer.Prepare((&http.Request{}).WithContext(ctx))
88}
89
90// CreateSender sends the Create request. The method will close the
91// http.Response Body if it receives an error.
92func (client AliasClient) CreateSender(req *http.Request) (future AliasCreateFuture, err error) {
93	var resp *http.Response
94	resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
95	if err != nil {
96		return
97	}
98	var azf azure.Future
99	azf, err = azure.NewFutureFromResponse(resp)
100	future.FutureAPI = &azf
101	future.Result = future.result
102	return
103}
104
105// CreateResponder handles the response to the Create request. The method always
106// closes the http.Response Body.
107func (client AliasClient) CreateResponder(resp *http.Response) (result PutAliasResponse, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
111		autorest.ByUnmarshallingJSON(&result),
112		autorest.ByClosing())
113	result.Response = autorest.Response{Response: resp}
114	return
115}
116
117// Delete delete Alias.
118// Parameters:
119// aliasName - alias Name
120func (client AliasClient) Delete(ctx context.Context, aliasName string) (result autorest.Response, err error) {
121	if tracing.IsEnabled() {
122		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.Delete")
123		defer func() {
124			sc := -1
125			if result.Response != nil {
126				sc = result.Response.StatusCode
127			}
128			tracing.EndSpan(ctx, sc, err)
129		}()
130	}
131	req, err := client.DeletePreparer(ctx, aliasName)
132	if err != nil {
133		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Delete", nil, "Failure preparing request")
134		return
135	}
136
137	resp, err := client.DeleteSender(req)
138	if err != nil {
139		result.Response = resp
140		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Delete", resp, "Failure sending request")
141		return
142	}
143
144	result, err = client.DeleteResponder(resp)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Delete", resp, "Failure responding to request")
147		return
148	}
149
150	return
151}
152
153// DeletePreparer prepares the Delete request.
154func (client AliasClient) DeletePreparer(ctx context.Context, aliasName string) (*http.Request, error) {
155	pathParameters := map[string]interface{}{
156		"aliasName": autorest.Encode("path", aliasName),
157	}
158
159	const APIVersion = "2020-09-01"
160	queryParameters := map[string]interface{}{
161		"api-version": APIVersion,
162	}
163
164	preparer := autorest.CreatePreparer(
165		autorest.AsDelete(),
166		autorest.WithBaseURL(client.BaseURI),
167		autorest.WithPathParameters("/providers/Microsoft.Subscription/aliases/{aliasName}", pathParameters),
168		autorest.WithQueryParameters(queryParameters))
169	return preparer.Prepare((&http.Request{}).WithContext(ctx))
170}
171
172// DeleteSender sends the Delete request. The method will close the
173// http.Response Body if it receives an error.
174func (client AliasClient) DeleteSender(req *http.Request) (*http.Response, error) {
175	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
176}
177
178// DeleteResponder handles the response to the Delete request. The method always
179// closes the http.Response Body.
180func (client AliasClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
181	err = autorest.Respond(
182		resp,
183		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
184		autorest.ByClosing())
185	result.Response = resp
186	return
187}
188
189// Get get Alias Subscription.
190// Parameters:
191// aliasName - alias Name
192func (client AliasClient) Get(ctx context.Context, aliasName string) (result PutAliasResponse, err error) {
193	if tracing.IsEnabled() {
194		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.Get")
195		defer func() {
196			sc := -1
197			if result.Response.Response != nil {
198				sc = result.Response.Response.StatusCode
199			}
200			tracing.EndSpan(ctx, sc, err)
201		}()
202	}
203	req, err := client.GetPreparer(ctx, aliasName)
204	if err != nil {
205		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Get", nil, "Failure preparing request")
206		return
207	}
208
209	resp, err := client.GetSender(req)
210	if err != nil {
211		result.Response = autorest.Response{Response: resp}
212		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Get", resp, "Failure sending request")
213		return
214	}
215
216	result, err = client.GetResponder(resp)
217	if err != nil {
218		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "Get", resp, "Failure responding to request")
219		return
220	}
221
222	return
223}
224
225// GetPreparer prepares the Get request.
226func (client AliasClient) GetPreparer(ctx context.Context, aliasName string) (*http.Request, error) {
227	pathParameters := map[string]interface{}{
228		"aliasName": autorest.Encode("path", aliasName),
229	}
230
231	const APIVersion = "2020-09-01"
232	queryParameters := map[string]interface{}{
233		"api-version": APIVersion,
234	}
235
236	preparer := autorest.CreatePreparer(
237		autorest.AsGet(),
238		autorest.WithBaseURL(client.BaseURI),
239		autorest.WithPathParameters("/providers/Microsoft.Subscription/aliases/{aliasName}", pathParameters),
240		autorest.WithQueryParameters(queryParameters))
241	return preparer.Prepare((&http.Request{}).WithContext(ctx))
242}
243
244// GetSender sends the Get request. The method will close the
245// http.Response Body if it receives an error.
246func (client AliasClient) GetSender(req *http.Request) (*http.Response, error) {
247	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
248}
249
250// GetResponder handles the response to the Get request. The method always
251// closes the http.Response Body.
252func (client AliasClient) GetResponder(resp *http.Response) (result PutAliasResponse, err error) {
253	err = autorest.Respond(
254		resp,
255		azure.WithErrorUnlessStatusCode(http.StatusOK),
256		autorest.ByUnmarshallingJSON(&result),
257		autorest.ByClosing())
258	result.Response = autorest.Response{Response: resp}
259	return
260}
261
262// List get Alias Subscription.
263func (client AliasClient) List(ctx context.Context) (result PutAliasListResult, err error) {
264	if tracing.IsEnabled() {
265		ctx = tracing.StartSpan(ctx, fqdn+"/AliasClient.List")
266		defer func() {
267			sc := -1
268			if result.Response.Response != nil {
269				sc = result.Response.Response.StatusCode
270			}
271			tracing.EndSpan(ctx, sc, err)
272		}()
273	}
274	req, err := client.ListPreparer(ctx)
275	if err != nil {
276		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "List", nil, "Failure preparing request")
277		return
278	}
279
280	resp, err := client.ListSender(req)
281	if err != nil {
282		result.Response = autorest.Response{Response: resp}
283		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "List", resp, "Failure sending request")
284		return
285	}
286
287	result, err = client.ListResponder(resp)
288	if err != nil {
289		err = autorest.NewErrorWithError(err, "subscription.AliasClient", "List", resp, "Failure responding to request")
290		return
291	}
292
293	return
294}
295
296// ListPreparer prepares the List request.
297func (client AliasClient) ListPreparer(ctx context.Context) (*http.Request, error) {
298	const APIVersion = "2020-09-01"
299	queryParameters := map[string]interface{}{
300		"api-version": APIVersion,
301	}
302
303	preparer := autorest.CreatePreparer(
304		autorest.AsGet(),
305		autorest.WithBaseURL(client.BaseURI),
306		autorest.WithPath("/providers/Microsoft.Subscription/aliases"),
307		autorest.WithQueryParameters(queryParameters))
308	return preparer.Prepare((&http.Request{}).WithContext(ctx))
309}
310
311// ListSender sends the List request. The method will close the
312// http.Response Body if it receives an error.
313func (client AliasClient) ListSender(req *http.Request) (*http.Response, error) {
314	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
315}
316
317// ListResponder handles the response to the List request. The method always
318// closes the http.Response Body.
319func (client AliasClient) ListResponder(resp *http.Response) (result PutAliasListResult, err error) {
320	err = autorest.Respond(
321		resp,
322		azure.WithErrorUnlessStatusCode(http.StatusOK),
323		autorest.ByUnmarshallingJSON(&result),
324		autorest.ByClosing())
325	result.Response = autorest.Response{Response: resp}
326	return
327}
328