1package network 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// FlowLogsClient is the network Client 19type FlowLogsClient struct { 20 BaseClient 21} 22 23// NewFlowLogsClient creates an instance of the FlowLogsClient client. 24func NewFlowLogsClient(subscriptionID string) FlowLogsClient { 25 return NewFlowLogsClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewFlowLogsClientWithBaseURI creates an instance of the FlowLogsClient 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 NewFlowLogsClientWithBaseURI(baseURI string, subscriptionID string) FlowLogsClient { 31 return FlowLogsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate create or update a flow log for the specified network security group. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// networkWatcherName - the name of the network watcher. 38// flowLogName - the name of the flow log. 39// parameters - parameters that define the create or update flow log resource. 40func (client FlowLogsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters FlowLog) (result FlowLogsCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/FlowLogsClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.FlowLogPropertiesFormat", Name: validation.Null, Rule: false, 54 Chain: []validation.Constraint{{Target: "parameters.FlowLogPropertiesFormat.TargetResourceID", Name: validation.Null, Rule: true, Chain: nil}, 55 {Target: "parameters.FlowLogPropertiesFormat.StorageID", Name: validation.Null, Rule: true, Chain: nil}, 56 }}}}}); err != nil { 57 return result, validation.NewError("network.FlowLogsClient", "CreateOrUpdate", err.Error()) 58 } 59 60 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, networkWatcherName, flowLogName, parameters) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "CreateOrUpdate", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.CreateOrUpdateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "CreateOrUpdate", nil, "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 76func (client FlowLogsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters FlowLog) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "flowLogName": autorest.Encode("path", flowLogName), 79 "networkWatcherName": autorest.Encode("path", networkWatcherName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2020-06-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 parameters.Etag = nil 90 preparer := autorest.CreatePreparer( 91 autorest.AsContentType("application/json; charset=utf-8"), 92 autorest.AsPut(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/flowLogs/{flowLogName}", pathParameters), 95 autorest.WithJSON(parameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 101// http.Response Body if it receives an error. 102func (client FlowLogsClient) CreateOrUpdateSender(req *http.Request) (future FlowLogsCreateOrUpdateFuture, err error) { 103 var resp *http.Response 104 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105 if err != nil { 106 return 107 } 108 var azf azure.Future 109 azf, err = azure.NewFutureFromResponse(resp) 110 future.FutureAPI = &azf 111 future.Result = future.result 112 return 113} 114 115// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 116// closes the http.Response Body. 117func (client FlowLogsClient) CreateOrUpdateResponder(resp *http.Response) (result FlowLog, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Delete deletes the specified flow log resource. 128// Parameters: 129// resourceGroupName - the name of the resource group. 130// networkWatcherName - the name of the network watcher. 131// flowLogName - the name of the flow log resource. 132func (client FlowLogsClient) Delete(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string) (result FlowLogsDeleteFuture, err error) { 133 if tracing.IsEnabled() { 134 ctx = tracing.StartSpan(ctx, fqdn+"/FlowLogsClient.Delete") 135 defer func() { 136 sc := -1 137 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 138 sc = result.FutureAPI.Response().StatusCode 139 } 140 tracing.EndSpan(ctx, sc, err) 141 }() 142 } 143 req, err := client.DeletePreparer(ctx, resourceGroupName, networkWatcherName, flowLogName) 144 if err != nil { 145 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "Delete", nil, "Failure preparing request") 146 return 147 } 148 149 result, err = client.DeleteSender(req) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "Delete", nil, "Failure sending request") 152 return 153 } 154 155 return 156} 157 158// DeletePreparer prepares the Delete request. 159func (client FlowLogsClient) DeletePreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "flowLogName": autorest.Encode("path", flowLogName), 162 "networkWatcherName": autorest.Encode("path", networkWatcherName), 163 "resourceGroupName": autorest.Encode("path", resourceGroupName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 } 166 167 const APIVersion = "2020-06-01" 168 queryParameters := map[string]interface{}{ 169 "api-version": APIVersion, 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsDelete(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/flowLogs/{flowLogName}", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// DeleteSender sends the Delete request. The method will close the 181// http.Response Body if it receives an error. 182func (client FlowLogsClient) DeleteSender(req *http.Request) (future FlowLogsDeleteFuture, err error) { 183 var resp *http.Response 184 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 185 if err != nil { 186 return 187 } 188 var azf azure.Future 189 azf, err = azure.NewFutureFromResponse(resp) 190 future.FutureAPI = &azf 191 future.Result = future.result 192 return 193} 194 195// DeleteResponder handles the response to the Delete request. The method always 196// closes the http.Response Body. 197func (client FlowLogsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 198 err = autorest.Respond( 199 resp, 200 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 201 autorest.ByClosing()) 202 result.Response = resp 203 return 204} 205 206// Get gets a flow log resource by name. 207// Parameters: 208// resourceGroupName - the name of the resource group. 209// networkWatcherName - the name of the network watcher. 210// flowLogName - the name of the flow log resource. 211func (client FlowLogsClient) Get(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string) (result FlowLog, err error) { 212 if tracing.IsEnabled() { 213 ctx = tracing.StartSpan(ctx, fqdn+"/FlowLogsClient.Get") 214 defer func() { 215 sc := -1 216 if result.Response.Response != nil { 217 sc = result.Response.Response.StatusCode 218 } 219 tracing.EndSpan(ctx, sc, err) 220 }() 221 } 222 req, err := client.GetPreparer(ctx, resourceGroupName, networkWatcherName, flowLogName) 223 if err != nil { 224 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "Get", nil, "Failure preparing request") 225 return 226 } 227 228 resp, err := client.GetSender(req) 229 if err != nil { 230 result.Response = autorest.Response{Response: resp} 231 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "Get", resp, "Failure sending request") 232 return 233 } 234 235 result, err = client.GetResponder(resp) 236 if err != nil { 237 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "Get", resp, "Failure responding to request") 238 return 239 } 240 241 return 242} 243 244// GetPreparer prepares the Get request. 245func (client FlowLogsClient) GetPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string) (*http.Request, error) { 246 pathParameters := map[string]interface{}{ 247 "flowLogName": autorest.Encode("path", flowLogName), 248 "networkWatcherName": autorest.Encode("path", networkWatcherName), 249 "resourceGroupName": autorest.Encode("path", resourceGroupName), 250 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 251 } 252 253 const APIVersion = "2020-06-01" 254 queryParameters := map[string]interface{}{ 255 "api-version": APIVersion, 256 } 257 258 preparer := autorest.CreatePreparer( 259 autorest.AsGet(), 260 autorest.WithBaseURL(client.BaseURI), 261 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/flowLogs/{flowLogName}", pathParameters), 262 autorest.WithQueryParameters(queryParameters)) 263 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 264} 265 266// GetSender sends the Get request. The method will close the 267// http.Response Body if it receives an error. 268func (client FlowLogsClient) GetSender(req *http.Request) (*http.Response, error) { 269 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 270} 271 272// GetResponder handles the response to the Get request. The method always 273// closes the http.Response Body. 274func (client FlowLogsClient) GetResponder(resp *http.Response) (result FlowLog, err error) { 275 err = autorest.Respond( 276 resp, 277 azure.WithErrorUnlessStatusCode(http.StatusOK), 278 autorest.ByUnmarshallingJSON(&result), 279 autorest.ByClosing()) 280 result.Response = autorest.Response{Response: resp} 281 return 282} 283 284// List lists all flow log resources for the specified Network Watcher. 285// Parameters: 286// resourceGroupName - the name of the resource group containing Network Watcher. 287// networkWatcherName - the name of the Network Watcher resource. 288func (client FlowLogsClient) List(ctx context.Context, resourceGroupName string, networkWatcherName string) (result FlowLogListResultPage, err error) { 289 if tracing.IsEnabled() { 290 ctx = tracing.StartSpan(ctx, fqdn+"/FlowLogsClient.List") 291 defer func() { 292 sc := -1 293 if result.fllr.Response.Response != nil { 294 sc = result.fllr.Response.Response.StatusCode 295 } 296 tracing.EndSpan(ctx, sc, err) 297 }() 298 } 299 result.fn = client.listNextResults 300 req, err := client.ListPreparer(ctx, resourceGroupName, networkWatcherName) 301 if err != nil { 302 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "List", nil, "Failure preparing request") 303 return 304 } 305 306 resp, err := client.ListSender(req) 307 if err != nil { 308 result.fllr.Response = autorest.Response{Response: resp} 309 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "List", resp, "Failure sending request") 310 return 311 } 312 313 result.fllr, err = client.ListResponder(resp) 314 if err != nil { 315 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "List", resp, "Failure responding to request") 316 return 317 } 318 if result.fllr.hasNextLink() && result.fllr.IsEmpty() { 319 err = result.NextWithContext(ctx) 320 return 321 } 322 323 return 324} 325 326// ListPreparer prepares the List request. 327func (client FlowLogsClient) ListPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string) (*http.Request, error) { 328 pathParameters := map[string]interface{}{ 329 "networkWatcherName": autorest.Encode("path", networkWatcherName), 330 "resourceGroupName": autorest.Encode("path", resourceGroupName), 331 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 332 } 333 334 const APIVersion = "2020-06-01" 335 queryParameters := map[string]interface{}{ 336 "api-version": APIVersion, 337 } 338 339 preparer := autorest.CreatePreparer( 340 autorest.AsGet(), 341 autorest.WithBaseURL(client.BaseURI), 342 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/flowLogs", pathParameters), 343 autorest.WithQueryParameters(queryParameters)) 344 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 345} 346 347// ListSender sends the List request. The method will close the 348// http.Response Body if it receives an error. 349func (client FlowLogsClient) ListSender(req *http.Request) (*http.Response, error) { 350 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 351} 352 353// ListResponder handles the response to the List request. The method always 354// closes the http.Response Body. 355func (client FlowLogsClient) ListResponder(resp *http.Response) (result FlowLogListResult, err error) { 356 err = autorest.Respond( 357 resp, 358 azure.WithErrorUnlessStatusCode(http.StatusOK), 359 autorest.ByUnmarshallingJSON(&result), 360 autorest.ByClosing()) 361 result.Response = autorest.Response{Response: resp} 362 return 363} 364 365// listNextResults retrieves the next set of results, if any. 366func (client FlowLogsClient) listNextResults(ctx context.Context, lastResults FlowLogListResult) (result FlowLogListResult, err error) { 367 req, err := lastResults.flowLogListResultPreparer(ctx) 368 if err != nil { 369 return result, autorest.NewErrorWithError(err, "network.FlowLogsClient", "listNextResults", nil, "Failure preparing next results request") 370 } 371 if req == nil { 372 return 373 } 374 resp, err := client.ListSender(req) 375 if err != nil { 376 result.Response = autorest.Response{Response: resp} 377 return result, autorest.NewErrorWithError(err, "network.FlowLogsClient", "listNextResults", resp, "Failure sending next results request") 378 } 379 result, err = client.ListResponder(resp) 380 if err != nil { 381 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "listNextResults", resp, "Failure responding to next results request") 382 } 383 return 384} 385 386// ListComplete enumerates all values, automatically crossing page boundaries as required. 387func (client FlowLogsClient) ListComplete(ctx context.Context, resourceGroupName string, networkWatcherName string) (result FlowLogListResultIterator, err error) { 388 if tracing.IsEnabled() { 389 ctx = tracing.StartSpan(ctx, fqdn+"/FlowLogsClient.List") 390 defer func() { 391 sc := -1 392 if result.Response().Response.Response != nil { 393 sc = result.page.Response().Response.Response.StatusCode 394 } 395 tracing.EndSpan(ctx, sc, err) 396 }() 397 } 398 result.page, err = client.List(ctx, resourceGroupName, networkWatcherName) 399 return 400} 401 402// UpdateTags update tags of the specified flow log. 403// Parameters: 404// resourceGroupName - the name of the resource group. 405// networkWatcherName - the name of the network watcher. 406// flowLogName - the name of the flow log. 407// parameters - parameters supplied to update flow log tags. 408func (client FlowLogsClient) UpdateTags(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters TagsObject) (result FlowLog, err error) { 409 if tracing.IsEnabled() { 410 ctx = tracing.StartSpan(ctx, fqdn+"/FlowLogsClient.UpdateTags") 411 defer func() { 412 sc := -1 413 if result.Response.Response != nil { 414 sc = result.Response.Response.StatusCode 415 } 416 tracing.EndSpan(ctx, sc, err) 417 }() 418 } 419 req, err := client.UpdateTagsPreparer(ctx, resourceGroupName, networkWatcherName, flowLogName, parameters) 420 if err != nil { 421 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "UpdateTags", nil, "Failure preparing request") 422 return 423 } 424 425 resp, err := client.UpdateTagsSender(req) 426 if err != nil { 427 result.Response = autorest.Response{Response: resp} 428 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "UpdateTags", resp, "Failure sending request") 429 return 430 } 431 432 result, err = client.UpdateTagsResponder(resp) 433 if err != nil { 434 err = autorest.NewErrorWithError(err, "network.FlowLogsClient", "UpdateTags", resp, "Failure responding to request") 435 return 436 } 437 438 return 439} 440 441// UpdateTagsPreparer prepares the UpdateTags request. 442func (client FlowLogsClient) UpdateTagsPreparer(ctx context.Context, resourceGroupName string, networkWatcherName string, flowLogName string, parameters TagsObject) (*http.Request, error) { 443 pathParameters := map[string]interface{}{ 444 "flowLogName": autorest.Encode("path", flowLogName), 445 "networkWatcherName": autorest.Encode("path", networkWatcherName), 446 "resourceGroupName": autorest.Encode("path", resourceGroupName), 447 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 448 } 449 450 const APIVersion = "2020-06-01" 451 queryParameters := map[string]interface{}{ 452 "api-version": APIVersion, 453 } 454 455 preparer := autorest.CreatePreparer( 456 autorest.AsContentType("application/json; charset=utf-8"), 457 autorest.AsPatch(), 458 autorest.WithBaseURL(client.BaseURI), 459 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/flowLogs/{flowLogName}", pathParameters), 460 autorest.WithJSON(parameters), 461 autorest.WithQueryParameters(queryParameters)) 462 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 463} 464 465// UpdateTagsSender sends the UpdateTags request. The method will close the 466// http.Response Body if it receives an error. 467func (client FlowLogsClient) UpdateTagsSender(req *http.Request) (*http.Response, error) { 468 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 469} 470 471// UpdateTagsResponder handles the response to the UpdateTags request. The method always 472// closes the http.Response Body. 473func (client FlowLogsClient) UpdateTagsResponder(resp *http.Response) (result FlowLog, err error) { 474 err = autorest.Respond( 475 resp, 476 azure.WithErrorUnlessStatusCode(http.StatusOK), 477 autorest.ByUnmarshallingJSON(&result), 478 autorest.ByClosing()) 479 result.Response = autorest.Response{Response: resp} 480 return 481} 482