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// LocationsClient is the API spec for Microsoft.Security (Azure Security Center) resource provider 19type LocationsClient struct { 20 BaseClient 21} 22 23// NewLocationsClient creates an instance of the LocationsClient client. 24func NewLocationsClient(subscriptionID string, ascLocation string) LocationsClient { 25 return NewLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation) 26} 27 28// NewLocationsClientWithBaseURI creates an instance of the LocationsClient client using a custom endpoint. Use this 29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 30func NewLocationsClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) LocationsClient { 31 return LocationsClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)} 32} 33 34// Get details of a specific location 35func (client LocationsClient) Get(ctx context.Context) (result AscLocation, err error) { 36 if tracing.IsEnabled() { 37 ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.Get") 38 defer func() { 39 sc := -1 40 if result.Response.Response != nil { 41 sc = result.Response.Response.StatusCode 42 } 43 tracing.EndSpan(ctx, sc, err) 44 }() 45 } 46 if err := validation.Validate([]validation.Validation{ 47 {TargetValue: client.SubscriptionID, 48 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 { 49 return result, validation.NewError("security.LocationsClient", "Get", err.Error()) 50 } 51 52 req, err := client.GetPreparer(ctx) 53 if err != nil { 54 err = autorest.NewErrorWithError(err, "security.LocationsClient", "Get", nil, "Failure preparing request") 55 return 56 } 57 58 resp, err := client.GetSender(req) 59 if err != nil { 60 result.Response = autorest.Response{Response: resp} 61 err = autorest.NewErrorWithError(err, "security.LocationsClient", "Get", resp, "Failure sending request") 62 return 63 } 64 65 result, err = client.GetResponder(resp) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "security.LocationsClient", "Get", resp, "Failure responding to request") 68 return 69 } 70 71 return 72} 73 74// GetPreparer prepares the Get request. 75func (client LocationsClient) GetPreparer(ctx context.Context) (*http.Request, error) { 76 pathParameters := map[string]interface{}{ 77 "ascLocation": autorest.Encode("path", client.AscLocation), 78 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 79 } 80 81 const APIVersion = "2015-06-01-preview" 82 queryParameters := map[string]interface{}{ 83 "api-version": APIVersion, 84 } 85 86 preparer := autorest.CreatePreparer( 87 autorest.AsGet(), 88 autorest.WithBaseURL(client.BaseURI), 89 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations/{ascLocation}", pathParameters), 90 autorest.WithQueryParameters(queryParameters)) 91 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 92} 93 94// GetSender sends the Get request. The method will close the 95// http.Response Body if it receives an error. 96func (client LocationsClient) GetSender(req *http.Request) (*http.Response, error) { 97 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 98} 99 100// GetResponder handles the response to the Get request. The method always 101// closes the http.Response Body. 102func (client LocationsClient) GetResponder(resp *http.Response) (result AscLocation, err error) { 103 err = autorest.Respond( 104 resp, 105 azure.WithErrorUnlessStatusCode(http.StatusOK), 106 autorest.ByUnmarshallingJSON(&result), 107 autorest.ByClosing()) 108 result.Response = autorest.Response{Response: resp} 109 return 110} 111 112// List the location of the responsible ASC of the specific subscription (home region). For each subscription there is 113// only one responsible location. The location in the response should be used to read or write other resources in ASC 114// according to their ID. 115func (client LocationsClient) List(ctx context.Context) (result AscLocationListPage, err error) { 116 if tracing.IsEnabled() { 117 ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.List") 118 defer func() { 119 sc := -1 120 if result.all.Response.Response != nil { 121 sc = result.all.Response.Response.StatusCode 122 } 123 tracing.EndSpan(ctx, sc, err) 124 }() 125 } 126 if err := validation.Validate([]validation.Validation{ 127 {TargetValue: client.SubscriptionID, 128 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 { 129 return result, validation.NewError("security.LocationsClient", "List", err.Error()) 130 } 131 132 result.fn = client.listNextResults 133 req, err := client.ListPreparer(ctx) 134 if err != nil { 135 err = autorest.NewErrorWithError(err, "security.LocationsClient", "List", nil, "Failure preparing request") 136 return 137 } 138 139 resp, err := client.ListSender(req) 140 if err != nil { 141 result.all.Response = autorest.Response{Response: resp} 142 err = autorest.NewErrorWithError(err, "security.LocationsClient", "List", resp, "Failure sending request") 143 return 144 } 145 146 result.all, err = client.ListResponder(resp) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "security.LocationsClient", "List", resp, "Failure responding to request") 149 return 150 } 151 if result.all.hasNextLink() && result.all.IsEmpty() { 152 err = result.NextWithContext(ctx) 153 return 154 } 155 156 return 157} 158 159// ListPreparer prepares the List request. 160func (client LocationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 161 pathParameters := map[string]interface{}{ 162 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 163 } 164 165 const APIVersion = "2015-06-01-preview" 166 queryParameters := map[string]interface{}{ 167 "api-version": APIVersion, 168 } 169 170 preparer := autorest.CreatePreparer( 171 autorest.AsGet(), 172 autorest.WithBaseURL(client.BaseURI), 173 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations", pathParameters), 174 autorest.WithQueryParameters(queryParameters)) 175 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 176} 177 178// ListSender sends the List request. The method will close the 179// http.Response Body if it receives an error. 180func (client LocationsClient) ListSender(req *http.Request) (*http.Response, error) { 181 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 182} 183 184// ListResponder handles the response to the List request. The method always 185// closes the http.Response Body. 186func (client LocationsClient) ListResponder(resp *http.Response) (result AscLocationList, err error) { 187 err = autorest.Respond( 188 resp, 189 azure.WithErrorUnlessStatusCode(http.StatusOK), 190 autorest.ByUnmarshallingJSON(&result), 191 autorest.ByClosing()) 192 result.Response = autorest.Response{Response: resp} 193 return 194} 195 196// listNextResults retrieves the next set of results, if any. 197func (client LocationsClient) listNextResults(ctx context.Context, lastResults AscLocationList) (result AscLocationList, err error) { 198 req, err := lastResults.ascLocationListPreparer(ctx) 199 if err != nil { 200 return result, autorest.NewErrorWithError(err, "security.LocationsClient", "listNextResults", nil, "Failure preparing next results request") 201 } 202 if req == nil { 203 return 204 } 205 resp, err := client.ListSender(req) 206 if err != nil { 207 result.Response = autorest.Response{Response: resp} 208 return result, autorest.NewErrorWithError(err, "security.LocationsClient", "listNextResults", resp, "Failure sending next results request") 209 } 210 result, err = client.ListResponder(resp) 211 if err != nil { 212 err = autorest.NewErrorWithError(err, "security.LocationsClient", "listNextResults", resp, "Failure responding to next results request") 213 } 214 return 215} 216 217// ListComplete enumerates all values, automatically crossing page boundaries as required. 218func (client LocationsClient) ListComplete(ctx context.Context) (result AscLocationListIterator, err error) { 219 if tracing.IsEnabled() { 220 ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.List") 221 defer func() { 222 sc := -1 223 if result.Response().Response.Response != nil { 224 sc = result.page.Response().Response.Response.StatusCode 225 } 226 tracing.EndSpan(ctx, sc, err) 227 }() 228 } 229 result.page, err = client.List(ctx) 230 return 231} 232