...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-11-01/managementgroups/entities.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-11-01/managementgroups

     1  package managementgroups
     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  
     9  import (
    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  // EntitiesClient is the the Azure Management Groups API enables consolidation of multiple subscriptions/resources into
    18  // an organizational hierarchy and centrally manage access control, policies, alerting and reporting for those
    19  // resources.
    20  type EntitiesClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewEntitiesClient creates an instance of the EntitiesClient client.
    25  func NewEntitiesClient() EntitiesClient {
    26  	return NewEntitiesClientWithBaseURI(DefaultBaseURI)
    27  }
    28  
    29  // NewEntitiesClientWithBaseURI creates an instance of the EntitiesClient client using a custom endpoint.  Use this
    30  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewEntitiesClientWithBaseURI(baseURI string) EntitiesClient {
    32  	return EntitiesClient{NewWithBaseURI(baseURI)}
    33  }
    34  
    35  // List list all entities (Management Groups, Subscriptions, etc.) for the authenticated user.
    36  // Parameters:
    37  // skiptoken - page continuation token is only used if a previous operation returned a partial result. If a
    38  // previous response contains a nextLink element, the value of the nextLink element will include a token
    39  // parameter that specifies a starting point to use for subsequent calls.
    40  // skip - number of entities to skip over when retrieving results. Passing this in will override $skipToken.
    41  // top - number of elements to return when retrieving results. Passing this in will override $skipToken.
    42  // selectParameter - this parameter specifies the fields to include in the response. Can include any
    43  // combination of Name,DisplayName,Type,ParentDisplayNameChain,ParentChain, e.g.
    44  // '$select=Name,DisplayName,Type,ParentDisplayNameChain,ParentNameChain'. When specified the $select parameter
    45  // can override select in $skipToken.
    46  // search - the $search parameter is used in conjunction with the $filter parameter to return three different
    47  // outputs depending on the parameter passed in. With $search=AllowedParents the API will return the entity
    48  // info of all groups that the requested entity will be able to reparent to as determined by the user's
    49  // permissions.With $search=AllowedChildren the API will return the entity info of all entities that can be
    50  // added as children of the requested entity.With $search=ParentAndFirstLevelChildren the API will return the
    51  // parent and  first level of children that the user has either direct access to or indirect access via one of
    52  // their descendants.With $search=ParentOnly the API will return only the group if the user has access to at
    53  // least one of the descendants of the group.With $search=ChildrenOnly the API will return only the first level
    54  // of children of the group entity info specified in $filter.  The user must have direct access to the children
    55  // entities or one of it's descendants for it to show up in the results.
    56  // filter - the filter parameter allows you to filter on the the name or display name fields. You can check for
    57  // equality on the name field (e.g. name eq '{entityName}')  and you can check for substrings on either the
    58  // name or display name fields(e.g. contains(name, '{substringToSearch}'), contains(displayName,
    59  // '{substringToSearch')). Note that the '{entityName}' and '{substringToSearch}' fields are checked case
    60  // insensitively.
    61  // view - the view parameter allows clients to filter the type of data that is returned by the getEntities
    62  // call.
    63  // groupName - a filter which allows the get entities call to focus on a particular group (i.e. "$filter=name
    64  // eq 'groupName'")
    65  // cacheControl - indicates that the request shouldn't utilize any caches.
    66  func (client EntitiesClient) List(ctx context.Context, skiptoken string, skip *int32, top *int32, selectParameter string, search string, filter string, view string, groupName string, cacheControl string) (result EntityListResultPage, err error) {
    67  	if tracing.IsEnabled() {
    68  		ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
    69  		defer func() {
    70  			sc := -1
    71  			if result.elr.Response.Response != nil {
    72  				sc = result.elr.Response.Response.StatusCode
    73  			}
    74  			tracing.EndSpan(ctx, sc, err)
    75  		}()
    76  	}
    77  	result.fn = client.listNextResults
    78  	req, err := client.ListPreparer(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
    79  	if err != nil {
    80  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", nil, "Failure preparing request")
    81  		return
    82  	}
    83  
    84  	resp, err := client.ListSender(req)
    85  	if err != nil {
    86  		result.elr.Response = autorest.Response{Response: resp}
    87  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure sending request")
    88  		return
    89  	}
    90  
    91  	result.elr, err = client.ListResponder(resp)
    92  	if err != nil {
    93  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure responding to request")
    94  		return
    95  	}
    96  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
    97  		err = result.NextWithContext(ctx)
    98  		return
    99  	}
   100  
   101  	return
   102  }
   103  
   104  // ListPreparer prepares the List request.
   105  func (client EntitiesClient) ListPreparer(ctx context.Context, skiptoken string, skip *int32, top *int32, selectParameter string, search string, filter string, view string, groupName string, cacheControl string) (*http.Request, error) {
   106  	const APIVersion = "2019-11-01"
   107  	queryParameters := map[string]interface{}{
   108  		"api-version": APIVersion,
   109  	}
   110  	if len(skiptoken) > 0 {
   111  		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
   112  	}
   113  	if skip != nil {
   114  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   115  	}
   116  	if top != nil {
   117  		queryParameters["$top"] = autorest.Encode("query", *top)
   118  	}
   119  	if len(selectParameter) > 0 {
   120  		queryParameters["$select"] = autorest.Encode("query", selectParameter)
   121  	}
   122  	if len(string(search)) > 0 {
   123  		queryParameters["$search"] = autorest.Encode("query", search)
   124  	}
   125  	if len(filter) > 0 {
   126  		queryParameters["$filter"] = autorest.Encode("query", filter)
   127  	}
   128  	if len(string(view)) > 0 {
   129  		queryParameters["$view"] = autorest.Encode("query", view)
   130  	}
   131  	if len(groupName) > 0 {
   132  		queryParameters["groupName"] = autorest.Encode("query", groupName)
   133  	}
   134  
   135  	preparer := autorest.CreatePreparer(
   136  		autorest.AsPost(),
   137  		autorest.WithBaseURL(client.BaseURI),
   138  		autorest.WithPath("/providers/Microsoft.Management/getEntities"),
   139  		autorest.WithQueryParameters(queryParameters))
   140  	if len(cacheControl) > 0 {
   141  		preparer = autorest.DecoratePreparer(preparer,
   142  			autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
   143  	} else {
   144  		preparer = autorest.DecoratePreparer(preparer,
   145  			autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
   146  	}
   147  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   148  }
   149  
   150  // ListSender sends the List request. The method will close the
   151  // http.Response Body if it receives an error.
   152  func (client EntitiesClient) ListSender(req *http.Request) (*http.Response, error) {
   153  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   154  }
   155  
   156  // ListResponder handles the response to the List request. The method always
   157  // closes the http.Response Body.
   158  func (client EntitiesClient) ListResponder(resp *http.Response) (result EntityListResult, err error) {
   159  	err = autorest.Respond(
   160  		resp,
   161  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   162  		autorest.ByUnmarshallingJSON(&result),
   163  		autorest.ByClosing())
   164  	result.Response = autorest.Response{Response: resp}
   165  	return
   166  }
   167  
   168  // listNextResults retrieves the next set of results, if any.
   169  func (client EntitiesClient) listNextResults(ctx context.Context, lastResults EntityListResult) (result EntityListResult, err error) {
   170  	req, err := lastResults.entityListResultPreparer(ctx)
   171  	if err != nil {
   172  		return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", nil, "Failure preparing next results request")
   173  	}
   174  	if req == nil {
   175  		return
   176  	}
   177  	resp, err := client.ListSender(req)
   178  	if err != nil {
   179  		result.Response = autorest.Response{Response: resp}
   180  		return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure sending next results request")
   181  	}
   182  	result, err = client.ListResponder(resp)
   183  	if err != nil {
   184  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure responding to next results request")
   185  	}
   186  	return
   187  }
   188  
   189  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   190  func (client EntitiesClient) ListComplete(ctx context.Context, skiptoken string, skip *int32, top *int32, selectParameter string, search string, filter string, view string, groupName string, cacheControl string) (result EntityListResultIterator, err error) {
   191  	if tracing.IsEnabled() {
   192  		ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
   193  		defer func() {
   194  			sc := -1
   195  			if result.Response().Response.Response != nil {
   196  				sc = result.page.Response().Response.Response.StatusCode
   197  			}
   198  			tracing.EndSpan(ctx, sc, err)
   199  		}()
   200  	}
   201  	result.page, err = client.List(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
   202  	return
   203  }
   204  

View as plain text