1package managementgroups 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 "net/http" 25) 26 27// EntitiesClient is the the Azure Management Groups API enables consolidation of multiple 28// subscriptions/resources into an organizational hierarchy and centrally 29// manage access control, policies, alerting and reporting for those resources. 30type EntitiesClient struct { 31 BaseClient 32} 33 34// NewEntitiesClient creates an instance of the EntitiesClient client. 35func NewEntitiesClient(operationResultID string, skiptoken string) EntitiesClient { 36 return NewEntitiesClientWithBaseURI(DefaultBaseURI, operationResultID, skiptoken) 37} 38 39// NewEntitiesClientWithBaseURI creates an instance of the EntitiesClient client. 40func NewEntitiesClientWithBaseURI(baseURI string, operationResultID string, skiptoken string) EntitiesClient { 41 return EntitiesClient{NewWithBaseURI(baseURI, operationResultID, skiptoken)} 42} 43 44// List list all entities (Management Groups, Subscriptions, etc.) for the authenticated user. 45// Parameters: 46// groupName - a filter which allows the call to be filtered for a specific group. 47// cacheControl - indicates that the request shouldn't utilize any caches. 48func (client EntitiesClient) List(ctx context.Context, groupName string, cacheControl string) (result EntityListResultPage, err error) { 49 result.fn = client.listNextResults 50 req, err := client.ListPreparer(ctx, groupName, cacheControl) 51 if err != nil { 52 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", nil, "Failure preparing request") 53 return 54 } 55 56 resp, err := client.ListSender(req) 57 if err != nil { 58 result.elr.Response = autorest.Response{Response: resp} 59 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure sending request") 60 return 61 } 62 63 result.elr, err = client.ListResponder(resp) 64 if err != nil { 65 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure responding to request") 66 } 67 68 return 69} 70 71// ListPreparer prepares the List request. 72func (client EntitiesClient) ListPreparer(ctx context.Context, groupName string, cacheControl string) (*http.Request, error) { 73 const APIVersion = "2018-01-01-preview" 74 queryParameters := map[string]interface{}{ 75 "api-version": APIVersion, 76 } 77 if len(client.Skiptoken) > 0 { 78 queryParameters["$skiptoken"] = autorest.Encode("query", client.Skiptoken) 79 } 80 if len(groupName) > 0 { 81 queryParameters["groupName"] = autorest.Encode("query", groupName) 82 } 83 84 preparer := autorest.CreatePreparer( 85 autorest.AsPost(), 86 autorest.WithBaseURL(client.BaseURI), 87 autorest.WithPath("/providers/Microsoft.Management/getEntities"), 88 autorest.WithQueryParameters(queryParameters)) 89 if len(cacheControl) > 0 { 90 preparer = autorest.DecoratePreparer(preparer, 91 autorest.WithHeader("Cache-Control", autorest.String(cacheControl))) 92 } else { 93 preparer = autorest.DecoratePreparer(preparer, 94 autorest.WithHeader("Cache-Control", autorest.String("no-cache"))) 95 } 96 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 97} 98 99// ListSender sends the List request. The method will close the 100// http.Response Body if it receives an error. 101func (client EntitiesClient) ListSender(req *http.Request) (*http.Response, error) { 102 return autorest.SendWithSender(client, req, 103 autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 104} 105 106// ListResponder handles the response to the List request. The method always 107// closes the http.Response Body. 108func (client EntitiesClient) ListResponder(resp *http.Response) (result EntityListResult, err error) { 109 err = autorest.Respond( 110 resp, 111 client.ByInspecting(), 112 azure.WithErrorUnlessStatusCode(http.StatusOK), 113 autorest.ByUnmarshallingJSON(&result), 114 autorest.ByClosing()) 115 result.Response = autorest.Response{Response: resp} 116 return 117} 118 119// listNextResults retrieves the next set of results, if any. 120func (client EntitiesClient) listNextResults(lastResults EntityListResult) (result EntityListResult, err error) { 121 req, err := lastResults.entityListResultPreparer() 122 if err != nil { 123 return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", nil, "Failure preparing next results request") 124 } 125 if req == nil { 126 return 127 } 128 resp, err := client.ListSender(req) 129 if err != nil { 130 result.Response = autorest.Response{Response: resp} 131 return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure sending next results request") 132 } 133 result, err = client.ListResponder(resp) 134 if err != nil { 135 err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure responding to next results request") 136 } 137 return 138} 139 140// ListComplete enumerates all values, automatically crossing page boundaries as required. 141func (client EntitiesClient) ListComplete(ctx context.Context, groupName string, cacheControl string) (result EntityListResultIterator, err error) { 142 result.page, err = client.List(ctx, groupName, cacheControl) 143 return 144} 145