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	"net/http"
26)
27
28// MapsClient is the service Map API Reference
29type MapsClient struct {
30	BaseClient
31}
32
33// NewMapsClient creates an instance of the MapsClient client.
34func NewMapsClient(subscriptionID string) MapsClient {
35	return NewMapsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewMapsClientWithBaseURI creates an instance of the MapsClient client.
39func NewMapsClientWithBaseURI(baseURI string, subscriptionID string) MapsClient {
40	return MapsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// Generate generates the specified map.
44// Parameters:
45// resourceGroupName - resource group name within the specified subscriptionId.
46// workspaceName - OMS workspace containing the resources of interest.
47// request - request options.
48func (client MapsClient) Generate(ctx context.Context, resourceGroupName string, workspaceName string, request BasicMapRequest) (result MapResponse, err error) {
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: resourceGroupName,
51			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 64, Chain: nil},
52				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
53				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_-]+`, Chain: nil}}},
54		{TargetValue: workspaceName,
55			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
56				{Target: "workspaceName", Name: validation.MinLength, Rule: 3, Chain: nil},
57				{Target: "workspaceName", Name: validation.Pattern, Rule: `[a-zA-Z0-9_][a-zA-Z0-9_-]+[a-zA-Z0-9_]`, Chain: nil}}}}); err != nil {
58		return result, validation.NewError("servicemap.MapsClient", "Generate", err.Error())
59	}
60
61	req, err := client.GeneratePreparer(ctx, resourceGroupName, workspaceName, request)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "servicemap.MapsClient", "Generate", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.GenerateSender(req)
68	if err != nil {
69		result.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "servicemap.MapsClient", "Generate", resp, "Failure sending request")
71		return
72	}
73
74	result, err = client.GenerateResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "servicemap.MapsClient", "Generate", resp, "Failure responding to request")
77	}
78
79	return
80}
81
82// GeneratePreparer prepares the Generate request.
83func (client MapsClient) GeneratePreparer(ctx context.Context, resourceGroupName string, workspaceName string, request BasicMapRequest) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"resourceGroupName": autorest.Encode("path", resourceGroupName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87		"workspaceName":     autorest.Encode("path", workspaceName),
88	}
89
90	const APIVersion = "2015-11-01-preview"
91	queryParameters := map[string]interface{}{
92		"api-version": APIVersion,
93	}
94
95	preparer := autorest.CreatePreparer(
96		autorest.AsContentType("application/json; charset=utf-8"),
97		autorest.AsPost(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/features/serviceMap/generateMap", pathParameters),
100		autorest.WithJSON(request),
101		autorest.WithQueryParameters(queryParameters))
102	return preparer.Prepare((&http.Request{}).WithContext(ctx))
103}
104
105// GenerateSender sends the Generate request. The method will close the
106// http.Response Body if it receives an error.
107func (client MapsClient) GenerateSender(req *http.Request) (*http.Response, error) {
108	return autorest.SendWithSender(client, req,
109		azure.DoRetryWithRegistration(client.Client))
110}
111
112// GenerateResponder handles the response to the Generate request. The method always
113// closes the http.Response Body.
114func (client MapsClient) GenerateResponder(resp *http.Response) (result MapResponse, err error) {
115	err = autorest.Respond(
116		resp,
117		client.ByInspecting(),
118		azure.WithErrorUnlessStatusCode(http.StatusOK),
119		autorest.ByUnmarshallingJSON(&result),
120		autorest.ByClosing())
121	result.Response = autorest.Response{Response: resp}
122	return
123}
124