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 AnnotationsClient struct {
20 BaseClient
21 }
22
23
24 func NewAnnotationsClient(subscriptionID string) AnnotationsClient {
25 return NewAnnotationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewAnnotationsClientWithBaseURI(baseURI string, subscriptionID string) AnnotationsClient {
31 return AnnotationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client AnnotationsClient) Create(ctx context.Context, resourceGroupName string, resourceName string, annotationProperties Annotation) (result ListAnnotation, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/AnnotationsClient.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.AnnotationsClient", "Create", err.Error())
58 }
59
60 req, err := client.CreatePreparer(ctx, resourceGroupName, resourceName, annotationProperties)
61 if err != nil {
62 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "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.AnnotationsClient", "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.AnnotationsClient", "Create", resp, "Failure responding to request")
76 return
77 }
78
79 return
80 }
81
82
83 func (client AnnotationsClient) CreatePreparer(ctx context.Context, resourceGroupName string, resourceName string, annotationProperties Annotation) (*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.AsPut(),
98 autorest.WithBaseURL(client.BaseURI),
99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/Annotations", pathParameters),
100 autorest.WithJSON(annotationProperties),
101 autorest.WithQueryParameters(queryParameters))
102 return preparer.Prepare((&http.Request{}).WithContext(ctx))
103 }
104
105
106
107 func (client AnnotationsClient) CreateSender(req *http.Request) (*http.Response, error) {
108 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
109 }
110
111
112
113 func (client AnnotationsClient) CreateResponder(resp *http.Response) (result ListAnnotation, err error) {
114 err = autorest.Respond(
115 resp,
116 azure.WithErrorUnlessStatusCode(http.StatusOK),
117 autorest.ByUnmarshallingJSON(&result.Value),
118 autorest.ByClosing())
119 result.Response = autorest.Response{Response: resp}
120 return
121 }
122
123
124
125
126
127
128 func (client AnnotationsClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, annotationID string) (result autorest.Response, err error) {
129 if tracing.IsEnabled() {
130 ctx = tracing.StartSpan(ctx, fqdn+"/AnnotationsClient.Delete")
131 defer func() {
132 sc := -1
133 if result.Response != nil {
134 sc = result.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.AnnotationsClient", "Delete", err.Error())
146 }
147
148 req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, annotationID)
149 if err != nil {
150 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "Delete", nil, "Failure preparing request")
151 return
152 }
153
154 resp, err := client.DeleteSender(req)
155 if err != nil {
156 result.Response = resp
157 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "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.AnnotationsClient", "Delete", resp, "Failure responding to request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client AnnotationsClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, annotationID string) (*http.Request, error) {
172 pathParameters := map[string]interface{}{
173 "annotationId": autorest.Encode("path", annotationID),
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}/Annotations/{annotationId}", pathParameters),
188 autorest.WithQueryParameters(queryParameters))
189 return preparer.Prepare((&http.Request{}).WithContext(ctx))
190 }
191
192
193
194 func (client AnnotationsClient) DeleteSender(req *http.Request) (*http.Response, error) {
195 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
196 }
197
198
199
200 func (client AnnotationsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
201 err = autorest.Respond(
202 resp,
203 azure.WithErrorUnlessStatusCode(http.StatusOK),
204 autorest.ByClosing())
205 result.Response = resp
206 return
207 }
208
209
210
211
212
213
214 func (client AnnotationsClient) Get(ctx context.Context, resourceGroupName string, resourceName string, annotationID string) (result ListAnnotation, err error) {
215 if tracing.IsEnabled() {
216 ctx = tracing.StartSpan(ctx, fqdn+"/AnnotationsClient.Get")
217 defer func() {
218 sc := -1
219 if result.Response.Response != nil {
220 sc = result.Response.Response.StatusCode
221 }
222 tracing.EndSpan(ctx, sc, err)
223 }()
224 }
225 if err := validation.Validate([]validation.Validation{
226 {TargetValue: resourceGroupName,
227 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
228 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
229 {TargetValue: client.SubscriptionID,
230 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
231 return result, validation.NewError("insights.AnnotationsClient", "Get", err.Error())
232 }
233
234 req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, annotationID)
235 if err != nil {
236 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "Get", nil, "Failure preparing request")
237 return
238 }
239
240 resp, err := client.GetSender(req)
241 if err != nil {
242 result.Response = autorest.Response{Response: resp}
243 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "Get", resp, "Failure sending request")
244 return
245 }
246
247 result, err = client.GetResponder(resp)
248 if err != nil {
249 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "Get", resp, "Failure responding to request")
250 return
251 }
252
253 return
254 }
255
256
257 func (client AnnotationsClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, annotationID string) (*http.Request, error) {
258 pathParameters := map[string]interface{}{
259 "annotationId": autorest.Encode("path", annotationID),
260 "resourceGroupName": autorest.Encode("path", resourceGroupName),
261 "resourceName": autorest.Encode("path", resourceName),
262 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
263 }
264
265 const APIVersion = "2015-05-01"
266 queryParameters := map[string]interface{}{
267 "api-version": APIVersion,
268 }
269
270 preparer := autorest.CreatePreparer(
271 autorest.AsGet(),
272 autorest.WithBaseURL(client.BaseURI),
273 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/Annotations/{annotationId}", pathParameters),
274 autorest.WithQueryParameters(queryParameters))
275 return preparer.Prepare((&http.Request{}).WithContext(ctx))
276 }
277
278
279
280 func (client AnnotationsClient) GetSender(req *http.Request) (*http.Response, error) {
281 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
282 }
283
284
285
286 func (client AnnotationsClient) GetResponder(resp *http.Response) (result ListAnnotation, err error) {
287 err = autorest.Respond(
288 resp,
289 azure.WithErrorUnlessStatusCode(http.StatusOK),
290 autorest.ByUnmarshallingJSON(&result.Value),
291 autorest.ByClosing())
292 result.Response = autorest.Response{Response: resp}
293 return
294 }
295
296
297
298
299
300
301
302 func (client AnnotationsClient) List(ctx context.Context, resourceGroupName string, resourceName string, start string, end string) (result AnnotationsListResult, err error) {
303 if tracing.IsEnabled() {
304 ctx = tracing.StartSpan(ctx, fqdn+"/AnnotationsClient.List")
305 defer func() {
306 sc := -1
307 if result.Response.Response != nil {
308 sc = result.Response.Response.StatusCode
309 }
310 tracing.EndSpan(ctx, sc, err)
311 }()
312 }
313 if err := validation.Validate([]validation.Validation{
314 {TargetValue: resourceGroupName,
315 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
316 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
317 {TargetValue: client.SubscriptionID,
318 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
319 return result, validation.NewError("insights.AnnotationsClient", "List", err.Error())
320 }
321
322 req, err := client.ListPreparer(ctx, resourceGroupName, resourceName, start, end)
323 if err != nil {
324 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "List", nil, "Failure preparing request")
325 return
326 }
327
328 resp, err := client.ListSender(req)
329 if err != nil {
330 result.Response = autorest.Response{Response: resp}
331 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "List", resp, "Failure sending request")
332 return
333 }
334
335 result, err = client.ListResponder(resp)
336 if err != nil {
337 err = autorest.NewErrorWithError(err, "insights.AnnotationsClient", "List", resp, "Failure responding to request")
338 return
339 }
340
341 return
342 }
343
344
345 func (client AnnotationsClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string, start string, end string) (*http.Request, error) {
346 pathParameters := map[string]interface{}{
347 "resourceGroupName": autorest.Encode("path", resourceGroupName),
348 "resourceName": autorest.Encode("path", resourceName),
349 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
350 }
351
352 const APIVersion = "2015-05-01"
353 queryParameters := map[string]interface{}{
354 "api-version": APIVersion,
355 "end": autorest.Encode("query", end),
356 "start": autorest.Encode("query", start),
357 }
358
359 preparer := autorest.CreatePreparer(
360 autorest.AsGet(),
361 autorest.WithBaseURL(client.BaseURI),
362 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/Annotations", pathParameters),
363 autorest.WithQueryParameters(queryParameters))
364 return preparer.Prepare((&http.Request{}).WithContext(ctx))
365 }
366
367
368
369 func (client AnnotationsClient) ListSender(req *http.Request) (*http.Response, error) {
370 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
371 }
372
373
374
375 func (client AnnotationsClient) ListResponder(resp *http.Response) (result AnnotationsListResult, err error) {
376 err = autorest.Respond(
377 resp,
378 azure.WithErrorUnlessStatusCode(http.StatusOK),
379 autorest.ByUnmarshallingJSON(&result),
380 autorest.ByClosing())
381 result.Response = autorest.Response{Response: resp}
382 return
383 }
384
View as plain text