...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-02-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 autorest.Response, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.Create")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response != nil {
    46  				sc = result.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 = 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-02-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 autorest.Response, err error) {
   109  	err = autorest.Respond(
   110  		resp,
   111  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   112  		autorest.ByClosing())
   113  	result.Response = resp
   114  	return
   115  }
   116  
   117  // Delete de-associates subscription from the management group.
   118  // Parameters:
   119  // groupID - management Group ID.
   120  // subscriptionID - subscription ID.
   121  // cacheControl - indicates that the request shouldn't utilize any caches.
   122  func (client SubscriptionsClient) Delete(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (result autorest.Response, err error) {
   123  	if tracing.IsEnabled() {
   124  		ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.Delete")
   125  		defer func() {
   126  			sc := -1
   127  			if result.Response != nil {
   128  				sc = result.Response.StatusCode
   129  			}
   130  			tracing.EndSpan(ctx, sc, err)
   131  		}()
   132  	}
   133  	req, err := client.DeletePreparer(ctx, groupID, subscriptionID, cacheControl)
   134  	if err != nil {
   135  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", nil, "Failure preparing request")
   136  		return
   137  	}
   138  
   139  	resp, err := client.DeleteSender(req)
   140  	if err != nil {
   141  		result.Response = resp
   142  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", resp, "Failure sending request")
   143  		return
   144  	}
   145  
   146  	result, err = client.DeleteResponder(resp)
   147  	if err != nil {
   148  		err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", resp, "Failure responding to request")
   149  		return
   150  	}
   151  
   152  	return
   153  }
   154  
   155  // DeletePreparer prepares the Delete request.
   156  func (client SubscriptionsClient) DeletePreparer(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (*http.Request, error) {
   157  	pathParameters := map[string]interface{}{
   158  		"groupId":        autorest.Encode("path", groupID),
   159  		"subscriptionId": autorest.Encode("path", subscriptionID),
   160  	}
   161  
   162  	const APIVersion = "2020-02-01"
   163  	queryParameters := map[string]interface{}{
   164  		"api-version": APIVersion,
   165  	}
   166  
   167  	preparer := autorest.CreatePreparer(
   168  		autorest.AsDelete(),
   169  		autorest.WithBaseURL(client.BaseURI),
   170  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}", pathParameters),
   171  		autorest.WithQueryParameters(queryParameters))
   172  	if len(cacheControl) > 0 {
   173  		preparer = autorest.DecoratePreparer(preparer,
   174  			autorest.WithHeader("Cache-Control", autorest.String(cacheControl)))
   175  	} else {
   176  		preparer = autorest.DecoratePreparer(preparer,
   177  			autorest.WithHeader("Cache-Control", autorest.String("no-cache")))
   178  	}
   179  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   180  }
   181  
   182  // DeleteSender sends the Delete request. The method will close the
   183  // http.Response Body if it receives an error.
   184  func (client SubscriptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   185  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   186  }
   187  
   188  // DeleteResponder handles the response to the Delete request. The method always
   189  // closes the http.Response Body.
   190  func (client SubscriptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   191  	err = autorest.Respond(
   192  		resp,
   193  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   194  		autorest.ByClosing())
   195  	result.Response = resp
   196  	return
   197  }
   198  

View as plain text