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