1package advisor
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// SuppressionsClient is the REST APIs for Azure Advisor
29type SuppressionsClient struct {
30	BaseClient
31}
32
33// NewSuppressionsClient creates an instance of the SuppressionsClient client.
34func NewSuppressionsClient(subscriptionID string) SuppressionsClient {
35	return NewSuppressionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewSuppressionsClientWithBaseURI creates an instance of the SuppressionsClient client using a custom endpoint.  Use
39// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewSuppressionsClientWithBaseURI(baseURI string, subscriptionID string) SuppressionsClient {
41	return SuppressionsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Create enables the snoozed or dismissed attribute of a recommendation. The snoozed or dismissed attribute is
45// referred to as a suppression. Use this API to create or update the snoozed or dismissed status of a recommendation.
46// Parameters:
47// resourceURI - the fully qualified Azure Resource Manager identifier of the resource to which the
48// recommendation applies.
49// recommendationID - the recommendation ID.
50// name - the name of the suppression.
51// suppressionContract - the snoozed or dismissed attribute; for example, the snooze duration.
52func (client SuppressionsClient) Create(ctx context.Context, resourceURI string, recommendationID string, name string, suppressionContract SuppressionContract) (result SuppressionContract, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/SuppressionsClient.Create")
55		defer func() {
56			sc := -1
57			if result.Response.Response != nil {
58				sc = result.Response.Response.StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	req, err := client.CreatePreparer(ctx, resourceURI, recommendationID, name, suppressionContract)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Create", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.CreateSender(req)
70	if err != nil {
71		result.Response = autorest.Response{Response: resp}
72		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Create", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.CreateResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Create", resp, "Failure responding to request")
79		return
80	}
81
82	return
83}
84
85// CreatePreparer prepares the Create request.
86func (client SuppressionsClient) CreatePreparer(ctx context.Context, resourceURI string, recommendationID string, name string, suppressionContract SuppressionContract) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"name":             autorest.Encode("path", name),
89		"recommendationId": autorest.Encode("path", recommendationID),
90		"resourceUri":      autorest.Encode("path", resourceURI),
91	}
92
93	const APIVersion = "2016-07-12-preview"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsContentType("application/json; charset=utf-8"),
100		autorest.AsPut(),
101		autorest.WithBaseURL(client.BaseURI),
102		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Advisor/recommendations/{recommendationId}/suppressions/{name}", pathParameters),
103		autorest.WithJSON(suppressionContract),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CreateSender sends the Create request. The method will close the
109// http.Response Body if it receives an error.
110func (client SuppressionsClient) CreateSender(req *http.Request) (*http.Response, error) {
111	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
112}
113
114// CreateResponder handles the response to the Create request. The method always
115// closes the http.Response Body.
116func (client SuppressionsClient) CreateResponder(resp *http.Response) (result SuppressionContract, err error) {
117	err = autorest.Respond(
118		resp,
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 enables the activation of a snoozed or dismissed recommendation. The snoozed or dismissed attribute of a
127// recommendation is referred to as a suppression.
128// Parameters:
129// resourceURI - the fully qualified Azure Resource Manager identifier of the resource to which the
130// recommendation applies.
131// recommendationID - the recommendation ID.
132// name - the name of the suppression.
133func (client SuppressionsClient) Delete(ctx context.Context, resourceURI string, recommendationID string, name string) (result autorest.Response, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/SuppressionsClient.Delete")
136		defer func() {
137			sc := -1
138			if result.Response != nil {
139				sc = result.Response.StatusCode
140			}
141			tracing.EndSpan(ctx, sc, err)
142		}()
143	}
144	req, err := client.DeletePreparer(ctx, resourceURI, recommendationID, name)
145	if err != nil {
146		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Delete", nil, "Failure preparing request")
147		return
148	}
149
150	resp, err := client.DeleteSender(req)
151	if err != nil {
152		result.Response = resp
153		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Delete", resp, "Failure sending request")
154		return
155	}
156
157	result, err = client.DeleteResponder(resp)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Delete", resp, "Failure responding to request")
160		return
161	}
162
163	return
164}
165
166// DeletePreparer prepares the Delete request.
167func (client SuppressionsClient) DeletePreparer(ctx context.Context, resourceURI string, recommendationID string, name string) (*http.Request, error) {
168	pathParameters := map[string]interface{}{
169		"name":             autorest.Encode("path", name),
170		"recommendationId": autorest.Encode("path", recommendationID),
171		"resourceUri":      autorest.Encode("path", resourceURI),
172	}
173
174	const APIVersion = "2016-07-12-preview"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsDelete(),
181		autorest.WithBaseURL(client.BaseURI),
182		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Advisor/recommendations/{recommendationId}/suppressions/{name}", pathParameters),
183		autorest.WithQueryParameters(queryParameters))
184	return preparer.Prepare((&http.Request{}).WithContext(ctx))
185}
186
187// DeleteSender sends the Delete request. The method will close the
188// http.Response Body if it receives an error.
189func (client SuppressionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
190	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
191}
192
193// DeleteResponder handles the response to the Delete request. The method always
194// closes the http.Response Body.
195func (client SuppressionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
196	err = autorest.Respond(
197		resp,
198		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
199		autorest.ByClosing())
200	result.Response = resp
201	return
202}
203
204// Get obtains the details of a suppression.
205// Parameters:
206// resourceURI - the fully qualified Azure Resource Manager identifier of the resource to which the
207// recommendation applies.
208// recommendationID - the recommendation ID.
209// name - the name of the suppression.
210func (client SuppressionsClient) Get(ctx context.Context, resourceURI string, recommendationID string, name string) (result SuppressionContract, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/SuppressionsClient.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, resourceURI, recommendationID, name)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "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, "advisor.SuppressionsClient", "Get", resp, "Failure sending request")
231		return
232	}
233
234	result, err = client.GetResponder(resp)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "Get", resp, "Failure responding to request")
237		return
238	}
239
240	return
241}
242
243// GetPreparer prepares the Get request.
244func (client SuppressionsClient) GetPreparer(ctx context.Context, resourceURI string, recommendationID string, name string) (*http.Request, error) {
245	pathParameters := map[string]interface{}{
246		"name":             autorest.Encode("path", name),
247		"recommendationId": autorest.Encode("path", recommendationID),
248		"resourceUri":      autorest.Encode("path", resourceURI),
249	}
250
251	const APIVersion = "2016-07-12-preview"
252	queryParameters := map[string]interface{}{
253		"api-version": APIVersion,
254	}
255
256	preparer := autorest.CreatePreparer(
257		autorest.AsGet(),
258		autorest.WithBaseURL(client.BaseURI),
259		autorest.WithPathParameters("/{resourceUri}/providers/Microsoft.Advisor/recommendations/{recommendationId}/suppressions/{name}", pathParameters),
260		autorest.WithQueryParameters(queryParameters))
261	return preparer.Prepare((&http.Request{}).WithContext(ctx))
262}
263
264// GetSender sends the Get request. The method will close the
265// http.Response Body if it receives an error.
266func (client SuppressionsClient) GetSender(req *http.Request) (*http.Response, error) {
267	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
268}
269
270// GetResponder handles the response to the Get request. The method always
271// closes the http.Response Body.
272func (client SuppressionsClient) GetResponder(resp *http.Response) (result SuppressionContract, err error) {
273	err = autorest.Respond(
274		resp,
275		azure.WithErrorUnlessStatusCode(http.StatusOK),
276		autorest.ByUnmarshallingJSON(&result),
277		autorest.ByClosing())
278	result.Response = autorest.Response{Response: resp}
279	return
280}
281
282// List retrieves the list of snoozed or dismissed suppressions for a subscription. The snoozed or dismissed attribute
283// of a recommendation is referred to as a suppression.
284func (client SuppressionsClient) List(ctx context.Context) (result ListSuppressionContract, err error) {
285	if tracing.IsEnabled() {
286		ctx = tracing.StartSpan(ctx, fqdn+"/SuppressionsClient.List")
287		defer func() {
288			sc := -1
289			if result.Response.Response != nil {
290				sc = result.Response.Response.StatusCode
291			}
292			tracing.EndSpan(ctx, sc, err)
293		}()
294	}
295	req, err := client.ListPreparer(ctx)
296	if err != nil {
297		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "List", nil, "Failure preparing request")
298		return
299	}
300
301	resp, err := client.ListSender(req)
302	if err != nil {
303		result.Response = autorest.Response{Response: resp}
304		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "List", resp, "Failure sending request")
305		return
306	}
307
308	result, err = client.ListResponder(resp)
309	if err != nil {
310		err = autorest.NewErrorWithError(err, "advisor.SuppressionsClient", "List", resp, "Failure responding to request")
311		return
312	}
313
314	return
315}
316
317// ListPreparer prepares the List request.
318func (client SuppressionsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
319	pathParameters := map[string]interface{}{
320		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
321	}
322
323	const APIVersion = "2016-07-12-preview"
324	queryParameters := map[string]interface{}{
325		"api-version": APIVersion,
326	}
327
328	preparer := autorest.CreatePreparer(
329		autorest.AsGet(),
330		autorest.WithBaseURL(client.BaseURI),
331		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Advisor/suppressions", pathParameters),
332		autorest.WithQueryParameters(queryParameters))
333	return preparer.Prepare((&http.Request{}).WithContext(ctx))
334}
335
336// ListSender sends the List request. The method will close the
337// http.Response Body if it receives an error.
338func (client SuppressionsClient) ListSender(req *http.Request) (*http.Response, error) {
339	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
340}
341
342// ListResponder handles the response to the List request. The method always
343// closes the http.Response Body.
344func (client SuppressionsClient) ListResponder(resp *http.Response) (result ListSuppressionContract, err error) {
345	err = autorest.Respond(
346		resp,
347		azure.WithErrorUnlessStatusCode(http.StatusOK),
348		autorest.ByUnmarshallingJSON(&result.Value),
349		autorest.ByClosing())
350	result.Response = autorest.Response{Response: resp}
351	return
352}
353