1package insights 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// LogProfilesClient is the monitor Management Client 30type LogProfilesClient struct { 31 BaseClient 32} 33 34// NewLogProfilesClient creates an instance of the LogProfilesClient client. 35func NewLogProfilesClient(subscriptionID string) LogProfilesClient { 36 return NewLogProfilesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewLogProfilesClientWithBaseURI creates an instance of the LogProfilesClient client using a custom endpoint. Use 40// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewLogProfilesClientWithBaseURI(baseURI string, subscriptionID string) LogProfilesClient { 42 return LogProfilesClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate create or update a log profile in Azure Monitoring REST API. 46// Parameters: 47// logProfileName - the name of the log profile. 48// parameters - parameters supplied to the operation. 49func (client LogProfilesClient) CreateOrUpdate(ctx context.Context, logProfileName string, parameters LogProfileResource) (result LogProfileResource, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.CreateOrUpdate") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 if err := validation.Validate([]validation.Validation{ 61 {TargetValue: parameters, 62 Constraints: []validation.Constraint{{Target: "parameters.LogProfileProperties", Name: validation.Null, Rule: true, 63 Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.Locations", Name: validation.Null, Rule: true, Chain: nil}, 64 {Target: "parameters.LogProfileProperties.Categories", Name: validation.Null, Rule: true, Chain: nil}, 65 {Target: "parameters.LogProfileProperties.RetentionPolicy", Name: validation.Null, Rule: true, 66 Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.RetentionPolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil}, 67 {Target: "parameters.LogProfileProperties.RetentionPolicy.Days", Name: validation.Null, Rule: true, 68 Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.RetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}, 69 }}, 70 }}}}}); err != nil { 71 return result, validation.NewError("insights.LogProfilesClient", "CreateOrUpdate", err.Error()) 72 } 73 74 req, err := client.CreateOrUpdatePreparer(ctx, logProfileName, parameters) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "CreateOrUpdate", nil, "Failure preparing request") 77 return 78 } 79 80 resp, err := client.CreateOrUpdateSender(req) 81 if err != nil { 82 result.Response = autorest.Response{Response: resp} 83 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "CreateOrUpdate", resp, "Failure sending request") 84 return 85 } 86 87 result, err = client.CreateOrUpdateResponder(resp) 88 if err != nil { 89 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "CreateOrUpdate", resp, "Failure responding to request") 90 } 91 92 return 93} 94 95// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 96func (client LogProfilesClient) CreateOrUpdatePreparer(ctx context.Context, logProfileName string, parameters LogProfileResource) (*http.Request, error) { 97 pathParameters := map[string]interface{}{ 98 "logProfileName": autorest.Encode("path", logProfileName), 99 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 100 } 101 102 const APIVersion = "2016-03-01" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 107 preparer := autorest.CreatePreparer( 108 autorest.AsContentType("application/json; charset=utf-8"), 109 autorest.AsPut(), 110 autorest.WithBaseURL(client.BaseURI), 111 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), 112 autorest.WithJSON(parameters), 113 autorest.WithQueryParameters(queryParameters)) 114 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 115} 116 117// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 118// http.Response Body if it receives an error. 119func (client LogProfilesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 120 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 121} 122 123// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 124// closes the http.Response Body. 125func (client LogProfilesClient) CreateOrUpdateResponder(resp *http.Response) (result LogProfileResource, err error) { 126 err = autorest.Respond( 127 resp, 128 client.ByInspecting(), 129 azure.WithErrorUnlessStatusCode(http.StatusOK), 130 autorest.ByUnmarshallingJSON(&result), 131 autorest.ByClosing()) 132 result.Response = autorest.Response{Response: resp} 133 return 134} 135 136// Delete deletes the log profile. 137// Parameters: 138// logProfileName - the name of the log profile. 139func (client LogProfilesClient) Delete(ctx context.Context, logProfileName string) (result autorest.Response, err error) { 140 if tracing.IsEnabled() { 141 ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.Delete") 142 defer func() { 143 sc := -1 144 if result.Response != nil { 145 sc = result.Response.StatusCode 146 } 147 tracing.EndSpan(ctx, sc, err) 148 }() 149 } 150 req, err := client.DeletePreparer(ctx, logProfileName) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Delete", nil, "Failure preparing request") 153 return 154 } 155 156 resp, err := client.DeleteSender(req) 157 if err != nil { 158 result.Response = resp 159 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Delete", resp, "Failure sending request") 160 return 161 } 162 163 result, err = client.DeleteResponder(resp) 164 if err != nil { 165 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Delete", resp, "Failure responding to request") 166 } 167 168 return 169} 170 171// DeletePreparer prepares the Delete request. 172func (client LogProfilesClient) DeletePreparer(ctx context.Context, logProfileName string) (*http.Request, error) { 173 pathParameters := map[string]interface{}{ 174 "logProfileName": autorest.Encode("path", logProfileName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2016-03-01" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsDelete(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// DeleteSender sends the Delete request. The method will close the 192// http.Response Body if it receives an error. 193func (client LogProfilesClient) DeleteSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 195} 196 197// DeleteResponder handles the response to the Delete request. The method always 198// closes the http.Response Body. 199func (client LogProfilesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 200 err = autorest.Respond( 201 resp, 202 client.ByInspecting(), 203 azure.WithErrorUnlessStatusCode(http.StatusOK), 204 autorest.ByClosing()) 205 result.Response = resp 206 return 207} 208 209// Get gets the log profile. 210// Parameters: 211// logProfileName - the name of the log profile. 212func (client LogProfilesClient) Get(ctx context.Context, logProfileName string) (result LogProfileResource, err error) { 213 if tracing.IsEnabled() { 214 ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.Get") 215 defer func() { 216 sc := -1 217 if result.Response.Response != nil { 218 sc = result.Response.Response.StatusCode 219 } 220 tracing.EndSpan(ctx, sc, err) 221 }() 222 } 223 req, err := client.GetPreparer(ctx, logProfileName) 224 if err != nil { 225 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Get", nil, "Failure preparing request") 226 return 227 } 228 229 resp, err := client.GetSender(req) 230 if err != nil { 231 result.Response = autorest.Response{Response: resp} 232 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Get", resp, "Failure sending request") 233 return 234 } 235 236 result, err = client.GetResponder(resp) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Get", resp, "Failure responding to request") 239 } 240 241 return 242} 243 244// GetPreparer prepares the Get request. 245func (client LogProfilesClient) GetPreparer(ctx context.Context, logProfileName string) (*http.Request, error) { 246 pathParameters := map[string]interface{}{ 247 "logProfileName": autorest.Encode("path", logProfileName), 248 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 249 } 250 251 const APIVersion = "2016-03-01" 252 queryParameters := map[string]interface{}{ 253 "api-version": APIVersion, 254 } 255 256 preparer := autorest.CreatePreparer( 257 autorest.AsGet(), 258 autorest.WithBaseURL(client.BaseURI), 259 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), 260 autorest.WithQueryParameters(queryParameters)) 261 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 262} 263 264// GetSender sends the Get request. The method will close the 265// http.Response Body if it receives an error. 266func (client LogProfilesClient) GetSender(req *http.Request) (*http.Response, error) { 267 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 268} 269 270// GetResponder handles the response to the Get request. The method always 271// closes the http.Response Body. 272func (client LogProfilesClient) GetResponder(resp *http.Response) (result LogProfileResource, err error) { 273 err = autorest.Respond( 274 resp, 275 client.ByInspecting(), 276 azure.WithErrorUnlessStatusCode(http.StatusOK), 277 autorest.ByUnmarshallingJSON(&result), 278 autorest.ByClosing()) 279 result.Response = autorest.Response{Response: resp} 280 return 281} 282 283// List list the log profiles. 284func (client LogProfilesClient) List(ctx context.Context) (result LogProfileCollection, err error) { 285 if tracing.IsEnabled() { 286 ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.List") 287 defer func() { 288 sc := -1 289 if result.Response.Response != nil { 290 sc = result.Response.Response.StatusCode 291 } 292 tracing.EndSpan(ctx, sc, err) 293 }() 294 } 295 req, err := client.ListPreparer(ctx) 296 if err != nil { 297 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "List", nil, "Failure preparing request") 298 return 299 } 300 301 resp, err := client.ListSender(req) 302 if err != nil { 303 result.Response = autorest.Response{Response: resp} 304 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "List", resp, "Failure sending request") 305 return 306 } 307 308 result, err = client.ListResponder(resp) 309 if err != nil { 310 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "List", resp, "Failure responding to request") 311 } 312 313 return 314} 315 316// ListPreparer prepares the List request. 317func (client LogProfilesClient) ListPreparer(ctx context.Context) (*http.Request, error) { 318 pathParameters := map[string]interface{}{ 319 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 320 } 321 322 const APIVersion = "2016-03-01" 323 queryParameters := map[string]interface{}{ 324 "api-version": APIVersion, 325 } 326 327 preparer := autorest.CreatePreparer( 328 autorest.AsGet(), 329 autorest.WithBaseURL(client.BaseURI), 330 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles", pathParameters), 331 autorest.WithQueryParameters(queryParameters)) 332 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 333} 334 335// ListSender sends the List request. The method will close the 336// http.Response Body if it receives an error. 337func (client LogProfilesClient) ListSender(req *http.Request) (*http.Response, error) { 338 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 339} 340 341// ListResponder handles the response to the List request. The method always 342// closes the http.Response Body. 343func (client LogProfilesClient) ListResponder(resp *http.Response) (result LogProfileCollection, err error) { 344 err = autorest.Respond( 345 resp, 346 client.ByInspecting(), 347 azure.WithErrorUnlessStatusCode(http.StatusOK), 348 autorest.ByUnmarshallingJSON(&result), 349 autorest.ByClosing()) 350 result.Response = autorest.Response{Response: resp} 351 return 352} 353 354// Update updates an existing LogProfilesResource. To update other fields use the CreateOrUpdate method. 355// Parameters: 356// logProfileName - the name of the log profile. 357// logProfilesResource - parameters supplied to the operation. 358func (client LogProfilesClient) Update(ctx context.Context, logProfileName string, logProfilesResource LogProfileResourcePatch) (result LogProfileResource, err error) { 359 if tracing.IsEnabled() { 360 ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.Update") 361 defer func() { 362 sc := -1 363 if result.Response.Response != nil { 364 sc = result.Response.Response.StatusCode 365 } 366 tracing.EndSpan(ctx, sc, err) 367 }() 368 } 369 req, err := client.UpdatePreparer(ctx, logProfileName, logProfilesResource) 370 if err != nil { 371 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Update", nil, "Failure preparing request") 372 return 373 } 374 375 resp, err := client.UpdateSender(req) 376 if err != nil { 377 result.Response = autorest.Response{Response: resp} 378 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Update", resp, "Failure sending request") 379 return 380 } 381 382 result, err = client.UpdateResponder(resp) 383 if err != nil { 384 err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Update", resp, "Failure responding to request") 385 } 386 387 return 388} 389 390// UpdatePreparer prepares the Update request. 391func (client LogProfilesClient) UpdatePreparer(ctx context.Context, logProfileName string, logProfilesResource LogProfileResourcePatch) (*http.Request, error) { 392 pathParameters := map[string]interface{}{ 393 "logProfileName": autorest.Encode("path", logProfileName), 394 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 395 } 396 397 const APIVersion = "2016-03-01" 398 queryParameters := map[string]interface{}{ 399 "api-version": APIVersion, 400 } 401 402 preparer := autorest.CreatePreparer( 403 autorest.AsContentType("application/json; charset=utf-8"), 404 autorest.AsPatch(), 405 autorest.WithBaseURL(client.BaseURI), 406 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters), 407 autorest.WithJSON(logProfilesResource), 408 autorest.WithQueryParameters(queryParameters)) 409 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 410} 411 412// UpdateSender sends the Update request. The method will close the 413// http.Response Body if it receives an error. 414func (client LogProfilesClient) UpdateSender(req *http.Request) (*http.Response, error) { 415 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 416} 417 418// UpdateResponder handles the response to the Update request. The method always 419// closes the http.Response Body. 420func (client LogProfilesClient) UpdateResponder(resp *http.Response) (result LogProfileResource, err error) { 421 err = autorest.Respond( 422 resp, 423 client.ByInspecting(), 424 azure.WithErrorUnlessStatusCode(http.StatusOK), 425 autorest.ByUnmarshallingJSON(&result), 426 autorest.ByClosing()) 427 result.Response = autorest.Response{Response: resp} 428 return 429} 430