1package securityinsight
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// EntityRelationsClient is the API spec for Microsoft.SecurityInsights (Azure Security Insights) resource provider
19type EntityRelationsClient struct {
20	BaseClient
21}
22
23// NewEntityRelationsClient creates an instance of the EntityRelationsClient client.
24func NewEntityRelationsClient(subscriptionID string) EntityRelationsClient {
25	return NewEntityRelationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewEntityRelationsClientWithBaseURI creates an instance of the EntityRelationsClient 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 NewEntityRelationsClientWithBaseURI(baseURI string, subscriptionID string) EntityRelationsClient {
31	return EntityRelationsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// GetRelation gets an entity relation.
35// Parameters:
36// resourceGroupName - the name of the resource group within the user's subscription. The name is case
37// insensitive.
38// operationalInsightsResourceProvider - the namespace of workspaces resource provider-
39// Microsoft.OperationalInsights.
40// workspaceName - the name of the workspace.
41// entityID - entity ID
42// relationName - relation Name
43func (client EntityRelationsClient) GetRelation(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, entityID string, relationName string) (result Relation, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/EntityRelationsClient.GetRelation")
46		defer func() {
47			sc := -1
48			if result.Response.Response != nil {
49				sc = result.Response.Response.StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	if err := validation.Validate([]validation.Validation{
55		{TargetValue: client.SubscriptionID,
56			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.Pattern, Rule: `^[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$`, Chain: nil}}},
57		{TargetValue: resourceGroupName,
58			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
59				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
60				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
61		{TargetValue: workspaceName,
62			Constraints: []validation.Constraint{{Target: "workspaceName", Name: validation.MaxLength, Rule: 90, Chain: nil},
63				{Target: "workspaceName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
64		return result, validation.NewError("securityinsight.EntityRelationsClient", "GetRelation", err.Error())
65	}
66
67	req, err := client.GetRelationPreparer(ctx, resourceGroupName, operationalInsightsResourceProvider, workspaceName, entityID, relationName)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "securityinsight.EntityRelationsClient", "GetRelation", nil, "Failure preparing request")
70		return
71	}
72
73	resp, err := client.GetRelationSender(req)
74	if err != nil {
75		result.Response = autorest.Response{Response: resp}
76		err = autorest.NewErrorWithError(err, "securityinsight.EntityRelationsClient", "GetRelation", resp, "Failure sending request")
77		return
78	}
79
80	result, err = client.GetRelationResponder(resp)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "securityinsight.EntityRelationsClient", "GetRelation", resp, "Failure responding to request")
83		return
84	}
85
86	return
87}
88
89// GetRelationPreparer prepares the GetRelation request.
90func (client EntityRelationsClient) GetRelationPreparer(ctx context.Context, resourceGroupName string, operationalInsightsResourceProvider string, workspaceName string, entityID string, relationName string) (*http.Request, error) {
91	pathParameters := map[string]interface{}{
92		"entityId":                            autorest.Encode("path", entityID),
93		"operationalInsightsResourceProvider": autorest.Encode("path", operationalInsightsResourceProvider),
94		"relationName":                        autorest.Encode("path", relationName),
95		"resourceGroupName":                   autorest.Encode("path", resourceGroupName),
96		"subscriptionId":                      autorest.Encode("path", client.SubscriptionID),
97		"workspaceName":                       autorest.Encode("path", workspaceName),
98	}
99
100	const APIVersion = "2019-01-01-preview"
101	queryParameters := map[string]interface{}{
102		"api-version": APIVersion,
103	}
104
105	preparer := autorest.CreatePreparer(
106		autorest.AsGet(),
107		autorest.WithBaseURL(client.BaseURI),
108		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/entities/{entityId}/relations/{relationName}", pathParameters),
109		autorest.WithQueryParameters(queryParameters))
110	return preparer.Prepare((&http.Request{}).WithContext(ctx))
111}
112
113// GetRelationSender sends the GetRelation request. The method will close the
114// http.Response Body if it receives an error.
115func (client EntityRelationsClient) GetRelationSender(req *http.Request) (*http.Response, error) {
116	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
117}
118
119// GetRelationResponder handles the response to the GetRelation request. The method always
120// closes the http.Response Body.
121func (client EntityRelationsClient) GetRelationResponder(resp *http.Response) (result Relation, err error) {
122	err = autorest.Respond(
123		resp,
124		azure.WithErrorUnlessStatusCode(http.StatusOK),
125		autorest.ByUnmarshallingJSON(&result),
126		autorest.ByClosing())
127	result.Response = autorest.Response{Response: resp}
128	return
129}
130