1package insights
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
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// LogProfilesClient is the monitor Management Client
19type LogProfilesClient struct {
20	BaseClient
21}
22
23// NewLogProfilesClient creates an instance of the LogProfilesClient client.
24func NewLogProfilesClient(subscriptionID string) LogProfilesClient {
25	return NewLogProfilesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewLogProfilesClientWithBaseURI creates an instance of the LogProfilesClient client using a custom endpoint.  Use
29// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewLogProfilesClientWithBaseURI(baseURI string, subscriptionID string) LogProfilesClient {
31	return LogProfilesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate create or update a log profile in Azure Monitoring REST API.
35// Parameters:
36// logProfileName - the name of the log profile.
37// parameters - parameters supplied to the operation.
38func (client LogProfilesClient) CreateOrUpdate(ctx context.Context, logProfileName string, parameters LogProfileResource) (result LogProfileResource, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.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	if err := validation.Validate([]validation.Validation{
50		{TargetValue: parameters,
51			Constraints: []validation.Constraint{{Target: "parameters.LogProfileProperties", Name: validation.Null, Rule: true,
52				Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.Locations", Name: validation.Null, Rule: true, Chain: nil},
53					{Target: "parameters.LogProfileProperties.Categories", Name: validation.Null, Rule: true, Chain: nil},
54					{Target: "parameters.LogProfileProperties.RetentionPolicy", Name: validation.Null, Rule: true,
55						Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.RetentionPolicy.Enabled", Name: validation.Null, Rule: true, Chain: nil},
56							{Target: "parameters.LogProfileProperties.RetentionPolicy.Days", Name: validation.Null, Rule: true,
57								Chain: []validation.Constraint{{Target: "parameters.LogProfileProperties.RetentionPolicy.Days", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}},
58						}},
59				}}}}}); err != nil {
60		return result, validation.NewError("insights.LogProfilesClient", "CreateOrUpdate", err.Error())
61	}
62
63	req, err := client.CreateOrUpdatePreparer(ctx, logProfileName, parameters)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "CreateOrUpdate", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.CreateOrUpdateSender(req)
70	if err != nil {
71		result.Response = autorest.Response{Response: resp}
72		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "CreateOrUpdate", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.CreateOrUpdateResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "CreateOrUpdate", resp, "Failure responding to request")
79		return
80	}
81
82	return
83}
84
85// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
86func (client LogProfilesClient) CreateOrUpdatePreparer(ctx context.Context, logProfileName string, parameters LogProfileResource) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"logProfileName": autorest.Encode("path", logProfileName),
89		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2016-03-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsContentType("application/json; charset=utf-8"),
99		autorest.AsPut(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters),
102		autorest.WithJSON(parameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
108// http.Response Body if it receives an error.
109func (client LogProfilesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
110	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
111}
112
113// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
114// closes the http.Response Body.
115func (client LogProfilesClient) CreateOrUpdateResponder(resp *http.Response) (result LogProfileResource, err error) {
116	err = autorest.Respond(
117		resp,
118		azure.WithErrorUnlessStatusCode(http.StatusOK),
119		autorest.ByUnmarshallingJSON(&result),
120		autorest.ByClosing())
121	result.Response = autorest.Response{Response: resp}
122	return
123}
124
125// Delete deletes the log profile.
126// Parameters:
127// logProfileName - the name of the log profile.
128func (client LogProfilesClient) Delete(ctx context.Context, logProfileName string) (result autorest.Response, err error) {
129	if tracing.IsEnabled() {
130		ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.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	req, err := client.DeletePreparer(ctx, logProfileName)
140	if err != nil {
141		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Delete", nil, "Failure preparing request")
142		return
143	}
144
145	resp, err := client.DeleteSender(req)
146	if err != nil {
147		result.Response = resp
148		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Delete", resp, "Failure sending request")
149		return
150	}
151
152	result, err = client.DeleteResponder(resp)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Delete", resp, "Failure responding to request")
155		return
156	}
157
158	return
159}
160
161// DeletePreparer prepares the Delete request.
162func (client LogProfilesClient) DeletePreparer(ctx context.Context, logProfileName string) (*http.Request, error) {
163	pathParameters := map[string]interface{}{
164		"logProfileName": autorest.Encode("path", logProfileName),
165		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
166	}
167
168	const APIVersion = "2016-03-01"
169	queryParameters := map[string]interface{}{
170		"api-version": APIVersion,
171	}
172
173	preparer := autorest.CreatePreparer(
174		autorest.AsDelete(),
175		autorest.WithBaseURL(client.BaseURI),
176		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters),
177		autorest.WithQueryParameters(queryParameters))
178	return preparer.Prepare((&http.Request{}).WithContext(ctx))
179}
180
181// DeleteSender sends the Delete request. The method will close the
182// http.Response Body if it receives an error.
183func (client LogProfilesClient) DeleteSender(req *http.Request) (*http.Response, error) {
184	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
185}
186
187// DeleteResponder handles the response to the Delete request. The method always
188// closes the http.Response Body.
189func (client LogProfilesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
190	err = autorest.Respond(
191		resp,
192		azure.WithErrorUnlessStatusCode(http.StatusOK),
193		autorest.ByClosing())
194	result.Response = resp
195	return
196}
197
198// Get gets the log profile.
199// Parameters:
200// logProfileName - the name of the log profile.
201func (client LogProfilesClient) Get(ctx context.Context, logProfileName string) (result LogProfileResource, err error) {
202	if tracing.IsEnabled() {
203		ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.Get")
204		defer func() {
205			sc := -1
206			if result.Response.Response != nil {
207				sc = result.Response.Response.StatusCode
208			}
209			tracing.EndSpan(ctx, sc, err)
210		}()
211	}
212	req, err := client.GetPreparer(ctx, logProfileName)
213	if err != nil {
214		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Get", nil, "Failure preparing request")
215		return
216	}
217
218	resp, err := client.GetSender(req)
219	if err != nil {
220		result.Response = autorest.Response{Response: resp}
221		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Get", resp, "Failure sending request")
222		return
223	}
224
225	result, err = client.GetResponder(resp)
226	if err != nil {
227		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Get", resp, "Failure responding to request")
228		return
229	}
230
231	return
232}
233
234// GetPreparer prepares the Get request.
235func (client LogProfilesClient) GetPreparer(ctx context.Context, logProfileName string) (*http.Request, error) {
236	pathParameters := map[string]interface{}{
237		"logProfileName": autorest.Encode("path", logProfileName),
238		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
239	}
240
241	const APIVersion = "2016-03-01"
242	queryParameters := map[string]interface{}{
243		"api-version": APIVersion,
244	}
245
246	preparer := autorest.CreatePreparer(
247		autorest.AsGet(),
248		autorest.WithBaseURL(client.BaseURI),
249		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters),
250		autorest.WithQueryParameters(queryParameters))
251	return preparer.Prepare((&http.Request{}).WithContext(ctx))
252}
253
254// GetSender sends the Get request. The method will close the
255// http.Response Body if it receives an error.
256func (client LogProfilesClient) GetSender(req *http.Request) (*http.Response, error) {
257	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
258}
259
260// GetResponder handles the response to the Get request. The method always
261// closes the http.Response Body.
262func (client LogProfilesClient) GetResponder(resp *http.Response) (result LogProfileResource, err error) {
263	err = autorest.Respond(
264		resp,
265		azure.WithErrorUnlessStatusCode(http.StatusOK),
266		autorest.ByUnmarshallingJSON(&result),
267		autorest.ByClosing())
268	result.Response = autorest.Response{Response: resp}
269	return
270}
271
272// List list the log profiles.
273func (client LogProfilesClient) List(ctx context.Context) (result LogProfileCollection, err error) {
274	if tracing.IsEnabled() {
275		ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.List")
276		defer func() {
277			sc := -1
278			if result.Response.Response != nil {
279				sc = result.Response.Response.StatusCode
280			}
281			tracing.EndSpan(ctx, sc, err)
282		}()
283	}
284	req, err := client.ListPreparer(ctx)
285	if err != nil {
286		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "List", nil, "Failure preparing request")
287		return
288	}
289
290	resp, err := client.ListSender(req)
291	if err != nil {
292		result.Response = autorest.Response{Response: resp}
293		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "List", resp, "Failure sending request")
294		return
295	}
296
297	result, err = client.ListResponder(resp)
298	if err != nil {
299		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "List", resp, "Failure responding to request")
300		return
301	}
302
303	return
304}
305
306// ListPreparer prepares the List request.
307func (client LogProfilesClient) ListPreparer(ctx context.Context) (*http.Request, error) {
308	pathParameters := map[string]interface{}{
309		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
310	}
311
312	const APIVersion = "2016-03-01"
313	queryParameters := map[string]interface{}{
314		"api-version": APIVersion,
315	}
316
317	preparer := autorest.CreatePreparer(
318		autorest.AsGet(),
319		autorest.WithBaseURL(client.BaseURI),
320		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles", pathParameters),
321		autorest.WithQueryParameters(queryParameters))
322	return preparer.Prepare((&http.Request{}).WithContext(ctx))
323}
324
325// ListSender sends the List request. The method will close the
326// http.Response Body if it receives an error.
327func (client LogProfilesClient) ListSender(req *http.Request) (*http.Response, error) {
328	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
329}
330
331// ListResponder handles the response to the List request. The method always
332// closes the http.Response Body.
333func (client LogProfilesClient) ListResponder(resp *http.Response) (result LogProfileCollection, err error) {
334	err = autorest.Respond(
335		resp,
336		azure.WithErrorUnlessStatusCode(http.StatusOK),
337		autorest.ByUnmarshallingJSON(&result),
338		autorest.ByClosing())
339	result.Response = autorest.Response{Response: resp}
340	return
341}
342
343// Update updates an existing LogProfilesResource. To update other fields use the CreateOrUpdate method.
344// Parameters:
345// logProfileName - the name of the log profile.
346// logProfilesResource - parameters supplied to the operation.
347func (client LogProfilesClient) Update(ctx context.Context, logProfileName string, logProfilesResource LogProfileResourcePatch) (result LogProfileResource, err error) {
348	if tracing.IsEnabled() {
349		ctx = tracing.StartSpan(ctx, fqdn+"/LogProfilesClient.Update")
350		defer func() {
351			sc := -1
352			if result.Response.Response != nil {
353				sc = result.Response.Response.StatusCode
354			}
355			tracing.EndSpan(ctx, sc, err)
356		}()
357	}
358	req, err := client.UpdatePreparer(ctx, logProfileName, logProfilesResource)
359	if err != nil {
360		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Update", nil, "Failure preparing request")
361		return
362	}
363
364	resp, err := client.UpdateSender(req)
365	if err != nil {
366		result.Response = autorest.Response{Response: resp}
367		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Update", resp, "Failure sending request")
368		return
369	}
370
371	result, err = client.UpdateResponder(resp)
372	if err != nil {
373		err = autorest.NewErrorWithError(err, "insights.LogProfilesClient", "Update", resp, "Failure responding to request")
374		return
375	}
376
377	return
378}
379
380// UpdatePreparer prepares the Update request.
381func (client LogProfilesClient) UpdatePreparer(ctx context.Context, logProfileName string, logProfilesResource LogProfileResourcePatch) (*http.Request, error) {
382	pathParameters := map[string]interface{}{
383		"logProfileName": autorest.Encode("path", logProfileName),
384		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
385	}
386
387	const APIVersion = "2016-03-01"
388	queryParameters := map[string]interface{}{
389		"api-version": APIVersion,
390	}
391
392	preparer := autorest.CreatePreparer(
393		autorest.AsContentType("application/json; charset=utf-8"),
394		autorest.AsPatch(),
395		autorest.WithBaseURL(client.BaseURI),
396		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/logprofiles/{logProfileName}", pathParameters),
397		autorest.WithJSON(logProfilesResource),
398		autorest.WithQueryParameters(queryParameters))
399	return preparer.Prepare((&http.Request{}).WithContext(ctx))
400}
401
402// UpdateSender sends the Update request. The method will close the
403// http.Response Body if it receives an error.
404func (client LogProfilesClient) UpdateSender(req *http.Request) (*http.Response, error) {
405	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
406}
407
408// UpdateResponder handles the response to the Update request. The method always
409// closes the http.Response Body.
410func (client LogProfilesClient) UpdateResponder(resp *http.Response) (result LogProfileResource, err error) {
411	err = autorest.Respond(
412		resp,
413		azure.WithErrorUnlessStatusCode(http.StatusOK),
414		autorest.ByUnmarshallingJSON(&result),
415		autorest.ByClosing())
416	result.Response = autorest.Response{Response: resp}
417	return
418}
419