1package servicemap
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// MapsClient is the service Map API Reference
30type MapsClient struct {
31	BaseClient
32}
33
34// NewMapsClient creates an instance of the MapsClient client.
35func NewMapsClient(subscriptionID string) MapsClient {
36	return NewMapsClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewMapsClientWithBaseURI creates an instance of the MapsClient client.
40func NewMapsClientWithBaseURI(baseURI string, subscriptionID string) MapsClient {
41	return MapsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// Generate generates the specified map.
45// Parameters:
46// resourceGroupName - resource group name within the specified subscriptionId.
47// workspaceName - OMS workspace containing the resources of interest.
48// request - request options.
49func (client MapsClient) Generate(ctx context.Context, resourceGroupName string, workspaceName string, request BasicMapRequest) (result MapResponse, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/MapsClient.Generate")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: resourceGroupName,
62			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
63				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
64				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
65		{TargetValue: workspaceName,
66			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
67				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
68				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}}}); err != nil {
69		return result, validation.NewError("servicemap.MapsClient", "Generate", err.Error())
70	}
71
72	req, err := client.GeneratePreparer(ctx, resourceGroupName, workspaceName, request)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "servicemap.MapsClient", "Generate", nil, "Failure preparing request")
75		return
76	}
77
78	resp, err := client.GenerateSender(req)
79	if err != nil {
80		result.Response = autorest.Response{Response: resp}
81		err = autorest.NewErrorWithError(err, "servicemap.MapsClient", "Generate", resp, "Failure sending request")
82		return
83	}
84
85	result, err = client.GenerateResponder(resp)
86	if err != nil {
87		err = autorest.NewErrorWithError(err, "servicemap.MapsClient", "Generate", resp, "Failure responding to request")
88	}
89
90	return
91}
92
93// GeneratePreparer prepares the Generate request.
94func (client MapsClient) GeneratePreparer(ctx context.Context, resourceGroupName string, workspaceName string, request BasicMapRequest) (*http.Request, error) {
95	pathParameters := map[string]interface{}{
96		"resourceGroupName": autorest.Encode("path", resourceGroupName),
97		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
98		"workspaceName":     autorest.Encode("path", workspaceName),
99	}
100
101	const APIVersion = "2015-11-01-preview"
102	queryParameters := map[string]interface{}{
103		"api-version": APIVersion,
104	}
105
106	preparer := autorest.CreatePreparer(
107		autorest.AsContentType("application/json; charset=utf-8"),
108		autorest.AsPost(),
109		autorest.WithBaseURL(client.BaseURI),
110		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/generateMap", pathParameters),
111		autorest.WithJSON(request),
112		autorest.WithQueryParameters(queryParameters))
113	return preparer.Prepare((&http.Request{}).WithContext(ctx))
114}
115
116// GenerateSender sends the Generate request. The method will close the
117// http.Response Body if it receives an error.
118func (client MapsClient) GenerateSender(req *http.Request) (*http.Response, error) {
119	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
120	return autorest.SendWithSender(client, req, sd...)
121}
122
123// GenerateResponder handles the response to the Generate request. The method always
124// closes the http.Response Body.
125func (client MapsClient) GenerateResponder(resp *http.Response) (result MapResponse, err error) {
126	err = autorest.Respond(
127		resp,
128		client.ByInspecting(),
129		azure.WithErrorUnlessStatusCode(http.StatusOK),
130		autorest.ByUnmarshallingJSON(&result),
131		autorest.ByClosing())
132	result.Response = autorest.Response{Response: resp}
133	return
134}
135