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