...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-05-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
    18  // subscriptions/resources into an organizational hierarchy and centrally
    19  // manage access control, policies, alerting and reporting for those 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.
    38  // If a 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.
    48  // With $search=AllowedParents the API will return the entity info of all groups that the requested entity will
    49  // be able to reparent to as determined by the user's permissions.
    50  // With $search=AllowedChildren the API will return the entity info of all entities that can be added as
    51  // children of the requested entity.
    52  // With $search=ParentAndFirstLevelChildren the API will return the parent and  first level of children that
    53  // the user has either direct access to or indirect access via one of their descendants.
    54  // With $search=ParentOnly the API will return only the group if the user has access to at least one of the
    55  // descendants of the group.
    56  // With $search=ChildrenOnly the API will return only the first level of children of the group entity info
    57  // specified in $filter.  The user must have direct access to the children entities or one of it's descendants
    58  // for it to show up in the results.
    59  // filter - the filter parameter allows you to filter on the the name or display name fields. You can check for
    60  // equality on the name field (e.g. name eq '{entityName}')  and you can check for substrings on either the
    61  // name or display name fields(e.g. contains(name, '{substringToSearch}'), contains(displayName,
    62  // '{substringToSearch')). Note that the '{entityName}' and '{substringToSearch}' fields are checked case
    63  // insensitively.
    64  // view - the view parameter allows clients to filter the type of data that is returned by the getEntities
    65  // call.
    66  // groupName - a filter which allows the get entities call to focus on a particular group (i.e. "$filter=name
    67  // eq 'groupName'")
    68  // cacheControl - indicates that the request shouldn't utilize any caches.
    69  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) {
    70  	if tracing.IsEnabled() {
    71  		ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
    72  		defer func() {
    73  			sc := -1
    74  			if result.elr.Response.Response != nil {
    75  				sc = result.elr.Response.Response.StatusCode
    76  			}
    77  			tracing.EndSpan(ctx, sc, err)
    78  		}()
    79  	}
    80  	result.fn = client.listNextResults
    81  	req, err := client.ListPreparer(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
    82  	if err != nil {
    83  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", nil, "Failure preparing request")
    84  		return
    85  	}
    86  
    87  	resp, err := client.ListSender(req)
    88  	if err != nil {
    89  		result.elr.Response = autorest.Response{Response: resp}
    90  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure sending request")
    91  		return
    92  	}
    93  
    94  	result.elr, err = client.ListResponder(resp)
    95  	if err != nil {
    96  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "List", resp, "Failure responding to request")
    97  		return
    98  	}
    99  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   100  		err = result.NextWithContext(ctx)
   101  		return
   102  	}
   103  
   104  	return
   105  }
   106  
   107  // ListPreparer prepares the List request.
   108  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) {
   109  	const APIVersion = "2020-05-01"
   110  	queryParameters := map[string]interface{}{
   111  		"api-version": APIVersion,
   112  	}
   113  	if len(skiptoken) > 0 {
   114  		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
   115  	}
   116  	if skip != nil {
   117  		queryParameters["$skip"] = autorest.Encode("query", *skip)
   118  	}
   119  	if top != nil {
   120  		queryParameters["$top"] = autorest.Encode("query", *top)
   121  	}
   122  	if len(selectParameter) > 0 {
   123  		queryParameters["$select"] = autorest.Encode("query", selectParameter)
   124  	}
   125  	if len(string(search)) > 0 {
   126  		queryParameters["$search"] = autorest.Encode("query", search)
   127  	}
   128  	if len(filter) > 0 {
   129  		queryParameters["$filter"] = autorest.Encode("query", filter)
   130  	}
   131  	if len(string(view)) > 0 {
   132  		queryParameters["$view"] = autorest.Encode("query", view)
   133  	}
   134  	if len(groupName) > 0 {
   135  		queryParameters["groupName"] = autorest.Encode("query", groupName)
   136  	}
   137  
   138  	preparer := autorest.CreatePreparer(
   139  		autorest.AsPost(),
   140  		autorest.WithBaseURL(client.BaseURI),
   141  		autorest.WithPath("/providers/Microsoft.Management/getEntities"),
   142  		autorest.WithQueryParameters(queryParameters))
   143  	if len(cacheControl) > 0 {
   144  		preparer = autorest.DecoratePreparer(preparer,
   145  			autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
   146  	} else {
   147  		preparer = autorest.DecoratePreparer(preparer,
   148  			autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
   149  	}
   150  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   151  }
   152  
   153  // ListSender sends the List request. The method will close the
   154  // http.Response Body if it receives an error.
   155  func (client EntitiesClient) ListSender(req *http.Request) (*http.Response, error) {
   156  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   157  }
   158  
   159  // ListResponder handles the response to the List request. The method always
   160  // closes the http.Response Body.
   161  func (client EntitiesClient) ListResponder(resp *http.Response) (result EntityListResult, err error) {
   162  	err = autorest.Respond(
   163  		resp,
   164  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   165  		autorest.ByUnmarshallingJSON(&result),
   166  		autorest.ByClosing())
   167  	result.Response = autorest.Response{Response: resp}
   168  	return
   169  }
   170  
   171  // listNextResults retrieves the next set of results, if any.
   172  func (client EntitiesClient) listNextResults(ctx context.Context, lastResults EntityListResult) (result EntityListResult, err error) {
   173  	req, err := lastResults.entityListResultPreparer(ctx)
   174  	if err != nil {
   175  		return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", nil, "Failure preparing next results request")
   176  	}
   177  	if req == nil {
   178  		return
   179  	}
   180  	resp, err := client.ListSender(req)
   181  	if err != nil {
   182  		result.Response = autorest.Response{Response: resp}
   183  		return result, autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure sending next results request")
   184  	}
   185  	result, err = client.ListResponder(resp)
   186  	if err != nil {
   187  		err = autorest.NewErrorWithError(err, "managementgroups.EntitiesClient", "listNextResults", resp, "Failure responding to next results request")
   188  	}
   189  	return
   190  }
   191  
   192  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   193  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) {
   194  	if tracing.IsEnabled() {
   195  		ctx = tracing.StartSpan(ctx, fqdn+"/EntitiesClient.List")
   196  		defer func() {
   197  			sc := -1
   198  			if result.Response().Response.Response != nil {
   199  				sc = result.page.Response().Response.Response.StatusCode
   200  			}
   201  			tracing.EndSpan(ctx, sc, err)
   202  		}()
   203  	}
   204  	result.page, err = client.List(ctx, skiptoken, skip, top, selectParameter, search, filter, view, groupName, cacheControl)
   205  	return
   206  }
   207  

View as plain text