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// AnalyticsItemsClient is the composite Swagger for Application Insights Management Client
19type AnalyticsItemsClient struct {
20	BaseClient
21}
22
23// NewAnalyticsItemsClient creates an instance of the AnalyticsItemsClient client.
24func NewAnalyticsItemsClient(subscriptionID string) AnalyticsItemsClient {
25	return NewAnalyticsItemsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAnalyticsItemsClientWithBaseURI creates an instance of the AnalyticsItemsClient client using a custom endpoint.
29// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAnalyticsItemsClientWithBaseURI(baseURI string, subscriptionID string) AnalyticsItemsClient {
31	return AnalyticsItemsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Delete deletes a specific Analytics Items defined within an Application Insights component.
35// Parameters:
36// resourceGroupName - the name of the resource group. The name is case insensitive.
37// resourceName - the name of the Application Insights component resource.
38// scopePath - enum indicating if this item definition is owned by a specific user or is shared between all
39// users with access to the Application Insights component.
40// ID - the Id of a specific item defined in the Application Insights component
41// name - the name of a specific item defined in the Application Insights component
42func (client AnalyticsItemsClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, ID string, name string) (result autorest.Response, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/AnalyticsItemsClient.Delete")
45		defer func() {
46			sc := -1
47			if result.Response != nil {
48				sc = result.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: client.SubscriptionID,
55			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
56		{TargetValue: resourceGroupName,
57			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
58				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
59				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
60		return result, validation.NewError("insights.AnalyticsItemsClient", "Delete", err.Error())
61	}
62
63	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, scopePath, ID, name)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Delete", nil, "Failure preparing request")
66		return
67	}
68
69	resp, err := client.DeleteSender(req)
70	if err != nil {
71		result.Response = resp
72		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Delete", resp, "Failure sending request")
73		return
74	}
75
76	result, err = client.DeleteResponder(resp)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Delete", resp, "Failure responding to request")
79		return
80	}
81
82	return
83}
84
85// DeletePreparer prepares the Delete request.
86func (client AnalyticsItemsClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, ID string, name string) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"resourceGroupName": autorest.Encode("path", resourceGroupName),
89		"resourceName":      autorest.Encode("path", resourceName),
90		"scopePath":         autorest.Encode("path", scopePath),
91		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
92	}
93
94	const APIVersion = "2015-05-01"
95	queryParameters := map[string]interface{}{
96		"api-version": APIVersion,
97	}
98	if len(ID) > 0 {
99		queryParameters["id"] = autorest.Encode("query", ID)
100	}
101	if len(name) > 0 {
102		queryParameters["name"] = autorest.Encode("query", name)
103	}
104
105	preparer := autorest.CreatePreparer(
106		autorest.AsDelete(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}/item", pathParameters),
109		autorest.WithQueryParameters(queryParameters))
110	return preparer.Prepare((&http.Request{}).WithContext(ctx))
111}
112
113// DeleteSender sends the Delete request. The method will close the
114// http.Response Body if it receives an error.
115func (client AnalyticsItemsClient) DeleteSender(req *http.Request) (*http.Response, error) {
116	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
117}
118
119// DeleteResponder handles the response to the Delete request. The method always
120// closes the http.Response Body.
121func (client AnalyticsItemsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
122	err = autorest.Respond(
123		resp,
124		azure.WithErrorUnlessStatusCode(http.StatusOK),
125		autorest.ByClosing())
126	result.Response = resp
127	return
128}
129
130// Get gets a specific Analytics Items defined within an Application Insights component.
131// Parameters:
132// resourceGroupName - the name of the resource group. The name is case insensitive.
133// resourceName - the name of the Application Insights component resource.
134// scopePath - enum indicating if this item definition is owned by a specific user or is shared between all
135// users with access to the Application Insights component.
136// ID - the Id of a specific item defined in the Application Insights component
137// name - the name of a specific item defined in the Application Insights component
138func (client AnalyticsItemsClient) Get(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, ID string, name string) (result ApplicationInsightsComponentAnalyticsItem, err error) {
139	if tracing.IsEnabled() {
140		ctx = tracing.StartSpan(ctx, fqdn+"/AnalyticsItemsClient.Get")
141		defer func() {
142			sc := -1
143			if result.Response.Response != nil {
144				sc = result.Response.Response.StatusCode
145			}
146			tracing.EndSpan(ctx, sc, err)
147		}()
148	}
149	if err := validation.Validate([]validation.Validation{
150		{TargetValue: client.SubscriptionID,
151			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
152		{TargetValue: resourceGroupName,
153			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
154				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
155				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
156		return result, validation.NewError("insights.AnalyticsItemsClient", "Get", err.Error())
157	}
158
159	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, scopePath, ID, name)
160	if err != nil {
161		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Get", nil, "Failure preparing request")
162		return
163	}
164
165	resp, err := client.GetSender(req)
166	if err != nil {
167		result.Response = autorest.Response{Response: resp}
168		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Get", resp, "Failure sending request")
169		return
170	}
171
172	result, err = client.GetResponder(resp)
173	if err != nil {
174		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Get", resp, "Failure responding to request")
175		return
176	}
177
178	return
179}
180
181// GetPreparer prepares the Get request.
182func (client AnalyticsItemsClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, ID string, name string) (*http.Request, error) {
183	pathParameters := map[string]interface{}{
184		"resourceGroupName": autorest.Encode("path", resourceGroupName),
185		"resourceName":      autorest.Encode("path", resourceName),
186		"scopePath":         autorest.Encode("path", scopePath),
187		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
188	}
189
190	const APIVersion = "2015-05-01"
191	queryParameters := map[string]interface{}{
192		"api-version": APIVersion,
193	}
194	if len(ID) > 0 {
195		queryParameters["id"] = autorest.Encode("query", ID)
196	}
197	if len(name) > 0 {
198		queryParameters["name"] = autorest.Encode("query", name)
199	}
200
201	preparer := autorest.CreatePreparer(
202		autorest.AsGet(),
203		autorest.WithBaseURL(client.BaseURI),
204		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}/item", pathParameters),
205		autorest.WithQueryParameters(queryParameters))
206	return preparer.Prepare((&http.Request{}).WithContext(ctx))
207}
208
209// GetSender sends the Get request. The method will close the
210// http.Response Body if it receives an error.
211func (client AnalyticsItemsClient) GetSender(req *http.Request) (*http.Response, error) {
212	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
213}
214
215// GetResponder handles the response to the Get request. The method always
216// closes the http.Response Body.
217func (client AnalyticsItemsClient) GetResponder(resp *http.Response) (result ApplicationInsightsComponentAnalyticsItem, err error) {
218	err = autorest.Respond(
219		resp,
220		azure.WithErrorUnlessStatusCode(http.StatusOK),
221		autorest.ByUnmarshallingJSON(&result),
222		autorest.ByClosing())
223	result.Response = autorest.Response{Response: resp}
224	return
225}
226
227// List gets a list of Analytics Items defined within an Application Insights component.
228// Parameters:
229// resourceGroupName - the name of the resource group. The name is case insensitive.
230// resourceName - the name of the Application Insights component resource.
231// scopePath - enum indicating if this item definition is owned by a specific user or is shared between all
232// users with access to the Application Insights component.
233// scope - enum indicating if this item definition is owned by a specific user or is shared between all users
234// with access to the Application Insights component.
235// typeParameter - enum indicating the type of the Analytics item.
236// includeContent - flag indicating whether or not to return the content of each applicable item. If false,
237// only return the item information.
238func (client AnalyticsItemsClient) List(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, scope ItemScope, typeParameter ItemTypeParameter, includeContent *bool) (result ListApplicationInsightsComponentAnalyticsItem, err error) {
239	if tracing.IsEnabled() {
240		ctx = tracing.StartSpan(ctx, fqdn+"/AnalyticsItemsClient.List")
241		defer func() {
242			sc := -1
243			if result.Response.Response != nil {
244				sc = result.Response.Response.StatusCode
245			}
246			tracing.EndSpan(ctx, sc, err)
247		}()
248	}
249	if err := validation.Validate([]validation.Validation{
250		{TargetValue: client.SubscriptionID,
251			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
252		{TargetValue: resourceGroupName,
253			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
254				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
255				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
256		return result, validation.NewError("insights.AnalyticsItemsClient", "List", err.Error())
257	}
258
259	req, err := client.ListPreparer(ctx, resourceGroupName, resourceName, scopePath, scope, typeParameter, includeContent)
260	if err != nil {
261		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "List", nil, "Failure preparing request")
262		return
263	}
264
265	resp, err := client.ListSender(req)
266	if err != nil {
267		result.Response = autorest.Response{Response: resp}
268		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "List", resp, "Failure sending request")
269		return
270	}
271
272	result, err = client.ListResponder(resp)
273	if err != nil {
274		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "List", resp, "Failure responding to request")
275		return
276	}
277
278	return
279}
280
281// ListPreparer prepares the List request.
282func (client AnalyticsItemsClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, scope ItemScope, typeParameter ItemTypeParameter, includeContent *bool) (*http.Request, error) {
283	pathParameters := map[string]interface{}{
284		"resourceGroupName": autorest.Encode("path", resourceGroupName),
285		"resourceName":      autorest.Encode("path", resourceName),
286		"scopePath":         autorest.Encode("path", scopePath),
287		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
288	}
289
290	const APIVersion = "2015-05-01"
291	queryParameters := map[string]interface{}{
292		"api-version": APIVersion,
293	}
294	if len(string(scope)) > 0 {
295		queryParameters["scope"] = autorest.Encode("query", scope)
296	} else {
297		queryParameters["scope"] = autorest.Encode("query", "shared")
298	}
299	if len(string(typeParameter)) > 0 {
300		queryParameters["type"] = autorest.Encode("query", typeParameter)
301	} else {
302		queryParameters["type"] = autorest.Encode("query", "none")
303	}
304	if includeContent != nil {
305		queryParameters["includeContent"] = autorest.Encode("query", *includeContent)
306	}
307
308	preparer := autorest.CreatePreparer(
309		autorest.AsGet(),
310		autorest.WithBaseURL(client.BaseURI),
311		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}", pathParameters),
312		autorest.WithQueryParameters(queryParameters))
313	return preparer.Prepare((&http.Request{}).WithContext(ctx))
314}
315
316// ListSender sends the List request. The method will close the
317// http.Response Body if it receives an error.
318func (client AnalyticsItemsClient) ListSender(req *http.Request) (*http.Response, error) {
319	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
320}
321
322// ListResponder handles the response to the List request. The method always
323// closes the http.Response Body.
324func (client AnalyticsItemsClient) ListResponder(resp *http.Response) (result ListApplicationInsightsComponentAnalyticsItem, err error) {
325	err = autorest.Respond(
326		resp,
327		azure.WithErrorUnlessStatusCode(http.StatusOK),
328		autorest.ByUnmarshallingJSON(&result.Value),
329		autorest.ByClosing())
330	result.Response = autorest.Response{Response: resp}
331	return
332}
333
334// Put adds or Updates a specific Analytics Item within an Application Insights component.
335// Parameters:
336// resourceGroupName - the name of the resource group. The name is case insensitive.
337// resourceName - the name of the Application Insights component resource.
338// scopePath - enum indicating if this item definition is owned by a specific user or is shared between all
339// users with access to the Application Insights component.
340// itemProperties - properties that need to be specified to create a new item and add it to an Application
341// Insights component.
342// overrideItem - flag indicating whether or not to force save an item. This allows overriding an item if it
343// already exists.
344func (client AnalyticsItemsClient) Put(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, itemProperties ApplicationInsightsComponentAnalyticsItem, overrideItem *bool) (result ApplicationInsightsComponentAnalyticsItem, err error) {
345	if tracing.IsEnabled() {
346		ctx = tracing.StartSpan(ctx, fqdn+"/AnalyticsItemsClient.Put")
347		defer func() {
348			sc := -1
349			if result.Response.Response != nil {
350				sc = result.Response.Response.StatusCode
351			}
352			tracing.EndSpan(ctx, sc, err)
353		}()
354	}
355	if err := validation.Validate([]validation.Validation{
356		{TargetValue: client.SubscriptionID,
357			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
358		{TargetValue: resourceGroupName,
359			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
360				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
361				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
362		return result, validation.NewError("insights.AnalyticsItemsClient", "Put", err.Error())
363	}
364
365	req, err := client.PutPreparer(ctx, resourceGroupName, resourceName, scopePath, itemProperties, overrideItem)
366	if err != nil {
367		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Put", nil, "Failure preparing request")
368		return
369	}
370
371	resp, err := client.PutSender(req)
372	if err != nil {
373		result.Response = autorest.Response{Response: resp}
374		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Put", resp, "Failure sending request")
375		return
376	}
377
378	result, err = client.PutResponder(resp)
379	if err != nil {
380		err = autorest.NewErrorWithError(err, "insights.AnalyticsItemsClient", "Put", resp, "Failure responding to request")
381		return
382	}
383
384	return
385}
386
387// PutPreparer prepares the Put request.
388func (client AnalyticsItemsClient) PutPreparer(ctx context.Context, resourceGroupName string, resourceName string, scopePath ItemScopePath, itemProperties ApplicationInsightsComponentAnalyticsItem, overrideItem *bool) (*http.Request, error) {
389	pathParameters := map[string]interface{}{
390		"resourceGroupName": autorest.Encode("path", resourceGroupName),
391		"resourceName":      autorest.Encode("path", resourceName),
392		"scopePath":         autorest.Encode("path", scopePath),
393		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
394	}
395
396	const APIVersion = "2015-05-01"
397	queryParameters := map[string]interface{}{
398		"api-version": APIVersion,
399	}
400	if overrideItem != nil {
401		queryParameters["overrideItem"] = autorest.Encode("query", *overrideItem)
402	}
403
404	itemProperties.Version = nil
405	itemProperties.TimeCreated = nil
406	itemProperties.TimeModified = nil
407	preparer := autorest.CreatePreparer(
408		autorest.AsContentType("application/json; charset=utf-8"),
409		autorest.AsPut(),
410		autorest.WithBaseURL(client.BaseURI),
411		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}/item", pathParameters),
412		autorest.WithJSON(itemProperties),
413		autorest.WithQueryParameters(queryParameters))
414	return preparer.Prepare((&http.Request{}).WithContext(ctx))
415}
416
417// PutSender sends the Put request. The method will close the
418// http.Response Body if it receives an error.
419func (client AnalyticsItemsClient) PutSender(req *http.Request) (*http.Response, error) {
420	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
421}
422
423// PutResponder handles the response to the Put request. The method always
424// closes the http.Response Body.
425func (client AnalyticsItemsClient) PutResponder(resp *http.Response) (result ApplicationInsightsComponentAnalyticsItem, err error) {
426	err = autorest.Respond(
427		resp,
428		azure.WithErrorUnlessStatusCode(http.StatusOK),
429		autorest.ByUnmarshallingJSON(&result),
430		autorest.ByClosing())
431	result.Response = autorest.Response{Response: resp}
432	return
433}
434