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