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