1 package insights
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/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type APIKeysClient struct {
20 BaseClient
21 }
22
23
24 func NewAPIKeysClient(subscriptionID string) APIKeysClient {
25 return NewAPIKeysClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewAPIKeysClientWithBaseURI(baseURI string, subscriptionID string) APIKeysClient {
31 return APIKeysClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client APIKeysClient) Create(ctx context.Context, resourceGroupName string, resourceName string, APIKeyProperties APIKeyRequest) (result ApplicationInsightsComponentAPIKey, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/APIKeysClient.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 if err := validation.Validate([]validation.Validation{
52 {TargetValue: resourceGroupName,
53 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
54 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
55 {TargetValue: client.SubscriptionID,
56 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
57 return result, validation.NewError("insights.APIKeysClient", "Create", err.Error())
58 }
59
60 req, err := client.CreatePreparer(ctx, resourceGroupName, resourceName, APIKeyProperties)
61 if err != nil {
62 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Create", nil, "Failure preparing request")
63 return
64 }
65
66 resp, err := client.CreateSender(req)
67 if err != nil {
68 result.Response = autorest.Response{Response: resp}
69 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Create", resp, "Failure sending request")
70 return
71 }
72
73 result, err = client.CreateResponder(resp)
74 if err != nil {
75 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Create", resp, "Failure responding to request")
76 return
77 }
78
79 return
80 }
81
82
83 func (client APIKeysClient) CreatePreparer(ctx context.Context, resourceGroupName string, resourceName string, APIKeyProperties APIKeyRequest) (*http.Request, error) {
84 pathParameters := map[string]interface{}{
85 "resourceGroupName": autorest.Encode("path", resourceGroupName),
86 "resourceName": autorest.Encode("path", resourceName),
87 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
88 }
89
90 const APIVersion = "2015-05-01"
91 queryParameters := map[string]interface{}{
92 "api-version": APIVersion,
93 }
94
95 preparer := autorest.CreatePreparer(
96 autorest.AsContentType("application/json; charset=utf-8"),
97 autorest.AsPost(),
98 autorest.WithBaseURL(client.BaseURI),
99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ApiKeys", pathParameters),
100 autorest.WithJSON(APIKeyProperties),
101 autorest.WithQueryParameters(queryParameters))
102 return preparer.Prepare((&http.Request{}).WithContext(ctx))
103 }
104
105
106
107 func (client APIKeysClient) CreateSender(req *http.Request) (*http.Response, error) {
108 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109 }
110
111
112
113 func (client APIKeysClient) CreateResponder(resp *http.Response) (result ApplicationInsightsComponentAPIKey, err error) {
114 err = autorest.Respond(
115 resp,
116 azure.WithErrorUnlessStatusCode(http.StatusOK),
117 autorest.ByUnmarshallingJSON(&result),
118 autorest.ByClosing())
119 result.Response = autorest.Response{Response: resp}
120 return
121 }
122
123
124
125
126
127
128 func (client APIKeysClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, keyID string) (result ApplicationInsightsComponentAPIKey, err error) {
129 if tracing.IsEnabled() {
130 ctx = tracing.StartSpan(ctx, fqdn+"/APIKeysClient.Delete")
131 defer func() {
132 sc := -1
133 if result.Response.Response != nil {
134 sc = result.Response.Response.StatusCode
135 }
136 tracing.EndSpan(ctx, sc, err)
137 }()
138 }
139 if err := validation.Validate([]validation.Validation{
140 {TargetValue: resourceGroupName,
141 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
142 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
143 {TargetValue: client.SubscriptionID,
144 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
145 return result, validation.NewError("insights.APIKeysClient", "Delete", err.Error())
146 }
147
148 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, keyID)
149 if err != nil {
150 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Delete", nil, "Failure preparing request")
151 return
152 }
153
154 resp, err := client.DeleteSender(req)
155 if err != nil {
156 result.Response = autorest.Response{Response: resp}
157 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Delete", resp, "Failure sending request")
158 return
159 }
160
161 result, err = client.DeleteResponder(resp)
162 if err != nil {
163 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Delete", resp, "Failure responding to request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client APIKeysClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, keyID string) (*http.Request, error) {
172 pathParameters := map[string]interface{}{
173 "keyId": autorest.Encode("path", keyID),
174 "resourceGroupName": autorest.Encode("path", resourceGroupName),
175 "resourceName": autorest.Encode("path", resourceName),
176 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
177 }
178
179 const APIVersion = "2015-05-01"
180 queryParameters := map[string]interface{}{
181 "api-version": APIVersion,
182 }
183
184 preparer := autorest.CreatePreparer(
185 autorest.AsDelete(),
186 autorest.WithBaseURL(client.BaseURI),
187 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/APIKeys/{keyId}", pathParameters),
188 autorest.WithQueryParameters(queryParameters))
189 return preparer.Prepare((&http.Request{}).WithContext(ctx))
190 }
191
192
193
194 func (client APIKeysClient) DeleteSender(req *http.Request) (*http.Response, error) {
195 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
196 }
197
198
199
200 func (client APIKeysClient) DeleteResponder(resp *http.Response) (result ApplicationInsightsComponentAPIKey, err error) {
201 err = autorest.Respond(
202 resp,
203 azure.WithErrorUnlessStatusCode(http.StatusOK),
204 autorest.ByUnmarshallingJSON(&result),
205 autorest.ByClosing())
206 result.Response = autorest.Response{Response: resp}
207 return
208 }
209
210
211
212
213
214
215 func (client APIKeysClient) Get(ctx context.Context, resourceGroupName string, resourceName string, keyID string) (result ApplicationInsightsComponentAPIKey, err error) {
216 if tracing.IsEnabled() {
217 ctx = tracing.StartSpan(ctx, fqdn+"/APIKeysClient.Get")
218 defer func() {
219 sc := -1
220 if result.Response.Response != nil {
221 sc = result.Response.Response.StatusCode
222 }
223 tracing.EndSpan(ctx, sc, err)
224 }()
225 }
226 if err := validation.Validate([]validation.Validation{
227 {TargetValue: resourceGroupName,
228 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
229 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
230 {TargetValue: client.SubscriptionID,
231 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
232 return result, validation.NewError("insights.APIKeysClient", "Get", err.Error())
233 }
234
235 req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, keyID)
236 if err != nil {
237 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Get", nil, "Failure preparing request")
238 return
239 }
240
241 resp, err := client.GetSender(req)
242 if err != nil {
243 result.Response = autorest.Response{Response: resp}
244 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Get", resp, "Failure sending request")
245 return
246 }
247
248 result, err = client.GetResponder(resp)
249 if err != nil {
250 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "Get", resp, "Failure responding to request")
251 return
252 }
253
254 return
255 }
256
257
258 func (client APIKeysClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, keyID string) (*http.Request, error) {
259 pathParameters := map[string]interface{}{
260 "keyId": autorest.Encode("path", keyID),
261 "resourceGroupName": autorest.Encode("path", resourceGroupName),
262 "resourceName": autorest.Encode("path", resourceName),
263 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
264 }
265
266 const APIVersion = "2015-05-01"
267 queryParameters := map[string]interface{}{
268 "api-version": APIVersion,
269 }
270
271 preparer := autorest.CreatePreparer(
272 autorest.AsGet(),
273 autorest.WithBaseURL(client.BaseURI),
274 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/APIKeys/{keyId}", pathParameters),
275 autorest.WithQueryParameters(queryParameters))
276 return preparer.Prepare((&http.Request{}).WithContext(ctx))
277 }
278
279
280
281 func (client APIKeysClient) GetSender(req *http.Request) (*http.Response, error) {
282 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
283 }
284
285
286
287 func (client APIKeysClient) GetResponder(resp *http.Response) (result ApplicationInsightsComponentAPIKey, err error) {
288 err = autorest.Respond(
289 resp,
290 azure.WithErrorUnlessStatusCode(http.StatusOK),
291 autorest.ByUnmarshallingJSON(&result),
292 autorest.ByClosing())
293 result.Response = autorest.Response{Response: resp}
294 return
295 }
296
297
298
299
300
301 func (client APIKeysClient) List(ctx context.Context, resourceGroupName string, resourceName string) (result ApplicationInsightsComponentAPIKeyListResult, err error) {
302 if tracing.IsEnabled() {
303 ctx = tracing.StartSpan(ctx, fqdn+"/APIKeysClient.List")
304 defer func() {
305 sc := -1
306 if result.Response.Response != nil {
307 sc = result.Response.Response.StatusCode
308 }
309 tracing.EndSpan(ctx, sc, err)
310 }()
311 }
312 if err := validation.Validate([]validation.Validation{
313 {TargetValue: resourceGroupName,
314 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
315 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
316 {TargetValue: client.SubscriptionID,
317 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
318 return result, validation.NewError("insights.APIKeysClient", "List", err.Error())
319 }
320
321 req, err := client.ListPreparer(ctx, resourceGroupName, resourceName)
322 if err != nil {
323 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "List", nil, "Failure preparing request")
324 return
325 }
326
327 resp, err := client.ListSender(req)
328 if err != nil {
329 result.Response = autorest.Response{Response: resp}
330 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "List", resp, "Failure sending request")
331 return
332 }
333
334 result, err = client.ListResponder(resp)
335 if err != nil {
336 err = autorest.NewErrorWithError(err, "insights.APIKeysClient", "List", resp, "Failure responding to request")
337 return
338 }
339
340 return
341 }
342
343
344 func (client APIKeysClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
345 pathParameters := map[string]interface{}{
346 "resourceGroupName": autorest.Encode("path", resourceGroupName),
347 "resourceName": autorest.Encode("path", resourceName),
348 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
349 }
350
351 const APIVersion = "2015-05-01"
352 queryParameters := map[string]interface{}{
353 "api-version": APIVersion,
354 }
355
356 preparer := autorest.CreatePreparer(
357 autorest.AsGet(),
358 autorest.WithBaseURL(client.BaseURI),
359 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/ApiKeys", pathParameters),
360 autorest.WithQueryParameters(queryParameters))
361 return preparer.Prepare((&http.Request{}).WithContext(ctx))
362 }
363
364
365
366 func (client APIKeysClient) ListSender(req *http.Request) (*http.Response, error) {
367 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
368 }
369
370
371
372 func (client APIKeysClient) ListResponder(resp *http.Response) (result ApplicationInsightsComponentAPIKeyListResult, err error) {
373 err = autorest.Respond(
374 resp,
375 azure.WithErrorUnlessStatusCode(http.StatusOK),
376 autorest.ByUnmarshallingJSON(&result),
377 autorest.ByClosing())
378 result.Response = autorest.Response{Response: resp}
379 return
380 }
381
View as plain text