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// IoTSecuritySolutionsClient is the API spec for Microsoft.Security (Azure Security Center) resource provider 19type IoTSecuritySolutionsClient struct { 20 BaseClient 21} 22 23// NewIoTSecuritySolutionsClient creates an instance of the IoTSecuritySolutionsClient client. 24func NewIoTSecuritySolutionsClient(subscriptionID string, ascLocation string) IoTSecuritySolutionsClient { 25 return NewIoTSecuritySolutionsClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation) 26} 27 28// NewIoTSecuritySolutionsClientWithBaseURI creates an instance of the IoTSecuritySolutionsClient client using a custom 29// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 30// stack). 31func NewIoTSecuritySolutionsClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) IoTSecuritySolutionsClient { 32 return IoTSecuritySolutionsClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)} 33} 34 35// List list of security solutions 36// Parameters: 37// filter - filter the Security Solution with OData syntax. supporting filter by iotHubs 38func (client IoTSecuritySolutionsClient) List(ctx context.Context, filter string) (result IoTSecuritySolutionsListPage, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/IoTSecuritySolutionsClient.List") 41 defer func() { 42 sc := -1 43 if result.itssl.Response.Response != nil { 44 sc = result.itssl.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 if err := validation.Validate([]validation.Validation{ 50 {TargetValue: client.SubscriptionID, 51 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 { 52 return result, validation.NewError("security.IoTSecuritySolutionsClient", "List", err.Error()) 53 } 54 55 result.fn = client.listNextResults 56 req, err := client.ListPreparer(ctx, filter) 57 if err != nil { 58 err = autorest.NewErrorWithError(err, "security.IoTSecuritySolutionsClient", "List", nil, "Failure preparing request") 59 return 60 } 61 62 resp, err := client.ListSender(req) 63 if err != nil { 64 result.itssl.Response = autorest.Response{Response: resp} 65 err = autorest.NewErrorWithError(err, "security.IoTSecuritySolutionsClient", "List", resp, "Failure sending request") 66 return 67 } 68 69 result.itssl, err = client.ListResponder(resp) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "security.IoTSecuritySolutionsClient", "List", resp, "Failure responding to request") 72 return 73 } 74 if result.itssl.hasNextLink() && result.itssl.IsEmpty() { 75 err = result.NextWithContext(ctx) 76 return 77 } 78 79 return 80} 81 82// ListPreparer prepares the List request. 83func (client IoTSecuritySolutionsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2017-08-01-preview" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 if len(filter) > 0 { 93 queryParameters["$filter"] = autorest.Encode("query", filter) 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsGet(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/iotSecuritySolutions", pathParameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// ListSender sends the List request. The method will close the 105// http.Response Body if it receives an error. 106func (client IoTSecuritySolutionsClient) ListSender(req *http.Request) (*http.Response, error) { 107 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 108} 109 110// ListResponder handles the response to the List request. The method always 111// closes the http.Response Body. 112func (client IoTSecuritySolutionsClient) ListResponder(resp *http.Response) (result IoTSecuritySolutionsList, err error) { 113 err = autorest.Respond( 114 resp, 115 azure.WithErrorUnlessStatusCode(http.StatusOK), 116 autorest.ByUnmarshallingJSON(&result), 117 autorest.ByClosing()) 118 result.Response = autorest.Response{Response: resp} 119 return 120} 121 122// listNextResults retrieves the next set of results, if any. 123func (client IoTSecuritySolutionsClient) listNextResults(ctx context.Context, lastResults IoTSecuritySolutionsList) (result IoTSecuritySolutionsList, err error) { 124 req, err := lastResults.ioTSecuritySolutionsListPreparer(ctx) 125 if err != nil { 126 return result, autorest.NewErrorWithError(err, "security.IoTSecuritySolutionsClient", "listNextResults", nil, "Failure preparing next results request") 127 } 128 if req == nil { 129 return 130 } 131 resp, err := client.ListSender(req) 132 if err != nil { 133 result.Response = autorest.Response{Response: resp} 134 return result, autorest.NewErrorWithError(err, "security.IoTSecuritySolutionsClient", "listNextResults", resp, "Failure sending next results request") 135 } 136 result, err = client.ListResponder(resp) 137 if err != nil { 138 err = autorest.NewErrorWithError(err, "security.IoTSecuritySolutionsClient", "listNextResults", resp, "Failure responding to next results request") 139 } 140 return 141} 142 143// ListComplete enumerates all values, automatically crossing page boundaries as required. 144func (client IoTSecuritySolutionsClient) ListComplete(ctx context.Context, filter string) (result IoTSecuritySolutionsListIterator, err error) { 145 if tracing.IsEnabled() { 146 ctx = tracing.StartSpan(ctx, fqdn+"/IoTSecuritySolutionsClient.List") 147 defer func() { 148 sc := -1 149 if result.Response().Response.Response != nil { 150 sc = result.page.Response().Response.Response.StatusCode 151 } 152 tracing.EndSpan(ctx, sc, err) 153 }() 154 } 155 result.page, err = client.List(ctx, filter) 156 return 157} 158