1package security
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// TopologyClient is the API spec for Microsoft.Security (Azure Security Center) resource provider
19type TopologyClient struct {
20	BaseClient
21}
22
23// NewTopologyClient creates an instance of the TopologyClient client.
24func NewTopologyClient(subscriptionID string, ascLocation string) TopologyClient {
25	return NewTopologyClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation)
26}
27
28// NewTopologyClientWithBaseURI creates an instance of the TopologyClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewTopologyClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) TopologyClient {
31	return TopologyClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)}
32}
33
34// Get gets a specific topology component.
35// Parameters:
36// resourceGroupName - the name of the resource group within the user's subscription. The name is case
37// insensitive.
38// topologyResourceName - name of a topology resources collection.
39func (client TopologyClient) Get(ctx context.Context, resourceGroupName string, topologyResourceName string) (result TopologyResource, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/TopologyClient.Get")
42		defer func() {
43			sc := -1
44			if result.Response.Response != nil {
45				sc = result.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: client.SubscriptionID,
52			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}}},
53		{TargetValue: resourceGroupName,
54			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
55				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
57		return result, validation.NewError("security.TopologyClient", "Get", err.Error())
58	}
59
60	req, err := client.GetPreparer(ctx, resourceGroupName, topologyResourceName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "security.TopologyClient", "Get", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.GetSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "security.TopologyClient", "Get", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.GetResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "security.TopologyClient", "Get", resp, "Failure responding to request")
76		return
77	}
78
79	return
80}
81
82// GetPreparer prepares the Get request.
83func (client TopologyClient) GetPreparer(ctx context.Context, resourceGroupName string, topologyResourceName string) (*http.Request, error) {
84	pathParameters := map[string]interface{}{
85		"ascLocation":          autorest.Encode("path", client.AscLocation),
86		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
87		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
88		"topologyResourceName": autorest.Encode("path", topologyResourceName),
89	}
90
91	const APIVersion = "2015-06-01-preview"
92	queryParameters := map[string]interface{}{
93		"api-version": APIVersion,
94	}
95
96	preparer := autorest.CreatePreparer(
97		autorest.AsGet(),
98		autorest.WithBaseURL(client.BaseURI),
99		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Security/locations/{ascLocation}/topologies/{topologyResourceName}", pathParameters),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// GetSender sends the Get request. The method will close the
105// http.Response Body if it receives an error.
106func (client TopologyClient) GetSender(req *http.Request) (*http.Response, error) {
107	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108}
109
110// GetResponder handles the response to the Get request. The method always
111// closes the http.Response Body.
112func (client TopologyClient) GetResponder(resp *http.Response) (result TopologyResource, err error) {
113	err = autorest.Respond(
114		resp,
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121
122// List gets a list that allows to build a topology view of a subscription.
123func (client TopologyClient) List(ctx context.Context) (result TopologyListPage, err error) {
124	if tracing.IsEnabled() {
125		ctx = tracing.StartSpan(ctx, fqdn+"/TopologyClient.List")
126		defer func() {
127			sc := -1
128			if result.tl.Response.Response != nil {
129				sc = result.tl.Response.Response.StatusCode
130			}
131			tracing.EndSpan(ctx, sc, err)
132		}()
133	}
134	if err := validation.Validate([]validation.Validation{
135		{TargetValue: client.SubscriptionID,
136			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}}}}); err != nil {
137		return result, validation.NewError("security.TopologyClient", "List", err.Error())
138	}
139
140	result.fn = client.listNextResults
141	req, err := client.ListPreparer(ctx)
142	if err != nil {
143		err = autorest.NewErrorWithError(err, "security.TopologyClient", "List", nil, "Failure preparing request")
144		return
145	}
146
147	resp, err := client.ListSender(req)
148	if err != nil {
149		result.tl.Response = autorest.Response{Response: resp}
150		err = autorest.NewErrorWithError(err, "security.TopologyClient", "List", resp, "Failure sending request")
151		return
152	}
153
154	result.tl, err = client.ListResponder(resp)
155	if err != nil {
156		err = autorest.NewErrorWithError(err, "security.TopologyClient", "List", resp, "Failure responding to request")
157		return
158	}
159	if result.tl.hasNextLink() && result.tl.IsEmpty() {
160		err = result.NextWithContext(ctx)
161		return
162	}
163
164	return
165}
166
167// ListPreparer prepares the List request.
168func (client TopologyClient) ListPreparer(ctx context.Context) (*http.Request, error) {
169	pathParameters := map[string]interface{}{
170		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
171	}
172
173	const APIVersion = "2015-06-01-preview"
174	queryParameters := map[string]interface{}{
175		"api-version": APIVersion,
176	}
177
178	preparer := autorest.CreatePreparer(
179		autorest.AsGet(),
180		autorest.WithBaseURL(client.BaseURI),
181		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/topologies", pathParameters),
182		autorest.WithQueryParameters(queryParameters))
183	return preparer.Prepare((&http.Request{}).WithContext(ctx))
184}
185
186// ListSender sends the List request. The method will close the
187// http.Response Body if it receives an error.
188func (client TopologyClient) ListSender(req *http.Request) (*http.Response, error) {
189	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
190}
191
192// ListResponder handles the response to the List request. The method always
193// closes the http.Response Body.
194func (client TopologyClient) ListResponder(resp *http.Response) (result TopologyList, err error) {
195	err = autorest.Respond(
196		resp,
197		azure.WithErrorUnlessStatusCode(http.StatusOK),
198		autorest.ByUnmarshallingJSON(&result),
199		autorest.ByClosing())
200	result.Response = autorest.Response{Response: resp}
201	return
202}
203
204// listNextResults retrieves the next set of results, if any.
205func (client TopologyClient) listNextResults(ctx context.Context, lastResults TopologyList) (result TopologyList, err error) {
206	req, err := lastResults.topologyListPreparer(ctx)
207	if err != nil {
208		return result, autorest.NewErrorWithError(err, "security.TopologyClient", "listNextResults", nil, "Failure preparing next results request")
209	}
210	if req == nil {
211		return
212	}
213	resp, err := client.ListSender(req)
214	if err != nil {
215		result.Response = autorest.Response{Response: resp}
216		return result, autorest.NewErrorWithError(err, "security.TopologyClient", "listNextResults", resp, "Failure sending next results request")
217	}
218	result, err = client.ListResponder(resp)
219	if err != nil {
220		err = autorest.NewErrorWithError(err, "security.TopologyClient", "listNextResults", resp, "Failure responding to next results request")
221	}
222	return
223}
224
225// ListComplete enumerates all values, automatically crossing page boundaries as required.
226func (client TopologyClient) ListComplete(ctx context.Context) (result TopologyListIterator, err error) {
227	if tracing.IsEnabled() {
228		ctx = tracing.StartSpan(ctx, fqdn+"/TopologyClient.List")
229		defer func() {
230			sc := -1
231			if result.Response().Response.Response != nil {
232				sc = result.page.Response().Response.Response.StatusCode
233			}
234			tracing.EndSpan(ctx, sc, err)
235		}()
236	}
237	result.page, err = client.List(ctx)
238	return
239}
240
241// ListByHomeRegion gets a list that allows to build a topology view of a subscription and location.
242func (client TopologyClient) ListByHomeRegion(ctx context.Context) (result TopologyListPage, err error) {
243	if tracing.IsEnabled() {
244		ctx = tracing.StartSpan(ctx, fqdn+"/TopologyClient.ListByHomeRegion")
245		defer func() {
246			sc := -1
247			if result.tl.Response.Response != nil {
248				sc = result.tl.Response.Response.StatusCode
249			}
250			tracing.EndSpan(ctx, sc, err)
251		}()
252	}
253	if err := validation.Validate([]validation.Validation{
254		{TargetValue: client.SubscriptionID,
255			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}}}}); err != nil {
256		return result, validation.NewError("security.TopologyClient", "ListByHomeRegion", err.Error())
257	}
258
259	result.fn = client.listByHomeRegionNextResults
260	req, err := client.ListByHomeRegionPreparer(ctx)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "security.TopologyClient", "ListByHomeRegion", nil, "Failure preparing request")
263		return
264	}
265
266	resp, err := client.ListByHomeRegionSender(req)
267	if err != nil {
268		result.tl.Response = autorest.Response{Response: resp}
269		err = autorest.NewErrorWithError(err, "security.TopologyClient", "ListByHomeRegion", resp, "Failure sending request")
270		return
271	}
272
273	result.tl, err = client.ListByHomeRegionResponder(resp)
274	if err != nil {
275		err = autorest.NewErrorWithError(err, "security.TopologyClient", "ListByHomeRegion", resp, "Failure responding to request")
276		return
277	}
278	if result.tl.hasNextLink() && result.tl.IsEmpty() {
279		err = result.NextWithContext(ctx)
280		return
281	}
282
283	return
284}
285
286// ListByHomeRegionPreparer prepares the ListByHomeRegion request.
287func (client TopologyClient) ListByHomeRegionPreparer(ctx context.Context) (*http.Request, error) {
288	pathParameters := map[string]interface{}{
289		"ascLocation":    autorest.Encode("path", client.AscLocation),
290		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
291	}
292
293	const APIVersion = "2015-06-01-preview"
294	queryParameters := map[string]interface{}{
295		"api-version": APIVersion,
296	}
297
298	preparer := autorest.CreatePreparer(
299		autorest.AsGet(),
300		autorest.WithBaseURL(client.BaseURI),
301		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/locations/{ascLocation}/topologies", pathParameters),
302		autorest.WithQueryParameters(queryParameters))
303	return preparer.Prepare((&http.Request{}).WithContext(ctx))
304}
305
306// ListByHomeRegionSender sends the ListByHomeRegion request. The method will close the
307// http.Response Body if it receives an error.
308func (client TopologyClient) ListByHomeRegionSender(req *http.Request) (*http.Response, error) {
309	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
310}
311
312// ListByHomeRegionResponder handles the response to the ListByHomeRegion request. The method always
313// closes the http.Response Body.
314func (client TopologyClient) ListByHomeRegionResponder(resp *http.Response) (result TopologyList, err error) {
315	err = autorest.Respond(
316		resp,
317		azure.WithErrorUnlessStatusCode(http.StatusOK),
318		autorest.ByUnmarshallingJSON(&result),
319		autorest.ByClosing())
320	result.Response = autorest.Response{Response: resp}
321	return
322}
323
324// listByHomeRegionNextResults retrieves the next set of results, if any.
325func (client TopologyClient) listByHomeRegionNextResults(ctx context.Context, lastResults TopologyList) (result TopologyList, err error) {
326	req, err := lastResults.topologyListPreparer(ctx)
327	if err != nil {
328		return result, autorest.NewErrorWithError(err, "security.TopologyClient", "listByHomeRegionNextResults", nil, "Failure preparing next results request")
329	}
330	if req == nil {
331		return
332	}
333	resp, err := client.ListByHomeRegionSender(req)
334	if err != nil {
335		result.Response = autorest.Response{Response: resp}
336		return result, autorest.NewErrorWithError(err, "security.TopologyClient", "listByHomeRegionNextResults", resp, "Failure sending next results request")
337	}
338	result, err = client.ListByHomeRegionResponder(resp)
339	if err != nil {
340		err = autorest.NewErrorWithError(err, "security.TopologyClient", "listByHomeRegionNextResults", resp, "Failure responding to next results request")
341	}
342	return
343}
344
345// ListByHomeRegionComplete enumerates all values, automatically crossing page boundaries as required.
346func (client TopologyClient) ListByHomeRegionComplete(ctx context.Context) (result TopologyListIterator, err error) {
347	if tracing.IsEnabled() {
348		ctx = tracing.StartSpan(ctx, fqdn+"/TopologyClient.ListByHomeRegion")
349		defer func() {
350			sc := -1
351			if result.Response().Response.Response != nil {
352				sc = result.page.Response().Response.Response.StatusCode
353			}
354			tracing.EndSpan(ctx, sc, err)
355		}()
356	}
357	result.page, err = client.ListByHomeRegion(ctx)
358	return
359}
360