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