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// RegulatoryComplianceControlsClient is the API spec for Microsoft.Security (Azure Security Center) resource provider
19type RegulatoryComplianceControlsClient struct {
20	BaseClient
21}
22
23// NewRegulatoryComplianceControlsClient creates an instance of the RegulatoryComplianceControlsClient client.
24func NewRegulatoryComplianceControlsClient(subscriptionID string, ascLocation string) RegulatoryComplianceControlsClient {
25	return NewRegulatoryComplianceControlsClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation)
26}
27
28// NewRegulatoryComplianceControlsClientWithBaseURI creates an instance of the RegulatoryComplianceControlsClient
29// client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
30// (sovereign clouds, Azure stack).
31func NewRegulatoryComplianceControlsClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) RegulatoryComplianceControlsClient {
32	return RegulatoryComplianceControlsClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)}
33}
34
35// Get selected regulatory compliance control details and state
36// Parameters:
37// regulatoryComplianceStandardName - name of the regulatory compliance standard object
38// regulatoryComplianceControlName - name of the regulatory compliance control object
39func (client RegulatoryComplianceControlsClient) Get(ctx context.Context, regulatoryComplianceStandardName string, regulatoryComplianceControlName string) (result RegulatoryComplianceControl, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/RegulatoryComplianceControlsClient.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}}}}); err != nil {
53		return result, validation.NewError("security.RegulatoryComplianceControlsClient", "Get", err.Error())
54	}
55
56	req, err := client.GetPreparer(ctx, regulatoryComplianceStandardName, regulatoryComplianceControlName)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "Get", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.GetSender(req)
63	if err != nil {
64		result.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "Get", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.GetResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "Get", resp, "Failure responding to request")
72		return
73	}
74
75	return
76}
77
78// GetPreparer prepares the Get request.
79func (client RegulatoryComplianceControlsClient) GetPreparer(ctx context.Context, regulatoryComplianceStandardName string, regulatoryComplianceControlName string) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"regulatoryComplianceControlName":  autorest.Encode("path", regulatoryComplianceControlName),
82		"regulatoryComplianceStandardName": autorest.Encode("path", regulatoryComplianceStandardName),
83		"subscriptionId":                   autorest.Encode("path", client.SubscriptionID),
84	}
85
86	const APIVersion = "2019-01-01-preview"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsGet(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/regulatoryComplianceStandards/{regulatoryComplianceStandardName}/regulatoryComplianceControls/{regulatoryComplianceControlName}", pathParameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// GetSender sends the Get request. The method will close the
100// http.Response Body if it receives an error.
101func (client RegulatoryComplianceControlsClient) GetSender(req *http.Request) (*http.Response, error) {
102	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
103}
104
105// GetResponder handles the response to the Get request. The method always
106// closes the http.Response Body.
107func (client RegulatoryComplianceControlsClient) GetResponder(resp *http.Response) (result RegulatoryComplianceControl, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK),
111		autorest.ByUnmarshallingJSON(&result),
112		autorest.ByClosing())
113	result.Response = autorest.Response{Response: resp}
114	return
115}
116
117// List all supported regulatory compliance controls details and state for selected standard
118// Parameters:
119// regulatoryComplianceStandardName - name of the regulatory compliance standard object
120// filter - oData filter. Optional.
121func (client RegulatoryComplianceControlsClient) List(ctx context.Context, regulatoryComplianceStandardName string, filter string) (result RegulatoryComplianceControlListPage, err error) {
122	if tracing.IsEnabled() {
123		ctx = tracing.StartSpan(ctx, fqdn+"/RegulatoryComplianceControlsClient.List")
124		defer func() {
125			sc := -1
126			if result.rccl.Response.Response != nil {
127				sc = result.rccl.Response.Response.StatusCode
128			}
129			tracing.EndSpan(ctx, sc, err)
130		}()
131	}
132	if err := validation.Validate([]validation.Validation{
133		{TargetValue: client.SubscriptionID,
134			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 {
135		return result, validation.NewError("security.RegulatoryComplianceControlsClient", "List", err.Error())
136	}
137
138	result.fn = client.listNextResults
139	req, err := client.ListPreparer(ctx, regulatoryComplianceStandardName, filter)
140	if err != nil {
141		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "List", nil, "Failure preparing request")
142		return
143	}
144
145	resp, err := client.ListSender(req)
146	if err != nil {
147		result.rccl.Response = autorest.Response{Response: resp}
148		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "List", resp, "Failure sending request")
149		return
150	}
151
152	result.rccl, err = client.ListResponder(resp)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "List", resp, "Failure responding to request")
155		return
156	}
157	if result.rccl.hasNextLink() && result.rccl.IsEmpty() {
158		err = result.NextWithContext(ctx)
159		return
160	}
161
162	return
163}
164
165// ListPreparer prepares the List request.
166func (client RegulatoryComplianceControlsClient) ListPreparer(ctx context.Context, regulatoryComplianceStandardName string, filter string) (*http.Request, error) {
167	pathParameters := map[string]interface{}{
168		"regulatoryComplianceStandardName": autorest.Encode("path", regulatoryComplianceStandardName),
169		"subscriptionId":                   autorest.Encode("path", client.SubscriptionID),
170	}
171
172	const APIVersion = "2019-01-01-preview"
173	queryParameters := map[string]interface{}{
174		"api-version": APIVersion,
175	}
176	if len(filter) > 0 {
177		queryParameters["$filter"] = autorest.Encode("query", filter)
178	}
179
180	preparer := autorest.CreatePreparer(
181		autorest.AsGet(),
182		autorest.WithBaseURL(client.BaseURI),
183		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Security/regulatoryComplianceStandards/{regulatoryComplianceStandardName}/regulatoryComplianceControls", pathParameters),
184		autorest.WithQueryParameters(queryParameters))
185	return preparer.Prepare((&http.Request{}).WithContext(ctx))
186}
187
188// ListSender sends the List request. The method will close the
189// http.Response Body if it receives an error.
190func (client RegulatoryComplianceControlsClient) ListSender(req *http.Request) (*http.Response, error) {
191	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
192}
193
194// ListResponder handles the response to the List request. The method always
195// closes the http.Response Body.
196func (client RegulatoryComplianceControlsClient) ListResponder(resp *http.Response) (result RegulatoryComplianceControlList, err error) {
197	err = autorest.Respond(
198		resp,
199		azure.WithErrorUnlessStatusCode(http.StatusOK),
200		autorest.ByUnmarshallingJSON(&result),
201		autorest.ByClosing())
202	result.Response = autorest.Response{Response: resp}
203	return
204}
205
206// listNextResults retrieves the next set of results, if any.
207func (client RegulatoryComplianceControlsClient) listNextResults(ctx context.Context, lastResults RegulatoryComplianceControlList) (result RegulatoryComplianceControlList, err error) {
208	req, err := lastResults.regulatoryComplianceControlListPreparer(ctx)
209	if err != nil {
210		return result, autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "listNextResults", nil, "Failure preparing next results request")
211	}
212	if req == nil {
213		return
214	}
215	resp, err := client.ListSender(req)
216	if err != nil {
217		result.Response = autorest.Response{Response: resp}
218		return result, autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "listNextResults", resp, "Failure sending next results request")
219	}
220	result, err = client.ListResponder(resp)
221	if err != nil {
222		err = autorest.NewErrorWithError(err, "security.RegulatoryComplianceControlsClient", "listNextResults", resp, "Failure responding to next results request")
223	}
224	return
225}
226
227// ListComplete enumerates all values, automatically crossing page boundaries as required.
228func (client RegulatoryComplianceControlsClient) ListComplete(ctx context.Context, regulatoryComplianceStandardName string, filter string) (result RegulatoryComplianceControlListIterator, err error) {
229	if tracing.IsEnabled() {
230		ctx = tracing.StartSpan(ctx, fqdn+"/RegulatoryComplianceControlsClient.List")
231		defer func() {
232			sc := -1
233			if result.Response().Response.Response != nil {
234				sc = result.page.Response().Response.Response.StatusCode
235			}
236			tracing.EndSpan(ctx, sc, err)
237		}()
238	}
239	result.page, err = client.List(ctx, regulatoryComplianceStandardName, filter)
240	return
241}
242