1package automation 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// UsagesClient is the automation Client 30type UsagesClient struct { 31 BaseClient 32} 33 34// NewUsagesClient creates an instance of the UsagesClient client. 35func NewUsagesClient(subscriptionID string) UsagesClient { 36 return NewUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewUsagesClientWithBaseURI creates an instance of the UsagesClient client using a custom endpoint. Use this when 40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewUsagesClientWithBaseURI(baseURI string, subscriptionID string) UsagesClient { 42 return UsagesClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// ListByAutomationAccount retrieve the usage for the account id. 46// Parameters: 47// resourceGroupName - name of an Azure Resource group. 48// automationAccountName - the name of the automation account. 49func (client UsagesClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string) (result UsageListResult, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.ListByAutomationAccount") 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: resourceGroupName, 62 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 63 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 64 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 65 return result, validation.NewError("automation.UsagesClient", "ListByAutomationAccount", err.Error()) 66 } 67 68 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "automation.UsagesClient", "ListByAutomationAccount", nil, "Failure preparing request") 71 return 72 } 73 74 resp, err := client.ListByAutomationAccountSender(req) 75 if err != nil { 76 result.Response = autorest.Response{Response: resp} 77 err = autorest.NewErrorWithError(err, "automation.UsagesClient", "ListByAutomationAccount", resp, "Failure sending request") 78 return 79 } 80 81 result, err = client.ListByAutomationAccountResponder(resp) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "automation.UsagesClient", "ListByAutomationAccount", resp, "Failure responding to request") 84 } 85 86 return 87} 88 89// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 90func (client UsagesClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string) (*http.Request, error) { 91 pathParameters := map[string]interface{}{ 92 "automationAccountName": autorest.Encode("path", automationAccountName), 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 } 96 97 const APIVersion = "2015-10-31" 98 queryParameters := map[string]interface{}{ 99 "api-version": APIVersion, 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsGet(), 104 autorest.WithBaseURL(client.BaseURI), 105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/usages", pathParameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 111// http.Response Body if it receives an error. 112func (client UsagesClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 113 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 114} 115 116// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 117// closes the http.Response Body. 118func (client UsagesClient) ListByAutomationAccountResponder(resp *http.Response) (result UsageListResult, err error) { 119 err = autorest.Respond( 120 resp, 121 client.ByInspecting(), 122 azure.WithErrorUnlessStatusCode(http.StatusOK), 123 autorest.ByUnmarshallingJSON(&result), 124 autorest.ByClosing()) 125 result.Response = autorest.Response{Response: resp} 126 return 127} 128