...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-05-01/managementgroups/subscriptions.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  // SubscriptionsClient 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 SubscriptionsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewSubscriptionsClient creates an instance of the SubscriptionsClient client.
    25  func NewSubscriptionsClient() SubscriptionsClient {
    26  	return NewSubscriptionsClientWithBaseURI(DefaultBaseURI)
    27  }
    28  
    29  // NewSubscriptionsClientWithBaseURI creates an instance of the SubscriptionsClient client using a custom endpoint.
    30  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewSubscriptionsClientWithBaseURI(baseURI string) SubscriptionsClient {
    32  	return SubscriptionsClient{NewWithBaseURI(baseURI)}
    33  }
    34  
    35  // Create associates existing subscription with the management group.
    36  // Parameters:
    37  // groupID - management Group ID.
    38  // subscriptionID - subscription ID.
    39  // cacheControl - indicates that the request shouldn't utilize any caches.
    40  func (client SubscriptionsClient) Create(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (result SubscriptionUnderManagementGroup, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.Create")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	req, err := client.CreatePreparer(ctx, groupID, subscriptionID, cacheControl)
    52  	if err != nil {
    53  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Create", nil, "Failure preparing request")
    54  		return
    55  	}
    56  
    57  	resp, err := client.CreateSender(req)
    58  	if err != nil {
    59  		result.Response = autorest.Response{Response: resp}
    60  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Create", resp, "Failure sending request")
    61  		return
    62  	}
    63  
    64  	result, err = client.CreateResponder(resp)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Create", resp, "Failure responding to request")
    67  		return
    68  	}
    69  
    70  	return
    71  }
    72  
    73  // CreatePreparer prepares the Create request.
    74  func (client SubscriptionsClient) CreatePreparer(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (*http.Request, error) {
    75  	pathParameters := map[string]interface{}{
    76  		"groupId":        autorest.Encode("path", groupID),
    77  		"subscriptionId": autorest.Encode("path", subscriptionID),
    78  	}
    79  
    80  	const APIVersion = "2020-05-01"
    81  	queryParameters := map[string]interface{}{
    82  		"api-version": APIVersion,
    83  	}
    84  
    85  	preparer := autorest.CreatePreparer(
    86  		autorest.AsPut(),
    87  		autorest.WithBaseURL(client.BaseURI),
    88  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}", pathParameters),
    89  		autorest.WithQueryParameters(queryParameters))
    90  	if len(cacheControl) > 0 {
    91  		preparer = autorest.DecoratePreparer(preparer,
    92  			autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
    93  	} else {
    94  		preparer = autorest.DecoratePreparer(preparer,
    95  			autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
    96  	}
    97  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    98  }
    99  
   100  // CreateSender sends the Create request. The method will close the
   101  // http.Response Body if it receives an error.
   102  func (client SubscriptionsClient) CreateSender(req *http.Request) (*http.Response, error) {
   103  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   104  }
   105  
   106  // CreateResponder handles the response to the Create request. The method always
   107  // closes the http.Response Body.
   108  func (client SubscriptionsClient) CreateResponder(resp *http.Response) (result SubscriptionUnderManagementGroup, err error) {
   109  	err = autorest.Respond(
   110  		resp,
   111  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   112  		autorest.ByUnmarshallingJSON(&result),
   113  		autorest.ByClosing())
   114  	result.Response = autorest.Response{Response: resp}
   115  	return
   116  }
   117  
   118  // Delete de-associates subscription from the management group.
   119  // Parameters:
   120  // groupID - management Group ID.
   121  // subscriptionID - subscription ID.
   122  // cacheControl - indicates that the request shouldn't utilize any caches.
   123  func (client SubscriptionsClient) Delete(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (result autorest.Response, err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.Delete")
   126  		defer func() {
   127  			sc := -1
   128  			if result.Response != nil {
   129  				sc = result.Response.StatusCode
   130  			}
   131  			tracing.EndSpan(ctx, sc, err)
   132  		}()
   133  	}
   134  	req, err := client.DeletePreparer(ctx, groupID, subscriptionID, cacheControl)
   135  	if err != nil {
   136  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", nil, "Failure preparing request")
   137  		return
   138  	}
   139  
   140  	resp, err := client.DeleteSender(req)
   141  	if err != nil {
   142  		result.Response = resp
   143  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", resp, "Failure sending request")
   144  		return
   145  	}
   146  
   147  	result, err = client.DeleteResponder(resp)
   148  	if err != nil {
   149  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", resp, "Failure responding to request")
   150  		return
   151  	}
   152  
   153  	return
   154  }
   155  
   156  // DeletePreparer prepares the Delete request.
   157  func (client SubscriptionsClient) DeletePreparer(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (*http.Request, error) {
   158  	pathParameters := map[string]interface{}{
   159  		"groupId":        autorest.Encode("path", groupID),
   160  		"subscriptionId": autorest.Encode("path", subscriptionID),
   161  	}
   162  
   163  	const APIVersion = "2020-05-01"
   164  	queryParameters := map[string]interface{}{
   165  		"api-version": APIVersion,
   166  	}
   167  
   168  	preparer := autorest.CreatePreparer(
   169  		autorest.AsDelete(),
   170  		autorest.WithBaseURL(client.BaseURI),
   171  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}", pathParameters),
   172  		autorest.WithQueryParameters(queryParameters))
   173  	if len(cacheControl) > 0 {
   174  		preparer = autorest.DecoratePreparer(preparer,
   175  			autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
   176  	} else {
   177  		preparer = autorest.DecoratePreparer(preparer,
   178  			autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
   179  	}
   180  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   181  }
   182  
   183  // DeleteSender sends the Delete request. The method will close the
   184  // http.Response Body if it receives an error.
   185  func (client SubscriptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   186  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   187  }
   188  
   189  // DeleteResponder handles the response to the Delete request. The method always
   190  // closes the http.Response Body.
   191  func (client SubscriptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   192  	err = autorest.Respond(
   193  		resp,
   194  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   195  		autorest.ByClosing())
   196  	result.Response = resp
   197  	return
   198  }
   199  
   200  // GetSubscription retrieves details about given subscription which is associated with the management group.
   201  // Parameters:
   202  // groupID - management Group ID.
   203  // subscriptionID - subscription ID.
   204  // cacheControl - indicates that the request shouldn't utilize any caches.
   205  func (client SubscriptionsClient) GetSubscription(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (result SubscriptionUnderManagementGroup, err error) {
   206  	if tracing.IsEnabled() {
   207  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.GetSubscription")
   208  		defer func() {
   209  			sc := -1
   210  			if result.Response.Response != nil {
   211  				sc = result.Response.Response.StatusCode
   212  			}
   213  			tracing.EndSpan(ctx, sc, err)
   214  		}()
   215  	}
   216  	req, err := client.GetSubscriptionPreparer(ctx, groupID, subscriptionID, cacheControl)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "GetSubscription", nil, "Failure preparing request")
   219  		return
   220  	}
   221  
   222  	resp, err := client.GetSubscriptionSender(req)
   223  	if err != nil {
   224  		result.Response = autorest.Response{Response: resp}
   225  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "GetSubscription", resp, "Failure sending request")
   226  		return
   227  	}
   228  
   229  	result, err = client.GetSubscriptionResponder(resp)
   230  	if err != nil {
   231  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "GetSubscription", resp, "Failure responding to request")
   232  		return
   233  	}
   234  
   235  	return
   236  }
   237  
   238  // GetSubscriptionPreparer prepares the GetSubscription request.
   239  func (client SubscriptionsClient) GetSubscriptionPreparer(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (*http.Request, error) {
   240  	pathParameters := map[string]interface{}{
   241  		"groupId":        autorest.Encode("path", groupID),
   242  		"subscriptionId": autorest.Encode("path", subscriptionID),
   243  	}
   244  
   245  	const APIVersion = "2020-05-01"
   246  	queryParameters := map[string]interface{}{
   247  		"api-version": APIVersion,
   248  	}
   249  
   250  	preparer := autorest.CreatePreparer(
   251  		autorest.AsGet(),
   252  		autorest.WithBaseURL(client.BaseURI),
   253  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}", pathParameters),
   254  		autorest.WithQueryParameters(queryParameters))
   255  	if len(cacheControl) > 0 {
   256  		preparer = autorest.DecoratePreparer(preparer,
   257  			autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
   258  	} else {
   259  		preparer = autorest.DecoratePreparer(preparer,
   260  			autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
   261  	}
   262  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   263  }
   264  
   265  // GetSubscriptionSender sends the GetSubscription request. The method will close the
   266  // http.Response Body if it receives an error.
   267  func (client SubscriptionsClient) GetSubscriptionSender(req *http.Request) (*http.Response, error) {
   268  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   269  }
   270  
   271  // GetSubscriptionResponder handles the response to the GetSubscription request. The method always
   272  // closes the http.Response Body.
   273  func (client SubscriptionsClient) GetSubscriptionResponder(resp *http.Response) (result SubscriptionUnderManagementGroup, err error) {
   274  	err = autorest.Respond(
   275  		resp,
   276  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   277  		autorest.ByUnmarshallingJSON(&result),
   278  		autorest.ByClosing())
   279  	result.Response = autorest.Response{Response: resp}
   280  	return
   281  }
   282  
   283  // GetSubscriptionsUnderManagementGroup retrieves details about all subscriptions which are associated with the
   284  // management group.
   285  // Parameters:
   286  // groupID - management Group ID.
   287  // skiptoken - page continuation token is only used if a previous operation returned a partial result.
   288  // If a previous response contains a nextLink element, the value of the nextLink element will include a token
   289  // parameter that specifies a starting point to use for subsequent calls.
   290  func (client SubscriptionsClient) GetSubscriptionsUnderManagementGroup(ctx context.Context, groupID string, skiptoken string) (result ListSubscriptionUnderManagementGroupPage, err error) {
   291  	if tracing.IsEnabled() {
   292  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.GetSubscriptionsUnderManagementGroup")
   293  		defer func() {
   294  			sc := -1
   295  			if result.lsumg.Response.Response != nil {
   296  				sc = result.lsumg.Response.Response.StatusCode
   297  			}
   298  			tracing.EndSpan(ctx, sc, err)
   299  		}()
   300  	}
   301  	result.fn = client.getSubscriptionsUnderManagementGroupNextResults
   302  	req, err := client.GetSubscriptionsUnderManagementGroupPreparer(ctx, groupID, skiptoken)
   303  	if err != nil {
   304  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "GetSubscriptionsUnderManagementGroup", nil, "Failure preparing request")
   305  		return
   306  	}
   307  
   308  	resp, err := client.GetSubscriptionsUnderManagementGroupSender(req)
   309  	if err != nil {
   310  		result.lsumg.Response = autorest.Response{Response: resp}
   311  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "GetSubscriptionsUnderManagementGroup", resp, "Failure sending request")
   312  		return
   313  	}
   314  
   315  	result.lsumg, err = client.GetSubscriptionsUnderManagementGroupResponder(resp)
   316  	if err != nil {
   317  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "GetSubscriptionsUnderManagementGroup", resp, "Failure responding to request")
   318  		return
   319  	}
   320  	if result.lsumg.hasNextLink() && result.lsumg.IsEmpty() {
   321  		err = result.NextWithContext(ctx)
   322  		return
   323  	}
   324  
   325  	return
   326  }
   327  
   328  // GetSubscriptionsUnderManagementGroupPreparer prepares the GetSubscriptionsUnderManagementGroup request.
   329  func (client SubscriptionsClient) GetSubscriptionsUnderManagementGroupPreparer(ctx context.Context, groupID string, skiptoken string) (*http.Request, error) {
   330  	pathParameters := map[string]interface{}{
   331  		"groupId": autorest.Encode("path", groupID),
   332  	}
   333  
   334  	const APIVersion = "2020-05-01"
   335  	queryParameters := map[string]interface{}{
   336  		"api-version": APIVersion,
   337  	}
   338  	if len(skiptoken) > 0 {
   339  		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
   340  	}
   341  
   342  	preparer := autorest.CreatePreparer(
   343  		autorest.AsGet(),
   344  		autorest.WithBaseURL(client.BaseURI),
   345  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions", pathParameters),
   346  		autorest.WithQueryParameters(queryParameters))
   347  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   348  }
   349  
   350  // GetSubscriptionsUnderManagementGroupSender sends the GetSubscriptionsUnderManagementGroup request. The method will close the
   351  // http.Response Body if it receives an error.
   352  func (client SubscriptionsClient) GetSubscriptionsUnderManagementGroupSender(req *http.Request) (*http.Response, error) {
   353  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   354  }
   355  
   356  // GetSubscriptionsUnderManagementGroupResponder handles the response to the GetSubscriptionsUnderManagementGroup request. The method always
   357  // closes the http.Response Body.
   358  func (client SubscriptionsClient) GetSubscriptionsUnderManagementGroupResponder(resp *http.Response) (result ListSubscriptionUnderManagementGroup, err error) {
   359  	err = autorest.Respond(
   360  		resp,
   361  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   362  		autorest.ByUnmarshallingJSON(&result),
   363  		autorest.ByClosing())
   364  	result.Response = autorest.Response{Response: resp}
   365  	return
   366  }
   367  
   368  // getSubscriptionsUnderManagementGroupNextResults retrieves the next set of results, if any.
   369  func (client SubscriptionsClient) getSubscriptionsUnderManagementGroupNextResults(ctx context.Context, lastResults ListSubscriptionUnderManagementGroup) (result ListSubscriptionUnderManagementGroup, err error) {
   370  	req, err := lastResults.listSubscriptionUnderManagementGroupPreparer(ctx)
   371  	if err != nil {
   372  		return result, autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "getSubscriptionsUnderManagementGroupNextResults", nil, "Failure preparing next results request")
   373  	}
   374  	if req == nil {
   375  		return
   376  	}
   377  	resp, err := client.GetSubscriptionsUnderManagementGroupSender(req)
   378  	if err != nil {
   379  		result.Response = autorest.Response{Response: resp}
   380  		return result, autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "getSubscriptionsUnderManagementGroupNextResults", resp, "Failure sending next results request")
   381  	}
   382  	result, err = client.GetSubscriptionsUnderManagementGroupResponder(resp)
   383  	if err != nil {
   384  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "getSubscriptionsUnderManagementGroupNextResults", resp, "Failure responding to next results request")
   385  	}
   386  	return
   387  }
   388  
   389  // GetSubscriptionsUnderManagementGroupComplete enumerates all values, automatically crossing page boundaries as required.
   390  func (client SubscriptionsClient) GetSubscriptionsUnderManagementGroupComplete(ctx context.Context, groupID string, skiptoken string) (result ListSubscriptionUnderManagementGroupIterator, err error) {
   391  	if tracing.IsEnabled() {
   392  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.GetSubscriptionsUnderManagementGroup")
   393  		defer func() {
   394  			sc := -1
   395  			if result.Response().Response.Response != nil {
   396  				sc = result.page.Response().Response.Response.StatusCode
   397  			}
   398  			tracing.EndSpan(ctx, sc, err)
   399  		}()
   400  	}
   401  	result.page, err = client.GetSubscriptionsUnderManagementGroup(ctx, groupID, skiptoken)
   402  	return
   403  }
   404  

View as plain text