1 package managementgroups
2
3
4
5
6
7
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
18
19
20 type SubscriptionsClient struct {
21 BaseClient
22 }
23
24
25 func NewSubscriptionsClient() SubscriptionsClient {
26 return NewSubscriptionsClientWithBaseURI(DefaultBaseURI)
27 }
28
29
30
31 func NewSubscriptionsClientWithBaseURI(baseURI string) SubscriptionsClient {
32 return SubscriptionsClient{NewWithBaseURI(baseURI)}
33 }
34
35
36
37
38
39
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
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
101
102 func (client SubscriptionsClient) CreateSender(req *http.Request) (*http.Response, error) {
103 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
104 }
105
106
107
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
118
119
120
121
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
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
183
184 func (client SubscriptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
185 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
186 }
187
188
189
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