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// FieldsClient is the automation Client 30type FieldsClient struct { 31 BaseClient 32} 33 34// NewFieldsClient creates an instance of the FieldsClient client. 35func NewFieldsClient(subscriptionID string) FieldsClient { 36 return NewFieldsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewFieldsClientWithBaseURI creates an instance of the FieldsClient 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 NewFieldsClientWithBaseURI(baseURI string, subscriptionID string) FieldsClient { 42 return FieldsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// ListByType retrieve a list of fields of a given type identified by module name. 46// Parameters: 47// resourceGroupName - name of an Azure Resource group. 48// automationAccountName - the name of the automation account. 49// moduleName - the name of module. 50// typeName - the name of type. 51func (client FieldsClient) ListByType(ctx context.Context, resourceGroupName string, automationAccountName string, moduleName string, typeName string) (result TypeFieldListResult, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/FieldsClient.ListByType") 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 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: resourceGroupName, 64 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 65 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("automation.FieldsClient", "ListByType", err.Error()) 68 } 69 70 req, err := client.ListByTypePreparer(ctx, resourceGroupName, automationAccountName, moduleName, typeName) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "automation.FieldsClient", "ListByType", nil, "Failure preparing request") 73 return 74 } 75 76 resp, err := client.ListByTypeSender(req) 77 if err != nil { 78 result.Response = autorest.Response{Response: resp} 79 err = autorest.NewErrorWithError(err, "automation.FieldsClient", "ListByType", resp, "Failure sending request") 80 return 81 } 82 83 result, err = client.ListByTypeResponder(resp) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "automation.FieldsClient", "ListByType", resp, "Failure responding to request") 86 } 87 88 return 89} 90 91// ListByTypePreparer prepares the ListByType request. 92func (client FieldsClient) ListByTypePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, moduleName string, typeName string) (*http.Request, error) { 93 pathParameters := map[string]interface{}{ 94 "automationAccountName": autorest.Encode("path", automationAccountName), 95 "moduleName": autorest.Encode("path", moduleName), 96 "resourceGroupName": autorest.Encode("path", resourceGroupName), 97 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 98 "typeName": autorest.Encode("path", typeName), 99 } 100 101 const APIVersion = "2015-10-31" 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.Automation/automationAccounts/{automationAccountName}/modules/{moduleName}/types/{typeName}/fields", pathParameters), 110 autorest.WithQueryParameters(queryParameters)) 111 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 112} 113 114// ListByTypeSender sends the ListByType request. The method will close the 115// http.Response Body if it receives an error. 116func (client FieldsClient) ListByTypeSender(req *http.Request) (*http.Response, error) { 117 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 118} 119 120// ListByTypeResponder handles the response to the ListByType request. The method always 121// closes the http.Response Body. 122func (client FieldsClient) ListByTypeResponder(resp *http.Response) (result TypeFieldListResult, err error) { 123 err = autorest.Respond( 124 resp, 125 client.ByInspecting(), 126 azure.WithErrorUnlessStatusCode(http.StatusOK), 127 autorest.ByUnmarshallingJSON(&result), 128 autorest.ByClosing()) 129 result.Response = autorest.Response{Response: resp} 130 return 131} 132