1 package diagnostics
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 SettingsClient struct {
19 BaseClient
20 }
21
22
23 func NewSettingsClient(subscriptionID string) SettingsClient {
24 return NewSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewSettingsClientWithBaseURI(baseURI string, subscriptionID string) SettingsClient {
30 return SettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38 func (client SettingsClient) CreateOrUpdate(ctx context.Context, resourceURI string, parameters SettingsResource, name string) (result SettingsResource, err error) {
39 if tracing.IsEnabled() {
40 ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.CreateOrUpdate")
41 defer func() {
42 sc := -1
43 if result.Response.Response != nil {
44 sc = result.Response.Response.StatusCode
45 }
46 tracing.EndSpan(ctx, sc, err)
47 }()
48 }
49 req, err := client.CreateOrUpdatePreparer(ctx, resourceURI, parameters, name)
50 if err != nil {
51 err = autorest.NewErrorWithError(err, "diagnostics.SettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
52 return
53 }
54
55 resp, err := client.CreateOrUpdateSender(req)
56 if err != nil {
57 result.Response = autorest.Response{Response: resp}
58 err = autorest.NewErrorWithError(err, "diagnostics.SettingsClient", "CreateOrUpdate", resp, "Failure sending request")
59 return
60 }
61
62 result, err = client.CreateOrUpdateResponder(resp)
63 if err != nil {
64 err = autorest.NewErrorWithError(err, "diagnostics.SettingsClient", "CreateOrUpdate", resp, "Failure responding to request")
65 return
66 }
67
68 return
69 }
70
71
72 func (client SettingsClient) CreateOrUpdatePreparer(ctx context.Context, resourceURI string, parameters SettingsResource, name string) (*http.Request, error) {
73 pathParameters := map[string]interface{}{
74 "name": autorest.Encode("path", name),
75 "resourceUri": resourceURI,
76 }
77
78 const APIVersion = "2021-05-01-preview"
79 queryParameters := map[string]interface{}{
80 "api-version": APIVersion,
81 }
82
83 parameters.SystemData = nil
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 SettingsClient) 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 SettingsClient) CreateOrUpdateResponder(resp *http.Response) (result SettingsResource, 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 SettingsClient) Delete(ctx context.Context, resourceURI string, name string) (result autorest.Response, err error) {
117 if tracing.IsEnabled() {
118 ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.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, "diagnostics.SettingsClient", "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, "diagnostics.SettingsClient", "Delete", resp, "Failure sending request")
137 return
138 }
139
140 result, err = client.DeleteResponder(resp)
141 if err != nil {
142 err = autorest.NewErrorWithError(err, "diagnostics.SettingsClient", "Delete", resp, "Failure responding to request")
143 return
144 }
145
146 return
147 }
148
149
150 func (client SettingsClient) 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 = "2021-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 SettingsClient) 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 SettingsClient) 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 SettingsClient) Get(ctx context.Context, resourceURI string, name string) (result SettingsResource, err error) {
191 if tracing.IsEnabled() {
192 ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.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, "diagnostics.SettingsClient", "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, "diagnostics.SettingsClient", "Get", resp, "Failure sending request")
211 return
212 }
213
214 result, err = client.GetResponder(resp)
215 if err != nil {
216 err = autorest.NewErrorWithError(err, "diagnostics.SettingsClient", "Get", resp, "Failure responding to request")
217 return
218 }
219
220 return
221 }
222
223
224 func (client SettingsClient) 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 = "2021-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 SettingsClient) 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 SettingsClient) GetResponder(resp *http.Response) (result SettingsResource, 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 SettingsClient) List(ctx context.Context, resourceURI string) (result SettingsResourceCollection, err error) {
265 if tracing.IsEnabled() {
266 ctx = tracing.StartSpan(ctx, fqdn+"/SettingsClient.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, "diagnostics.SettingsClient", "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, "diagnostics.SettingsClient", "List", resp, "Failure sending request")
285 return
286 }
287
288 result, err = client.ListResponder(resp)
289 if err != nil {
290 err = autorest.NewErrorWithError(err, "diagnostics.SettingsClient", "List", resp, "Failure responding to request")
291 return
292 }
293
294 return
295 }
296
297
298 func (client SettingsClient) ListPreparer(ctx context.Context, resourceURI string) (*http.Request, error) {
299 pathParameters := map[string]interface{}{
300 "resourceUri": resourceURI,
301 }
302
303 const APIVersion = "2021-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 SettingsClient) 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 SettingsClient) ListResponder(resp *http.Response) (result SettingsResourceCollection, 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