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