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 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// SubscriptionsClient is the the Azure Management Groups API enables consolidation of multiple 29// subscriptions/resources into an organizational hierarchy and centrally 30// manage access control, policies, alerting and reporting for those resources. 31type SubscriptionsClient struct { 32 BaseClient 33} 34 35// NewSubscriptionsClient creates an instance of the SubscriptionsClient client. 36func NewSubscriptionsClient() SubscriptionsClient { 37 return NewSubscriptionsClientWithBaseURI(DefaultBaseURI) 38} 39 40// NewSubscriptionsClientWithBaseURI creates an instance of the SubscriptionsClient client. 41func NewSubscriptionsClientWithBaseURI(baseURI string) SubscriptionsClient { 42 return SubscriptionsClient{NewWithBaseURI(baseURI)} 43} 44 45// Create associates existing subscription with the management group. 46// Parameters: 47// groupID - management Group ID. 48// subscriptionID - subscription ID. 49// cacheControl - indicates that the request shouldn't utilize any caches. 50func (client SubscriptionsClient) Create(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (result autorest.Response, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.Create") 53 defer func() { 54 sc := -1 55 if result.Response != nil { 56 sc = result.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 req, err := client.CreatePreparer(ctx, groupID, subscriptionID, cacheControl) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Create", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.CreateSender(req) 68 if err != nil { 69 result.Response = resp 70 err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Create", resp, "Failure sending request") 71 return 72 } 73 74 result, err = client.CreateResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Create", resp, "Failure responding to request") 77 } 78 79 return 80} 81 82// CreatePreparer prepares the Create request. 83func (client SubscriptionsClient) CreatePreparer(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "groupId": autorest.Encode("path", groupID), 86 "subscriptionId": autorest.Encode("path", subscriptionID), 87 } 88 89 const APIVersion = "2017-11-01-preview" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsPut(), 96 autorest.WithBaseURL(client.BaseURI), 97 autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}", pathParameters), 98 autorest.WithQueryParameters(queryParameters)) 99 if len(cacheControl) > 0 { 100 preparer = autorest.DecoratePreparer(preparer, 101 autorest.WithHeader("Cache-Control", autorest.String(cacheControl))) 102 } else { 103 preparer = autorest.DecoratePreparer(preparer, 104 autorest.WithHeader("Cache-Control", autorest.String("no-cache"))) 105 } 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// CreateSender sends the Create request. The method will close the 110// http.Response Body if it receives an error. 111func (client SubscriptionsClient) CreateSender(req *http.Request) (*http.Response, error) { 112 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 113 return autorest.SendWithSender(client, req, sd...) 114} 115 116// CreateResponder handles the response to the Create request. The method always 117// closes the http.Response Body. 118func (client SubscriptionsClient) CreateResponder(resp *http.Response) (result autorest.Response, err error) { 119 err = autorest.Respond( 120 resp, 121 client.ByInspecting(), 122 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 123 autorest.ByClosing()) 124 result.Response = resp 125 return 126} 127 128// Delete de-associates subscription from the management group. 129// Parameters: 130// groupID - management Group ID. 131// subscriptionID - subscription ID. 132// cacheControl - indicates that the request shouldn't utilize any caches. 133func (client SubscriptionsClient) Delete(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (result autorest.Response, err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/SubscriptionsClient.Delete") 136 defer func() { 137 sc := -1 138 if result.Response != nil { 139 sc = result.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 req, err := client.DeletePreparer(ctx, groupID, subscriptionID, cacheControl) 145 if err != nil { 146 err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", nil, "Failure preparing request") 147 return 148 } 149 150 resp, err := client.DeleteSender(req) 151 if err != nil { 152 result.Response = resp 153 err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", resp, "Failure sending request") 154 return 155 } 156 157 result, err = client.DeleteResponder(resp) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "managementgroups.SubscriptionsClient", "Delete", resp, "Failure responding to request") 160 } 161 162 return 163} 164 165// DeletePreparer prepares the Delete request. 166func (client SubscriptionsClient) DeletePreparer(ctx context.Context, groupID string, subscriptionID string, cacheControl string) (*http.Request, error) { 167 pathParameters := map[string]interface{}{ 168 "groupId": autorest.Encode("path", groupID), 169 "subscriptionId": autorest.Encode("path", subscriptionID), 170 } 171 172 const APIVersion = "2017-11-01-preview" 173 queryParameters := map[string]interface{}{ 174 "api-version": APIVersion, 175 } 176 177 preparer := autorest.CreatePreparer( 178 autorest.AsDelete(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 if len(cacheControl) > 0 { 183 preparer = autorest.DecoratePreparer(preparer, 184 autorest.WithHeader("Cache-Control", autorest.String(cacheControl))) 185 } else { 186 preparer = autorest.DecoratePreparer(preparer, 187 autorest.WithHeader("Cache-Control", autorest.String("no-cache"))) 188 } 189 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 190} 191 192// DeleteSender sends the Delete request. The method will close the 193// http.Response Body if it receives an error. 194func (client SubscriptionsClient) DeleteSender(req *http.Request) (*http.Response, error) { 195 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 196 return autorest.SendWithSender(client, req, sd...) 197} 198 199// DeleteResponder handles the response to the Delete request. The method always 200// closes the http.Response Body. 201func (client SubscriptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 202 err = autorest.Respond( 203 resp, 204 client.ByInspecting(), 205 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), 206 autorest.ByClosing()) 207 result.Response = resp 208 return 209} 210