1package security
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// ExternalSecuritySolutionsClient is the API spec for Microsoft.Security (Azure Security Center) resource provider
19type ExternalSecuritySolutionsClient struct {
20	BaseClient
21}
22
23// NewExternalSecuritySolutionsClient creates an instance of the ExternalSecuritySolutionsClient client.
24func NewExternalSecuritySolutionsClient(subscriptionID string, ascLocation string) ExternalSecuritySolutionsClient {
25	return NewExternalSecuritySolutionsClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation)
26}
27
28// NewExternalSecuritySolutionsClientWithBaseURI creates an instance of the ExternalSecuritySolutionsClient client
29// using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign
30// clouds, Azure stack).
31func NewExternalSecuritySolutionsClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) ExternalSecuritySolutionsClient {
32	return ExternalSecuritySolutionsClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)}
33}
34
35// Get gets a specific external Security Solution.
36// Parameters:
37// resourceGroupName - the name of the resource group within the user's subscription. The name is case
38// insensitive.
39// externalSecuritySolutionsName - name of an external security solution.
40func (client ExternalSecuritySolutionsClient) Get(ctx context.Context, resourceGroupName string, externalSecuritySolutionsName string) (result ExternalSecuritySolutionModel, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/ExternalSecuritySolutionsClient.Get")
43		defer func() {
44			sc := -1
45			if result.Response.Response != nil {
46				sc = result.Response.Response.StatusCode
47			}
48			tracing.EndSpan(ctx, sc, err)
49		}()
50	}
51	if err := validation.Validate([]validation.Validation{
52		{TargetValue: client.SubscriptionID,
53			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}}},
54		{TargetValue: resourceGroupName,
55			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
58		return result, validation.NewError("security.ExternalSecuritySolutionsClient", "Get", err.Error())
59	}
60
61	req, err := client.GetPreparer(ctx, resourceGroupName, externalSecuritySolutionsName)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "Get", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.GetSender(req)
68	if err != nil {
69		result.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "Get", resp, "Failure sending request")
71		return
72	}
73
74	result, err = client.GetResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "Get", resp, "Failure responding to request")
77		return
78	}
79
80	return
81}
82
83// GetPreparer prepares the Get request.
84func (client ExternalSecuritySolutionsClient) GetPreparer(ctx context.Context, resourceGroupName string, externalSecuritySolutionsName string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"ascLocation":                   autorest.Encode("path", client.AscLocation),
87		"externalSecuritySolutionsName": autorest.Encode("path", externalSecuritySolutionsName),
88		"resourceGroupName":             autorest.Encode("path", resourceGroupName),
89		"subscriptionId":                autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2015-06-01-preview"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsGet(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/locations/{ascLocation}/ExternalSecuritySolutions/{externalSecuritySolutionsName}", pathParameters),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// GetSender sends the Get request. The method will close the
106// http.Response Body if it receives an error.
107func (client ExternalSecuritySolutionsClient) GetSender(req *http.Request) (*http.Response, error) {
108	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109}
110
111// GetResponder handles the response to the Get request. The method always
112// closes the http.Response Body.
113func (client ExternalSecuritySolutionsClient) GetResponder(resp *http.Response) (result ExternalSecuritySolutionModel, err error) {
114	err = autorest.Respond(
115		resp,
116		azure.WithErrorUnlessStatusCode(http.StatusOK),
117		autorest.ByUnmarshallingJSON(&result),
118		autorest.ByClosing())
119	result.Response = autorest.Response{Response: resp}
120	return
121}
122
123// List gets a list of external security solutions for the subscription.
124func (client ExternalSecuritySolutionsClient) List(ctx context.Context) (result ExternalSecuritySolutionListPage, err error) {
125	if tracing.IsEnabled() {
126		ctx = tracing.StartSpan(ctx, fqdn+"/ExternalSecuritySolutionsClient.List")
127		defer func() {
128			sc := -1
129			if result.essl.Response.Response != nil {
130				sc = result.essl.Response.Response.StatusCode
131			}
132			tracing.EndSpan(ctx, sc, err)
133		}()
134	}
135	if err := validation.Validate([]validation.Validation{
136		{TargetValue: client.SubscriptionID,
137			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 {
138		return result, validation.NewError("security.ExternalSecuritySolutionsClient", "List", err.Error())
139	}
140
141	result.fn = client.listNextResults
142	req, err := client.ListPreparer(ctx)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "List", nil, "Failure preparing request")
145		return
146	}
147
148	resp, err := client.ListSender(req)
149	if err != nil {
150		result.essl.Response = autorest.Response{Response: resp}
151		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "List", resp, "Failure sending request")
152		return
153	}
154
155	result.essl, err = client.ListResponder(resp)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "List", resp, "Failure responding to request")
158		return
159	}
160	if result.essl.hasNextLink() && result.essl.IsEmpty() {
161		err = result.NextWithContext(ctx)
162		return
163	}
164
165	return
166}
167
168// ListPreparer prepares the List request.
169func (client ExternalSecuritySolutionsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
170	pathParameters := map[string]interface{}{
171		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
172	}
173
174	const APIVersion = "2015-06-01-preview"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsGet(),
181		autorest.WithBaseURL(client.BaseURI),
182		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/externalSecuritySolutions", pathParameters),
183		autorest.WithQueryParameters(queryParameters))
184	return preparer.Prepare((&http.Request{}).WithContext(ctx))
185}
186
187// ListSender sends the List request. The method will close the
188// http.Response Body if it receives an error.
189func (client ExternalSecuritySolutionsClient) ListSender(req *http.Request) (*http.Response, error) {
190	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
191}
192
193// ListResponder handles the response to the List request. The method always
194// closes the http.Response Body.
195func (client ExternalSecuritySolutionsClient) ListResponder(resp *http.Response) (result ExternalSecuritySolutionList, err error) {
196	err = autorest.Respond(
197		resp,
198		azure.WithErrorUnlessStatusCode(http.StatusOK),
199		autorest.ByUnmarshallingJSON(&result),
200		autorest.ByClosing())
201	result.Response = autorest.Response{Response: resp}
202	return
203}
204
205// listNextResults retrieves the next set of results, if any.
206func (client ExternalSecuritySolutionsClient) listNextResults(ctx context.Context, lastResults ExternalSecuritySolutionList) (result ExternalSecuritySolutionList, err error) {
207	req, err := lastResults.externalSecuritySolutionListPreparer(ctx)
208	if err != nil {
209		return result, autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "listNextResults", nil, "Failure preparing next results request")
210	}
211	if req == nil {
212		return
213	}
214	resp, err := client.ListSender(req)
215	if err != nil {
216		result.Response = autorest.Response{Response: resp}
217		return result, autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "listNextResults", resp, "Failure sending next results request")
218	}
219	result, err = client.ListResponder(resp)
220	if err != nil {
221		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "listNextResults", resp, "Failure responding to next results request")
222	}
223	return
224}
225
226// ListComplete enumerates all values, automatically crossing page boundaries as required.
227func (client ExternalSecuritySolutionsClient) ListComplete(ctx context.Context) (result ExternalSecuritySolutionListIterator, err error) {
228	if tracing.IsEnabled() {
229		ctx = tracing.StartSpan(ctx, fqdn+"/ExternalSecuritySolutionsClient.List")
230		defer func() {
231			sc := -1
232			if result.Response().Response.Response != nil {
233				sc = result.page.Response().Response.Response.StatusCode
234			}
235			tracing.EndSpan(ctx, sc, err)
236		}()
237	}
238	result.page, err = client.List(ctx)
239	return
240}
241
242// ListByHomeRegion gets a list of external Security Solutions for the subscription and location.
243func (client ExternalSecuritySolutionsClient) ListByHomeRegion(ctx context.Context) (result ExternalSecuritySolutionListPage, err error) {
244	if tracing.IsEnabled() {
245		ctx = tracing.StartSpan(ctx, fqdn+"/ExternalSecuritySolutionsClient.ListByHomeRegion")
246		defer func() {
247			sc := -1
248			if result.essl.Response.Response != nil {
249				sc = result.essl.Response.Response.StatusCode
250			}
251			tracing.EndSpan(ctx, sc, err)
252		}()
253	}
254	if err := validation.Validate([]validation.Validation{
255		{TargetValue: client.SubscriptionID,
256			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 {
257		return result, validation.NewError("security.ExternalSecuritySolutionsClient", "ListByHomeRegion", err.Error())
258	}
259
260	result.fn = client.listByHomeRegionNextResults
261	req, err := client.ListByHomeRegionPreparer(ctx)
262	if err != nil {
263		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "ListByHomeRegion", nil, "Failure preparing request")
264		return
265	}
266
267	resp, err := client.ListByHomeRegionSender(req)
268	if err != nil {
269		result.essl.Response = autorest.Response{Response: resp}
270		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "ListByHomeRegion", resp, "Failure sending request")
271		return
272	}
273
274	result.essl, err = client.ListByHomeRegionResponder(resp)
275	if err != nil {
276		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "ListByHomeRegion", resp, "Failure responding to request")
277		return
278	}
279	if result.essl.hasNextLink() && result.essl.IsEmpty() {
280		err = result.NextWithContext(ctx)
281		return
282	}
283
284	return
285}
286
287// ListByHomeRegionPreparer prepares the ListByHomeRegion request.
288func (client ExternalSecuritySolutionsClient) ListByHomeRegionPreparer(ctx context.Context) (*http.Request, error) {
289	pathParameters := map[string]interface{}{
290		"ascLocation":    autorest.Encode("path", client.AscLocation),
291		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
292	}
293
294	const APIVersion = "2015-06-01-preview"
295	queryParameters := map[string]interface{}{
296		"api-version": APIVersion,
297	}
298
299	preparer := autorest.CreatePreparer(
300		autorest.AsGet(),
301		autorest.WithBaseURL(client.BaseURI),
302		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations/{ascLocation}/ExternalSecuritySolutions", pathParameters),
303		autorest.WithQueryParameters(queryParameters))
304	return preparer.Prepare((&http.Request{}).WithContext(ctx))
305}
306
307// ListByHomeRegionSender sends the ListByHomeRegion request. The method will close the
308// http.Response Body if it receives an error.
309func (client ExternalSecuritySolutionsClient) ListByHomeRegionSender(req *http.Request) (*http.Response, error) {
310	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
311}
312
313// ListByHomeRegionResponder handles the response to the ListByHomeRegion request. The method always
314// closes the http.Response Body.
315func (client ExternalSecuritySolutionsClient) ListByHomeRegionResponder(resp *http.Response) (result ExternalSecuritySolutionList, err error) {
316	err = autorest.Respond(
317		resp,
318		azure.WithErrorUnlessStatusCode(http.StatusOK),
319		autorest.ByUnmarshallingJSON(&result),
320		autorest.ByClosing())
321	result.Response = autorest.Response{Response: resp}
322	return
323}
324
325// listByHomeRegionNextResults retrieves the next set of results, if any.
326func (client ExternalSecuritySolutionsClient) listByHomeRegionNextResults(ctx context.Context, lastResults ExternalSecuritySolutionList) (result ExternalSecuritySolutionList, err error) {
327	req, err := lastResults.externalSecuritySolutionListPreparer(ctx)
328	if err != nil {
329		return result, autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "listByHomeRegionNextResults", nil, "Failure preparing next results request")
330	}
331	if req == nil {
332		return
333	}
334	resp, err := client.ListByHomeRegionSender(req)
335	if err != nil {
336		result.Response = autorest.Response{Response: resp}
337		return result, autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "listByHomeRegionNextResults", resp, "Failure sending next results request")
338	}
339	result, err = client.ListByHomeRegionResponder(resp)
340	if err != nil {
341		err = autorest.NewErrorWithError(err, "security.ExternalSecuritySolutionsClient", "listByHomeRegionNextResults", resp, "Failure responding to next results request")
342	}
343	return
344}
345
346// ListByHomeRegionComplete enumerates all values, automatically crossing page boundaries as required.
347func (client ExternalSecuritySolutionsClient) ListByHomeRegionComplete(ctx context.Context) (result ExternalSecuritySolutionListIterator, err error) {
348	if tracing.IsEnabled() {
349		ctx = tracing.StartSpan(ctx, fqdn+"/ExternalSecuritySolutionsClient.ListByHomeRegion")
350		defer func() {
351			sc := -1
352			if result.Response().Response.Response != nil {
353				sc = result.page.Response().Response.Response.StatusCode
354			}
355			tracing.EndSpan(ctx, sc, err)
356		}()
357	}
358	result.page, err = client.ListByHomeRegion(ctx)
359	return
360}
361