1package security
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// AlertsClient is the API spec for Microsoft.Security (Azure Security Center) resource provider
30type AlertsClient struct {
31	BaseClient
32}
33
34// NewAlertsClient creates an instance of the AlertsClient client.
35func NewAlertsClient(subscriptionID string, ascLocation string) AlertsClient {
36	return NewAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation)
37}
38
39// NewAlertsClientWithBaseURI creates an instance of the AlertsClient client.
40func NewAlertsClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) AlertsClient {
41	return AlertsClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)}
42}
43
44// GetResourceGroupLevelAlerts get an alert that is associated a resource group or a resource in a resource group
45// Parameters:
46// alertName - name of the alert object
47// resourceGroupName - the name of the resource group within the user's subscription. The name is case
48// insensitive.
49func (client AlertsClient) GetResourceGroupLevelAlerts(ctx context.Context, alertName string, resourceGroupName string) (result Alert, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetResourceGroupLevelAlerts")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: client.SubscriptionID,
62			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}},
63		{TargetValue: resourceGroupName,
64			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
65				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
66				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
67		return result, validation.NewError("security.AlertsClient", "GetResourceGroupLevelAlerts", err.Error())
68	}
69
70	req, err := client.GetResourceGroupLevelAlertsPreparer(ctx, alertName, resourceGroupName)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "security.AlertsClient", "GetResourceGroupLevelAlerts", nil, "Failure preparing request")
73		return
74	}
75
76	resp, err := client.GetResourceGroupLevelAlertsSender(req)
77	if err != nil {
78		result.Response = autorest.Response{Response: resp}
79		err = autorest.NewErrorWithError(err, "security.AlertsClient", "GetResourceGroupLevelAlerts", resp, "Failure sending request")
80		return
81	}
82
83	result, err = client.GetResourceGroupLevelAlertsResponder(resp)
84	if err != nil {
85		err = autorest.NewErrorWithError(err, "security.AlertsClient", "GetResourceGroupLevelAlerts", resp, "Failure responding to request")
86	}
87
88	return
89}
90
91// GetResourceGroupLevelAlertsPreparer prepares the GetResourceGroupLevelAlerts request.
92func (client AlertsClient) GetResourceGroupLevelAlertsPreparer(ctx context.Context, alertName string, resourceGroupName string) (*http.Request, error) {
93	pathParameters := map[string]interface{}{
94		"alertName":         autorest.Encode("path", alertName),
95		"ascLocation":       autorest.Encode("path", client.AscLocation),
96		"resourceGroupName": autorest.Encode("path", resourceGroupName),
97		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
98	}
99
100	const APIVersion = "2015-06-01-preview"
101	queryParameters := map[string]interface{}{
102		"api-version": APIVersion,
103	}
104
105	preparer := autorest.CreatePreparer(
106		autorest.AsGet(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/locations/{ascLocation}/alerts/{alertName}", pathParameters),
109		autorest.WithQueryParameters(queryParameters))
110	return preparer.Prepare((&http.Request{}).WithContext(ctx))
111}
112
113// GetResourceGroupLevelAlertsSender sends the GetResourceGroupLevelAlerts request. The method will close the
114// http.Response Body if it receives an error.
115func (client AlertsClient) GetResourceGroupLevelAlertsSender(req *http.Request) (*http.Response, error) {
116	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
117	return autorest.SendWithSender(client, req, sd...)
118}
119
120// GetResourceGroupLevelAlertsResponder handles the response to the GetResourceGroupLevelAlerts request. The method always
121// closes the http.Response Body.
122func (client AlertsClient) GetResourceGroupLevelAlertsResponder(resp *http.Response) (result Alert, err error) {
123	err = autorest.Respond(
124		resp,
125		client.ByInspecting(),
126		azure.WithErrorUnlessStatusCode(http.StatusOK),
127		autorest.ByUnmarshallingJSON(&result),
128		autorest.ByClosing())
129	result.Response = autorest.Response{Response: resp}
130	return
131}
132
133// GetSubscriptionLevelAlert get an alert that is associated with a subscription
134// Parameters:
135// alertName - name of the alert object
136func (client AlertsClient) GetSubscriptionLevelAlert(ctx context.Context, alertName string) (result Alert, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.GetSubscriptionLevelAlert")
139		defer func() {
140			sc := -1
141			if result.Response.Response != nil {
142				sc = result.Response.Response.StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	if err := validation.Validate([]validation.Validation{
148		{TargetValue: client.SubscriptionID,
149			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil {
150		return result, validation.NewError("security.AlertsClient", "GetSubscriptionLevelAlert", err.Error())
151	}
152
153	req, err := client.GetSubscriptionLevelAlertPreparer(ctx, alertName)
154	if err != nil {
155		err = autorest.NewErrorWithError(err, "security.AlertsClient", "GetSubscriptionLevelAlert", nil, "Failure preparing request")
156		return
157	}
158
159	resp, err := client.GetSubscriptionLevelAlertSender(req)
160	if err != nil {
161		result.Response = autorest.Response{Response: resp}
162		err = autorest.NewErrorWithError(err, "security.AlertsClient", "GetSubscriptionLevelAlert", resp, "Failure sending request")
163		return
164	}
165
166	result, err = client.GetSubscriptionLevelAlertResponder(resp)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "security.AlertsClient", "GetSubscriptionLevelAlert", resp, "Failure responding to request")
169	}
170
171	return
172}
173
174// GetSubscriptionLevelAlertPreparer prepares the GetSubscriptionLevelAlert request.
175func (client AlertsClient) GetSubscriptionLevelAlertPreparer(ctx context.Context, alertName string) (*http.Request, error) {
176	pathParameters := map[string]interface{}{
177		"alertName":      autorest.Encode("path", alertName),
178		"ascLocation":    autorest.Encode("path", client.AscLocation),
179		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
180	}
181
182	const APIVersion = "2015-06-01-preview"
183	queryParameters := map[string]interface{}{
184		"api-version": APIVersion,
185	}
186
187	preparer := autorest.CreatePreparer(
188		autorest.AsGet(),
189		autorest.WithBaseURL(client.BaseURI),
190		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations/{ascLocation}/alerts/{alertName}", pathParameters),
191		autorest.WithQueryParameters(queryParameters))
192	return preparer.Prepare((&http.Request{}).WithContext(ctx))
193}
194
195// GetSubscriptionLevelAlertSender sends the GetSubscriptionLevelAlert request. The method will close the
196// http.Response Body if it receives an error.
197func (client AlertsClient) GetSubscriptionLevelAlertSender(req *http.Request) (*http.Response, error) {
198	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
199	return autorest.SendWithSender(client, req, sd...)
200}
201
202// GetSubscriptionLevelAlertResponder handles the response to the GetSubscriptionLevelAlert request. The method always
203// closes the http.Response Body.
204func (client AlertsClient) GetSubscriptionLevelAlertResponder(resp *http.Response) (result Alert, err error) {
205	err = autorest.Respond(
206		resp,
207		client.ByInspecting(),
208		azure.WithErrorUnlessStatusCode(http.StatusOK),
209		autorest.ByUnmarshallingJSON(&result),
210		autorest.ByClosing())
211	result.Response = autorest.Response{Response: resp}
212	return
213}
214
215// List list all the alerts that are associated with the subscription
216// Parameters:
217// filter - oData filter. Optional.
218// selectParameter - oData select. Optional.
219// expand - oData expand. Optional.
220func (client AlertsClient) List(ctx context.Context, filter string, selectParameter string, expand string) (result AlertListPage, err error) {
221	if tracing.IsEnabled() {
222		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.List")
223		defer func() {
224			sc := -1
225			if result.al.Response.Response != nil {
226				sc = result.al.Response.Response.StatusCode
227			}
228			tracing.EndSpan(ctx, sc, err)
229		}()
230	}
231	if err := validation.Validate([]validation.Validation{
232		{TargetValue: client.SubscriptionID,
233			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil {
234		return result, validation.NewError("security.AlertsClient", "List", err.Error())
235	}
236
237	result.fn = client.listNextResults
238	req, err := client.ListPreparer(ctx, filter, selectParameter, expand)
239	if err != nil {
240		err = autorest.NewErrorWithError(err, "security.AlertsClient", "List", nil, "Failure preparing request")
241		return
242	}
243
244	resp, err := client.ListSender(req)
245	if err != nil {
246		result.al.Response = autorest.Response{Response: resp}
247		err = autorest.NewErrorWithError(err, "security.AlertsClient", "List", resp, "Failure sending request")
248		return
249	}
250
251	result.al, err = client.ListResponder(resp)
252	if err != nil {
253		err = autorest.NewErrorWithError(err, "security.AlertsClient", "List", resp, "Failure responding to request")
254	}
255
256	return
257}
258
259// ListPreparer prepares the List request.
260func (client AlertsClient) ListPreparer(ctx context.Context, filter string, selectParameter string, expand string) (*http.Request, error) {
261	pathParameters := map[string]interface{}{
262		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
263	}
264
265	const APIVersion = "2015-06-01-preview"
266	queryParameters := map[string]interface{}{
267		"api-version": APIVersion,
268	}
269	if len(filter) > 0 {
270		queryParameters["$filter"] = autorest.Encode("query", filter)
271	}
272	if len(selectParameter) > 0 {
273		queryParameters["$select"] = autorest.Encode("query", selectParameter)
274	}
275	if len(expand) > 0 {
276		queryParameters["$expand"] = autorest.Encode("query", expand)
277	}
278
279	preparer := autorest.CreatePreparer(
280		autorest.AsGet(),
281		autorest.WithBaseURL(client.BaseURI),
282		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/alerts", pathParameters),
283		autorest.WithQueryParameters(queryParameters))
284	return preparer.Prepare((&http.Request{}).WithContext(ctx))
285}
286
287// ListSender sends the List request. The method will close the
288// http.Response Body if it receives an error.
289func (client AlertsClient) ListSender(req *http.Request) (*http.Response, error) {
290	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
291	return autorest.SendWithSender(client, req, sd...)
292}
293
294// ListResponder handles the response to the List request. The method always
295// closes the http.Response Body.
296func (client AlertsClient) ListResponder(resp *http.Response) (result AlertList, err error) {
297	err = autorest.Respond(
298		resp,
299		client.ByInspecting(),
300		azure.WithErrorUnlessStatusCode(http.StatusOK),
301		autorest.ByUnmarshallingJSON(&result),
302		autorest.ByClosing())
303	result.Response = autorest.Response{Response: resp}
304	return
305}
306
307// listNextResults retrieves the next set of results, if any.
308func (client AlertsClient) listNextResults(ctx context.Context, lastResults AlertList) (result AlertList, err error) {
309	req, err := lastResults.alertListPreparer(ctx)
310	if err != nil {
311		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listNextResults", nil, "Failure preparing next results request")
312	}
313	if req == nil {
314		return
315	}
316	resp, err := client.ListSender(req)
317	if err != nil {
318		result.Response = autorest.Response{Response: resp}
319		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listNextResults", resp, "Failure sending next results request")
320	}
321	result, err = client.ListResponder(resp)
322	if err != nil {
323		err = autorest.NewErrorWithError(err, "security.AlertsClient", "listNextResults", resp, "Failure responding to next results request")
324	}
325	return
326}
327
328// ListComplete enumerates all values, automatically crossing page boundaries as required.
329func (client AlertsClient) ListComplete(ctx context.Context, filter string, selectParameter string, expand string) (result AlertListIterator, err error) {
330	if tracing.IsEnabled() {
331		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.List")
332		defer func() {
333			sc := -1
334			if result.Response().Response.Response != nil {
335				sc = result.page.Response().Response.Response.StatusCode
336			}
337			tracing.EndSpan(ctx, sc, err)
338		}()
339	}
340	result.page, err = client.List(ctx, filter, selectParameter, expand)
341	return
342}
343
344// ListByResourceGroup list all the alerts that are associated with the resource group
345// Parameters:
346// resourceGroupName - the name of the resource group within the user's subscription. The name is case
347// insensitive.
348// filter - oData filter. Optional.
349// selectParameter - oData select. Optional.
350// expand - oData expand. Optional.
351func (client AlertsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, filter string, selectParameter string, expand string) (result AlertListPage, err error) {
352	if tracing.IsEnabled() {
353		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListByResourceGroup")
354		defer func() {
355			sc := -1
356			if result.al.Response.Response != nil {
357				sc = result.al.Response.Response.StatusCode
358			}
359			tracing.EndSpan(ctx, sc, err)
360		}()
361	}
362	if err := validation.Validate([]validation.Validation{
363		{TargetValue: client.SubscriptionID,
364			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}},
365		{TargetValue: resourceGroupName,
366			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
367				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
368				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
369		return result, validation.NewError("security.AlertsClient", "ListByResourceGroup", err.Error())
370	}
371
372	result.fn = client.listByResourceGroupNextResults
373	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, filter, selectParameter, expand)
374	if err != nil {
375		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListByResourceGroup", nil, "Failure preparing request")
376		return
377	}
378
379	resp, err := client.ListByResourceGroupSender(req)
380	if err != nil {
381		result.al.Response = autorest.Response{Response: resp}
382		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListByResourceGroup", resp, "Failure sending request")
383		return
384	}
385
386	result.al, err = client.ListByResourceGroupResponder(resp)
387	if err != nil {
388		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListByResourceGroup", resp, "Failure responding to request")
389	}
390
391	return
392}
393
394// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
395func (client AlertsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string, selectParameter string, expand string) (*http.Request, error) {
396	pathParameters := map[string]interface{}{
397		"resourceGroupName": autorest.Encode("path", resourceGroupName),
398		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
399	}
400
401	const APIVersion = "2015-06-01-preview"
402	queryParameters := map[string]interface{}{
403		"api-version": APIVersion,
404	}
405	if len(filter) > 0 {
406		queryParameters["$filter"] = autorest.Encode("query", filter)
407	}
408	if len(selectParameter) > 0 {
409		queryParameters["$select"] = autorest.Encode("query", selectParameter)
410	}
411	if len(expand) > 0 {
412		queryParameters["$expand"] = autorest.Encode("query", expand)
413	}
414
415	preparer := autorest.CreatePreparer(
416		autorest.AsGet(),
417		autorest.WithBaseURL(client.BaseURI),
418		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/alerts", pathParameters),
419		autorest.WithQueryParameters(queryParameters))
420	return preparer.Prepare((&http.Request{}).WithContext(ctx))
421}
422
423// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
424// http.Response Body if it receives an error.
425func (client AlertsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
426	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
427	return autorest.SendWithSender(client, req, sd...)
428}
429
430// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
431// closes the http.Response Body.
432func (client AlertsClient) ListByResourceGroupResponder(resp *http.Response) (result AlertList, err error) {
433	err = autorest.Respond(
434		resp,
435		client.ByInspecting(),
436		azure.WithErrorUnlessStatusCode(http.StatusOK),
437		autorest.ByUnmarshallingJSON(&result),
438		autorest.ByClosing())
439	result.Response = autorest.Response{Response: resp}
440	return
441}
442
443// listByResourceGroupNextResults retrieves the next set of results, if any.
444func (client AlertsClient) listByResourceGroupNextResults(ctx context.Context, lastResults AlertList) (result AlertList, err error) {
445	req, err := lastResults.alertListPreparer(ctx)
446	if err != nil {
447		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
448	}
449	if req == nil {
450		return
451	}
452	resp, err := client.ListByResourceGroupSender(req)
453	if err != nil {
454		result.Response = autorest.Response{Response: resp}
455		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
456	}
457	result, err = client.ListByResourceGroupResponder(resp)
458	if err != nil {
459		err = autorest.NewErrorWithError(err, "security.AlertsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
460	}
461	return
462}
463
464// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
465func (client AlertsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string, selectParameter string, expand string) (result AlertListIterator, err error) {
466	if tracing.IsEnabled() {
467		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListByResourceGroup")
468		defer func() {
469			sc := -1
470			if result.Response().Response.Response != nil {
471				sc = result.page.Response().Response.Response.StatusCode
472			}
473			tracing.EndSpan(ctx, sc, err)
474		}()
475	}
476	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, filter, selectParameter, expand)
477	return
478}
479
480// ListResourceGroupLevelAlertsByRegion list all the alerts that are associated with the resource group that are stored
481// in a specific location
482// Parameters:
483// resourceGroupName - the name of the resource group within the user's subscription. The name is case
484// insensitive.
485// filter - oData filter. Optional.
486// selectParameter - oData select. Optional.
487// expand - oData expand. Optional.
488func (client AlertsClient) ListResourceGroupLevelAlertsByRegion(ctx context.Context, resourceGroupName string, filter string, selectParameter string, expand string) (result AlertListPage, err error) {
489	if tracing.IsEnabled() {
490		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListResourceGroupLevelAlertsByRegion")
491		defer func() {
492			sc := -1
493			if result.al.Response.Response != nil {
494				sc = result.al.Response.Response.StatusCode
495			}
496			tracing.EndSpan(ctx, sc, err)
497		}()
498	}
499	if err := validation.Validate([]validation.Validation{
500		{TargetValue: client.SubscriptionID,
501			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}},
502		{TargetValue: resourceGroupName,
503			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
504				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
505				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
506		return result, validation.NewError("security.AlertsClient", "ListResourceGroupLevelAlertsByRegion", err.Error())
507	}
508
509	result.fn = client.listResourceGroupLevelAlertsByRegionNextResults
510	req, err := client.ListResourceGroupLevelAlertsByRegionPreparer(ctx, resourceGroupName, filter, selectParameter, expand)
511	if err != nil {
512		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListResourceGroupLevelAlertsByRegion", nil, "Failure preparing request")
513		return
514	}
515
516	resp, err := client.ListResourceGroupLevelAlertsByRegionSender(req)
517	if err != nil {
518		result.al.Response = autorest.Response{Response: resp}
519		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListResourceGroupLevelAlertsByRegion", resp, "Failure sending request")
520		return
521	}
522
523	result.al, err = client.ListResourceGroupLevelAlertsByRegionResponder(resp)
524	if err != nil {
525		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListResourceGroupLevelAlertsByRegion", resp, "Failure responding to request")
526	}
527
528	return
529}
530
531// ListResourceGroupLevelAlertsByRegionPreparer prepares the ListResourceGroupLevelAlertsByRegion request.
532func (client AlertsClient) ListResourceGroupLevelAlertsByRegionPreparer(ctx context.Context, resourceGroupName string, filter string, selectParameter string, expand string) (*http.Request, error) {
533	pathParameters := map[string]interface{}{
534		"ascLocation":       autorest.Encode("path", client.AscLocation),
535		"resourceGroupName": autorest.Encode("path", resourceGroupName),
536		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
537	}
538
539	const APIVersion = "2015-06-01-preview"
540	queryParameters := map[string]interface{}{
541		"api-version": APIVersion,
542	}
543	if len(filter) > 0 {
544		queryParameters["$filter"] = autorest.Encode("query", filter)
545	}
546	if len(selectParameter) > 0 {
547		queryParameters["$select"] = autorest.Encode("query", selectParameter)
548	}
549	if len(expand) > 0 {
550		queryParameters["$expand"] = autorest.Encode("query", expand)
551	}
552
553	preparer := autorest.CreatePreparer(
554		autorest.AsGet(),
555		autorest.WithBaseURL(client.BaseURI),
556		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/locations/{ascLocation}/alerts", pathParameters),
557		autorest.WithQueryParameters(queryParameters))
558	return preparer.Prepare((&http.Request{}).WithContext(ctx))
559}
560
561// ListResourceGroupLevelAlertsByRegionSender sends the ListResourceGroupLevelAlertsByRegion request. The method will close the
562// http.Response Body if it receives an error.
563func (client AlertsClient) ListResourceGroupLevelAlertsByRegionSender(req *http.Request) (*http.Response, error) {
564	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
565	return autorest.SendWithSender(client, req, sd...)
566}
567
568// ListResourceGroupLevelAlertsByRegionResponder handles the response to the ListResourceGroupLevelAlertsByRegion request. The method always
569// closes the http.Response Body.
570func (client AlertsClient) ListResourceGroupLevelAlertsByRegionResponder(resp *http.Response) (result AlertList, err error) {
571	err = autorest.Respond(
572		resp,
573		client.ByInspecting(),
574		azure.WithErrorUnlessStatusCode(http.StatusOK),
575		autorest.ByUnmarshallingJSON(&result),
576		autorest.ByClosing())
577	result.Response = autorest.Response{Response: resp}
578	return
579}
580
581// listResourceGroupLevelAlertsByRegionNextResults retrieves the next set of results, if any.
582func (client AlertsClient) listResourceGroupLevelAlertsByRegionNextResults(ctx context.Context, lastResults AlertList) (result AlertList, err error) {
583	req, err := lastResults.alertListPreparer(ctx)
584	if err != nil {
585		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listResourceGroupLevelAlertsByRegionNextResults", nil, "Failure preparing next results request")
586	}
587	if req == nil {
588		return
589	}
590	resp, err := client.ListResourceGroupLevelAlertsByRegionSender(req)
591	if err != nil {
592		result.Response = autorest.Response{Response: resp}
593		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listResourceGroupLevelAlertsByRegionNextResults", resp, "Failure sending next results request")
594	}
595	result, err = client.ListResourceGroupLevelAlertsByRegionResponder(resp)
596	if err != nil {
597		err = autorest.NewErrorWithError(err, "security.AlertsClient", "listResourceGroupLevelAlertsByRegionNextResults", resp, "Failure responding to next results request")
598	}
599	return
600}
601
602// ListResourceGroupLevelAlertsByRegionComplete enumerates all values, automatically crossing page boundaries as required.
603func (client AlertsClient) ListResourceGroupLevelAlertsByRegionComplete(ctx context.Context, resourceGroupName string, filter string, selectParameter string, expand string) (result AlertListIterator, err error) {
604	if tracing.IsEnabled() {
605		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListResourceGroupLevelAlertsByRegion")
606		defer func() {
607			sc := -1
608			if result.Response().Response.Response != nil {
609				sc = result.page.Response().Response.Response.StatusCode
610			}
611			tracing.EndSpan(ctx, sc, err)
612		}()
613	}
614	result.page, err = client.ListResourceGroupLevelAlertsByRegion(ctx, resourceGroupName, filter, selectParameter, expand)
615	return
616}
617
618// ListSubscriptionLevelAlertsByRegion list all the alerts that are associated with the subscription that are stored in
619// a specific location
620// Parameters:
621// filter - oData filter. Optional.
622// selectParameter - oData select. Optional.
623// expand - oData expand. Optional.
624func (client AlertsClient) ListSubscriptionLevelAlertsByRegion(ctx context.Context, filter string, selectParameter string, expand string) (result AlertListPage, err error) {
625	if tracing.IsEnabled() {
626		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListSubscriptionLevelAlertsByRegion")
627		defer func() {
628			sc := -1
629			if result.al.Response.Response != nil {
630				sc = result.al.Response.Response.StatusCode
631			}
632			tracing.EndSpan(ctx, sc, err)
633		}()
634	}
635	if err := validation.Validate([]validation.Validation{
636		{TargetValue: client.SubscriptionID,
637			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil {
638		return result, validation.NewError("security.AlertsClient", "ListSubscriptionLevelAlertsByRegion", err.Error())
639	}
640
641	result.fn = client.listSubscriptionLevelAlertsByRegionNextResults
642	req, err := client.ListSubscriptionLevelAlertsByRegionPreparer(ctx, filter, selectParameter, expand)
643	if err != nil {
644		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListSubscriptionLevelAlertsByRegion", nil, "Failure preparing request")
645		return
646	}
647
648	resp, err := client.ListSubscriptionLevelAlertsByRegionSender(req)
649	if err != nil {
650		result.al.Response = autorest.Response{Response: resp}
651		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListSubscriptionLevelAlertsByRegion", resp, "Failure sending request")
652		return
653	}
654
655	result.al, err = client.ListSubscriptionLevelAlertsByRegionResponder(resp)
656	if err != nil {
657		err = autorest.NewErrorWithError(err, "security.AlertsClient", "ListSubscriptionLevelAlertsByRegion", resp, "Failure responding to request")
658	}
659
660	return
661}
662
663// ListSubscriptionLevelAlertsByRegionPreparer prepares the ListSubscriptionLevelAlertsByRegion request.
664func (client AlertsClient) ListSubscriptionLevelAlertsByRegionPreparer(ctx context.Context, filter string, selectParameter string, expand string) (*http.Request, error) {
665	pathParameters := map[string]interface{}{
666		"ascLocation":    autorest.Encode("path", client.AscLocation),
667		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
668	}
669
670	const APIVersion = "2015-06-01-preview"
671	queryParameters := map[string]interface{}{
672		"api-version": APIVersion,
673	}
674	if len(filter) > 0 {
675		queryParameters["$filter"] = autorest.Encode("query", filter)
676	}
677	if len(selectParameter) > 0 {
678		queryParameters["$select"] = autorest.Encode("query", selectParameter)
679	}
680	if len(expand) > 0 {
681		queryParameters["$expand"] = autorest.Encode("query", expand)
682	}
683
684	preparer := autorest.CreatePreparer(
685		autorest.AsGet(),
686		autorest.WithBaseURL(client.BaseURI),
687		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations/{ascLocation}/alerts", pathParameters),
688		autorest.WithQueryParameters(queryParameters))
689	return preparer.Prepare((&http.Request{}).WithContext(ctx))
690}
691
692// ListSubscriptionLevelAlertsByRegionSender sends the ListSubscriptionLevelAlertsByRegion request. The method will close the
693// http.Response Body if it receives an error.
694func (client AlertsClient) ListSubscriptionLevelAlertsByRegionSender(req *http.Request) (*http.Response, error) {
695	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
696	return autorest.SendWithSender(client, req, sd...)
697}
698
699// ListSubscriptionLevelAlertsByRegionResponder handles the response to the ListSubscriptionLevelAlertsByRegion request. The method always
700// closes the http.Response Body.
701func (client AlertsClient) ListSubscriptionLevelAlertsByRegionResponder(resp *http.Response) (result AlertList, err error) {
702	err = autorest.Respond(
703		resp,
704		client.ByInspecting(),
705		azure.WithErrorUnlessStatusCode(http.StatusOK),
706		autorest.ByUnmarshallingJSON(&result),
707		autorest.ByClosing())
708	result.Response = autorest.Response{Response: resp}
709	return
710}
711
712// listSubscriptionLevelAlertsByRegionNextResults retrieves the next set of results, if any.
713func (client AlertsClient) listSubscriptionLevelAlertsByRegionNextResults(ctx context.Context, lastResults AlertList) (result AlertList, err error) {
714	req, err := lastResults.alertListPreparer(ctx)
715	if err != nil {
716		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listSubscriptionLevelAlertsByRegionNextResults", nil, "Failure preparing next results request")
717	}
718	if req == nil {
719		return
720	}
721	resp, err := client.ListSubscriptionLevelAlertsByRegionSender(req)
722	if err != nil {
723		result.Response = autorest.Response{Response: resp}
724		return result, autorest.NewErrorWithError(err, "security.AlertsClient", "listSubscriptionLevelAlertsByRegionNextResults", resp, "Failure sending next results request")
725	}
726	result, err = client.ListSubscriptionLevelAlertsByRegionResponder(resp)
727	if err != nil {
728		err = autorest.NewErrorWithError(err, "security.AlertsClient", "listSubscriptionLevelAlertsByRegionNextResults", resp, "Failure responding to next results request")
729	}
730	return
731}
732
733// ListSubscriptionLevelAlertsByRegionComplete enumerates all values, automatically crossing page boundaries as required.
734func (client AlertsClient) ListSubscriptionLevelAlertsByRegionComplete(ctx context.Context, filter string, selectParameter string, expand string) (result AlertListIterator, err error) {
735	if tracing.IsEnabled() {
736		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListSubscriptionLevelAlertsByRegion")
737		defer func() {
738			sc := -1
739			if result.Response().Response.Response != nil {
740				sc = result.page.Response().Response.Response.StatusCode
741			}
742			tracing.EndSpan(ctx, sc, err)
743		}()
744	}
745	result.page, err = client.ListSubscriptionLevelAlertsByRegion(ctx, filter, selectParameter, expand)
746	return
747}
748
749// UpdateResourceGroupLevelAlertState update the alert's state
750// Parameters:
751// alertName - name of the alert object
752// alertUpdateActionType - type of the action to do on the alert
753// resourceGroupName - the name of the resource group within the user's subscription. The name is case
754// insensitive.
755func (client AlertsClient) UpdateResourceGroupLevelAlertState(ctx context.Context, alertName string, alertUpdateActionType string, resourceGroupName string) (result autorest.Response, err error) {
756	if tracing.IsEnabled() {
757		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.UpdateResourceGroupLevelAlertState")
758		defer func() {
759			sc := -1
760			if result.Response != nil {
761				sc = result.Response.StatusCode
762			}
763			tracing.EndSpan(ctx, sc, err)
764		}()
765	}
766	if err := validation.Validate([]validation.Validation{
767		{TargetValue: client.SubscriptionID,
768			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}},
769		{TargetValue: resourceGroupName,
770			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
771				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
772				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
773		return result, validation.NewError("security.AlertsClient", "UpdateResourceGroupLevelAlertState", err.Error())
774	}
775
776	req, err := client.UpdateResourceGroupLevelAlertStatePreparer(ctx, alertName, alertUpdateActionType, resourceGroupName)
777	if err != nil {
778		err = autorest.NewErrorWithError(err, "security.AlertsClient", "UpdateResourceGroupLevelAlertState", nil, "Failure preparing request")
779		return
780	}
781
782	resp, err := client.UpdateResourceGroupLevelAlertStateSender(req)
783	if err != nil {
784		result.Response = resp
785		err = autorest.NewErrorWithError(err, "security.AlertsClient", "UpdateResourceGroupLevelAlertState", resp, "Failure sending request")
786		return
787	}
788
789	result, err = client.UpdateResourceGroupLevelAlertStateResponder(resp)
790	if err != nil {
791		err = autorest.NewErrorWithError(err, "security.AlertsClient", "UpdateResourceGroupLevelAlertState", resp, "Failure responding to request")
792	}
793
794	return
795}
796
797// UpdateResourceGroupLevelAlertStatePreparer prepares the UpdateResourceGroupLevelAlertState request.
798func (client AlertsClient) UpdateResourceGroupLevelAlertStatePreparer(ctx context.Context, alertName string, alertUpdateActionType string, resourceGroupName string) (*http.Request, error) {
799	pathParameters := map[string]interface{}{
800		"alertName":             autorest.Encode("path", alertName),
801		"alertUpdateActionType": autorest.Encode("path", alertUpdateActionType),
802		"ascLocation":           autorest.Encode("path", client.AscLocation),
803		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
804		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
805	}
806
807	const APIVersion = "2015-06-01-preview"
808	queryParameters := map[string]interface{}{
809		"api-version": APIVersion,
810	}
811
812	preparer := autorest.CreatePreparer(
813		autorest.AsPost(),
814		autorest.WithBaseURL(client.BaseURI),
815		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/locations/{ascLocation}/alerts/{alertName}/{alertUpdateActionType}", pathParameters),
816		autorest.WithQueryParameters(queryParameters))
817	return preparer.Prepare((&http.Request{}).WithContext(ctx))
818}
819
820// UpdateResourceGroupLevelAlertStateSender sends the UpdateResourceGroupLevelAlertState request. The method will close the
821// http.Response Body if it receives an error.
822func (client AlertsClient) UpdateResourceGroupLevelAlertStateSender(req *http.Request) (*http.Response, error) {
823	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
824	return autorest.SendWithSender(client, req, sd...)
825}
826
827// UpdateResourceGroupLevelAlertStateResponder handles the response to the UpdateResourceGroupLevelAlertState request. The method always
828// closes the http.Response Body.
829func (client AlertsClient) UpdateResourceGroupLevelAlertStateResponder(resp *http.Response) (result autorest.Response, err error) {
830	err = autorest.Respond(
831		resp,
832		client.ByInspecting(),
833		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
834		autorest.ByClosing())
835	result.Response = resp
836	return
837}
838
839// UpdateSubscriptionLevelAlertState update the alert's state
840// Parameters:
841// alertName - name of the alert object
842// alertUpdateActionType - type of the action to do on the alert
843func (client AlertsClient) UpdateSubscriptionLevelAlertState(ctx context.Context, alertName string, alertUpdateActionType string) (result autorest.Response, err error) {
844	if tracing.IsEnabled() {
845		ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.UpdateSubscriptionLevelAlertState")
846		defer func() {
847			sc := -1
848			if result.Response != nil {
849				sc = result.Response.StatusCode
850			}
851			tracing.EndSpan(ctx, sc, err)
852		}()
853	}
854	if err := validation.Validate([]validation.Validation{
855		{TargetValue: client.SubscriptionID,
856			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}}}); err != nil {
857		return result, validation.NewError("security.AlertsClient", "UpdateSubscriptionLevelAlertState", err.Error())
858	}
859
860	req, err := client.UpdateSubscriptionLevelAlertStatePreparer(ctx, alertName, alertUpdateActionType)
861	if err != nil {
862		err = autorest.NewErrorWithError(err, "security.AlertsClient", "UpdateSubscriptionLevelAlertState", nil, "Failure preparing request")
863		return
864	}
865
866	resp, err := client.UpdateSubscriptionLevelAlertStateSender(req)
867	if err != nil {
868		result.Response = resp
869		err = autorest.NewErrorWithError(err, "security.AlertsClient", "UpdateSubscriptionLevelAlertState", resp, "Failure sending request")
870		return
871	}
872
873	result, err = client.UpdateSubscriptionLevelAlertStateResponder(resp)
874	if err != nil {
875		err = autorest.NewErrorWithError(err, "security.AlertsClient", "UpdateSubscriptionLevelAlertState", resp, "Failure responding to request")
876	}
877
878	return
879}
880
881// UpdateSubscriptionLevelAlertStatePreparer prepares the UpdateSubscriptionLevelAlertState request.
882func (client AlertsClient) UpdateSubscriptionLevelAlertStatePreparer(ctx context.Context, alertName string, alertUpdateActionType string) (*http.Request, error) {
883	pathParameters := map[string]interface{}{
884		"alertName":             autorest.Encode("path", alertName),
885		"alertUpdateActionType": autorest.Encode("path", alertUpdateActionType),
886		"ascLocation":           autorest.Encode("path", client.AscLocation),
887		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
888	}
889
890	const APIVersion = "2015-06-01-preview"
891	queryParameters := map[string]interface{}{
892		"api-version": APIVersion,
893	}
894
895	preparer := autorest.CreatePreparer(
896		autorest.AsPost(),
897		autorest.WithBaseURL(client.BaseURI),
898		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations/{ascLocation}/alerts/{alertName}/{alertUpdateActionType}", pathParameters),
899		autorest.WithQueryParameters(queryParameters))
900	return preparer.Prepare((&http.Request{}).WithContext(ctx))
901}
902
903// UpdateSubscriptionLevelAlertStateSender sends the UpdateSubscriptionLevelAlertState request. The method will close the
904// http.Response Body if it receives an error.
905func (client AlertsClient) UpdateSubscriptionLevelAlertStateSender(req *http.Request) (*http.Response, error) {
906	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
907	return autorest.SendWithSender(client, req, sd...)
908}
909
910// UpdateSubscriptionLevelAlertStateResponder handles the response to the UpdateSubscriptionLevelAlertState request. The method always
911// closes the http.Response Body.
912func (client AlertsClient) UpdateSubscriptionLevelAlertStateResponder(resp *http.Response) (result autorest.Response, err error) {
913	err = autorest.Respond(
914		resp,
915		client.ByInspecting(),
916		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
917		autorest.ByClosing())
918	result.Response = resp
919	return
920}
921