1package costmanagement 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/tracing" 14 "net/http" 15) 16 17// AlertsClient is the client for the Alerts methods of the Costmanagement service. 18type AlertsClient struct { 19 BaseClient 20} 21 22// NewAlertsClient creates an instance of the AlertsClient client. 23func NewAlertsClient(subscriptionID string) AlertsClient { 24 return NewAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewAlertsClientWithBaseURI creates an instance of the AlertsClient client using a custom endpoint. Use this when 28// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewAlertsClientWithBaseURI(baseURI string, subscriptionID string) AlertsClient { 30 return AlertsClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// Dismiss dismisses the specified alert 34// Parameters: 35// scope - the scope associated with alerts operations. This includes '/subscriptions/{subscriptionId}/' for 36// subscription scope, '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup 37// scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope and 38// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department 39// scope, 40// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' 41// for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId} for 42// Management Group scope, 43// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for 44// billingProfile scope, 45// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}/invoiceSections/{invoiceSectionId}' 46// for invoiceSection scope, and 47// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/customers/{customerId}' specific for 48// partners. 49// alertID - alert ID 50// parameters - parameters supplied to the Dismiss Alert operation. 51func (client AlertsClient) Dismiss(ctx context.Context, scope string, alertID string, parameters DismissAlertPayload) (result Alert, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.Dismiss") 54 defer func() { 55 sc := -1 56 if result.Response.Response != nil { 57 sc = result.Response.Response.StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 req, err := client.DismissPreparer(ctx, scope, alertID, parameters) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "Dismiss", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.DismissSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "Dismiss", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.DismissResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "Dismiss", resp, "Failure responding to request") 78 return 79 } 80 81 return 82} 83 84// DismissPreparer prepares the Dismiss request. 85func (client AlertsClient) DismissPreparer(ctx context.Context, scope string, alertID string, parameters DismissAlertPayload) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "alertId": alertID, 88 "scope": scope, 89 } 90 91 const APIVersion = "2020-06-01" 92 queryParameters := map[string]interface{}{ 93 "api-version": APIVersion, 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsContentType("application/json; charset=utf-8"), 98 autorest.AsPatch(), 99 autorest.WithBaseURL(client.BaseURI), 100 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/alerts/{alertId}", pathParameters), 101 autorest.WithJSON(parameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// DismissSender sends the Dismiss request. The method will close the 107// http.Response Body if it receives an error. 108func (client AlertsClient) DismissSender(req *http.Request) (*http.Response, error) { 109 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 110} 111 112// DismissResponder handles the response to the Dismiss request. The method always 113// closes the http.Response Body. 114func (client AlertsClient) DismissResponder(resp *http.Response) (result Alert, err error) { 115 err = autorest.Respond( 116 resp, 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// Get gets the alert for the scope by alert ID. 125// Parameters: 126// scope - the scope associated with alerts operations. This includes '/subscriptions/{subscriptionId}/' for 127// subscription scope, '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup 128// scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope and 129// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department 130// scope, 131// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' 132// for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId} for 133// Management Group scope, 134// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for 135// billingProfile scope, 136// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}/invoiceSections/{invoiceSectionId}' 137// for invoiceSection scope, and 138// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/customers/{customerId}' specific for 139// partners. 140// alertID - alert ID 141func (client AlertsClient) Get(ctx context.Context, scope string, alertID string) (result Alert, err error) { 142 if tracing.IsEnabled() { 143 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.Get") 144 defer func() { 145 sc := -1 146 if result.Response.Response != nil { 147 sc = result.Response.Response.StatusCode 148 } 149 tracing.EndSpan(ctx, sc, err) 150 }() 151 } 152 req, err := client.GetPreparer(ctx, scope, alertID) 153 if err != nil { 154 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "Get", nil, "Failure preparing request") 155 return 156 } 157 158 resp, err := client.GetSender(req) 159 if err != nil { 160 result.Response = autorest.Response{Response: resp} 161 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "Get", resp, "Failure sending request") 162 return 163 } 164 165 result, err = client.GetResponder(resp) 166 if err != nil { 167 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "Get", resp, "Failure responding to request") 168 return 169 } 170 171 return 172} 173 174// GetPreparer prepares the Get request. 175func (client AlertsClient) GetPreparer(ctx context.Context, scope string, alertID string) (*http.Request, error) { 176 pathParameters := map[string]interface{}{ 177 "alertId": alertID, 178 "scope": scope, 179 } 180 181 const APIVersion = "2020-06-01" 182 queryParameters := map[string]interface{}{ 183 "api-version": APIVersion, 184 } 185 186 preparer := autorest.CreatePreparer( 187 autorest.AsGet(), 188 autorest.WithBaseURL(client.BaseURI), 189 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/alerts/{alertId}", pathParameters), 190 autorest.WithQueryParameters(queryParameters)) 191 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 192} 193 194// GetSender sends the Get request. The method will close the 195// http.Response Body if it receives an error. 196func (client AlertsClient) GetSender(req *http.Request) (*http.Response, error) { 197 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 198} 199 200// GetResponder handles the response to the Get request. The method always 201// closes the http.Response Body. 202func (client AlertsClient) GetResponder(resp *http.Response) (result Alert, err error) { 203 err = autorest.Respond( 204 resp, 205 azure.WithErrorUnlessStatusCode(http.StatusOK), 206 autorest.ByUnmarshallingJSON(&result), 207 autorest.ByClosing()) 208 result.Response = autorest.Response{Response: resp} 209 return 210} 211 212// List lists the alerts for scope defined. 213// Parameters: 214// scope - the scope associated with alerts operations. This includes '/subscriptions/{subscriptionId}/' for 215// subscription scope, '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup 216// scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope and 217// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department 218// scope, 219// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' 220// for EnrollmentAccount scope, '/providers/Microsoft.Management/managementGroups/{managementGroupId} for 221// Management Group scope, 222// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for 223// billingProfile scope, 224// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}/invoiceSections/{invoiceSectionId}' 225// for invoiceSection scope, and 226// '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/customers/{customerId}' specific for 227// partners. 228func (client AlertsClient) List(ctx context.Context, scope string) (result AlertsResult, err error) { 229 if tracing.IsEnabled() { 230 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.List") 231 defer func() { 232 sc := -1 233 if result.Response.Response != nil { 234 sc = result.Response.Response.StatusCode 235 } 236 tracing.EndSpan(ctx, sc, err) 237 }() 238 } 239 req, err := client.ListPreparer(ctx, scope) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "List", nil, "Failure preparing request") 242 return 243 } 244 245 resp, err := client.ListSender(req) 246 if err != nil { 247 result.Response = autorest.Response{Response: resp} 248 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "List", resp, "Failure sending request") 249 return 250 } 251 252 result, err = client.ListResponder(resp) 253 if err != nil { 254 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "List", resp, "Failure responding to request") 255 return 256 } 257 258 return 259} 260 261// ListPreparer prepares the List request. 262func (client AlertsClient) ListPreparer(ctx context.Context, scope string) (*http.Request, error) { 263 pathParameters := map[string]interface{}{ 264 "scope": scope, 265 } 266 267 const APIVersion = "2020-06-01" 268 queryParameters := map[string]interface{}{ 269 "api-version": APIVersion, 270 } 271 272 preparer := autorest.CreatePreparer( 273 autorest.AsGet(), 274 autorest.WithBaseURL(client.BaseURI), 275 autorest.WithPathParameters("/{scope}/providers/Microsoft.CostManagement/alerts", pathParameters), 276 autorest.WithQueryParameters(queryParameters)) 277 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 278} 279 280// ListSender sends the List request. The method will close the 281// http.Response Body if it receives an error. 282func (client AlertsClient) ListSender(req *http.Request) (*http.Response, error) { 283 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 284} 285 286// ListResponder handles the response to the List request. The method always 287// closes the http.Response Body. 288func (client AlertsClient) ListResponder(resp *http.Response) (result AlertsResult, err error) { 289 err = autorest.Respond( 290 resp, 291 azure.WithErrorUnlessStatusCode(http.StatusOK), 292 autorest.ByUnmarshallingJSON(&result), 293 autorest.ByClosing()) 294 result.Response = autorest.Response{Response: resp} 295 return 296} 297 298// ListExternal lists the Alerts for external cloud provider type defined. 299// Parameters: 300// externalCloudProviderType - the external cloud provider type associated with dimension/query operations. 301// This includes 'externalSubscriptions' for linked account and 'externalBillingAccounts' for consolidated 302// account. 303// externalCloudProviderID - this can be '{externalSubscriptionId}' for linked account or 304// '{externalBillingAccountId}' for consolidated account used with dimension/query operations. 305func (client AlertsClient) ListExternal(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string) (result AlertsResult, err error) { 306 if tracing.IsEnabled() { 307 ctx = tracing.StartSpan(ctx, fqdn+"/AlertsClient.ListExternal") 308 defer func() { 309 sc := -1 310 if result.Response.Response != nil { 311 sc = result.Response.Response.StatusCode 312 } 313 tracing.EndSpan(ctx, sc, err) 314 }() 315 } 316 req, err := client.ListExternalPreparer(ctx, externalCloudProviderType, externalCloudProviderID) 317 if err != nil { 318 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "ListExternal", nil, "Failure preparing request") 319 return 320 } 321 322 resp, err := client.ListExternalSender(req) 323 if err != nil { 324 result.Response = autorest.Response{Response: resp} 325 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "ListExternal", resp, "Failure sending request") 326 return 327 } 328 329 result, err = client.ListExternalResponder(resp) 330 if err != nil { 331 err = autorest.NewErrorWithError(err, "costmanagement.AlertsClient", "ListExternal", resp, "Failure responding to request") 332 return 333 } 334 335 return 336} 337 338// ListExternalPreparer prepares the ListExternal request. 339func (client AlertsClient) ListExternalPreparer(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string) (*http.Request, error) { 340 pathParameters := map[string]interface{}{ 341 "externalCloudProviderId": autorest.Encode("path", externalCloudProviderID), 342 "externalCloudProviderType": autorest.Encode("path", externalCloudProviderType), 343 } 344 345 const APIVersion = "2020-06-01" 346 queryParameters := map[string]interface{}{ 347 "api-version": APIVersion, 348 } 349 350 preparer := autorest.CreatePreparer( 351 autorest.AsGet(), 352 autorest.WithBaseURL(client.BaseURI), 353 autorest.WithPathParameters("/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/alerts", pathParameters), 354 autorest.WithQueryParameters(queryParameters)) 355 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 356} 357 358// ListExternalSender sends the ListExternal request. The method will close the 359// http.Response Body if it receives an error. 360func (client AlertsClient) ListExternalSender(req *http.Request) (*http.Response, error) { 361 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 362} 363 364// ListExternalResponder handles the response to the ListExternal request. The method always 365// closes the http.Response Body. 366func (client AlertsClient) ListExternalResponder(resp *http.Response) (result AlertsResult, err error) { 367 err = autorest.Respond( 368 resp, 369 azure.WithErrorUnlessStatusCode(http.StatusOK), 370 autorest.ByUnmarshallingJSON(&result), 371 autorest.ByClosing()) 372 result.Response = autorest.Response{Response: resp} 373 return 374} 375