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