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/tracing" 14 "net/http" 15) 16 17// CompliancesClient is the API spec for Microsoft.Security (Azure Security Center) resource provider 18type CompliancesClient struct { 19 BaseClient 20} 21 22// NewCompliancesClient creates an instance of the CompliancesClient client. 23func NewCompliancesClient(subscriptionID string, ascLocation string) CompliancesClient { 24 return NewCompliancesClientWithBaseURI(DefaultBaseURI, subscriptionID, ascLocation) 25} 26 27// NewCompliancesClientWithBaseURI creates an instance of the CompliancesClient client using a custom endpoint. Use 28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewCompliancesClientWithBaseURI(baseURI string, subscriptionID string, ascLocation string) CompliancesClient { 30 return CompliancesClient{NewWithBaseURI(baseURI, subscriptionID, ascLocation)} 31} 32 33// Get details of a specific Compliance. 34// Parameters: 35// scope - scope of the query, can be subscription (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or 36// management group (/providers/Microsoft.Management/managementGroups/mgName). 37// complianceName - name of the Compliance 38func (client CompliancesClient) Get(ctx context.Context, scope string, complianceName string) (result Compliance, err error) { 39 if tracing.IsEnabled() { 40 ctx = tracing.StartSpan(ctx, fqdn+"/CompliancesClient.Get") 41 defer func() { 42 sc := -1 43 if result.Response.Response != nil { 44 sc = result.Response.Response.StatusCode 45 } 46 tracing.EndSpan(ctx, sc, err) 47 }() 48 } 49 req, err := client.GetPreparer(ctx, scope, complianceName) 50 if err != nil { 51 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "Get", nil, "Failure preparing request") 52 return 53 } 54 55 resp, err := client.GetSender(req) 56 if err != nil { 57 result.Response = autorest.Response{Response: resp} 58 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "Get", resp, "Failure sending request") 59 return 60 } 61 62 result, err = client.GetResponder(resp) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "Get", resp, "Failure responding to request") 65 return 66 } 67 68 return 69} 70 71// GetPreparer prepares the Get request. 72func (client CompliancesClient) GetPreparer(ctx context.Context, scope string, complianceName string) (*http.Request, error) { 73 pathParameters := map[string]interface{}{ 74 "complianceName": autorest.Encode("path", complianceName), 75 "scope": scope, 76 } 77 78 const APIVersion = "2017-08-01-preview" 79 queryParameters := map[string]interface{}{ 80 "api-version": APIVersion, 81 } 82 83 preparer := autorest.CreatePreparer( 84 autorest.AsGet(), 85 autorest.WithBaseURL(client.BaseURI), 86 autorest.WithPathParameters("/{scope}/providers/Microsoft.Security/compliances/{complianceName}", pathParameters), 87 autorest.WithQueryParameters(queryParameters)) 88 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 89} 90 91// GetSender sends the Get request. The method will close the 92// http.Response Body if it receives an error. 93func (client CompliancesClient) GetSender(req *http.Request) (*http.Response, error) { 94 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 95} 96 97// GetResponder handles the response to the Get request. The method always 98// closes the http.Response Body. 99func (client CompliancesClient) GetResponder(resp *http.Response) (result Compliance, err error) { 100 err = autorest.Respond( 101 resp, 102 azure.WithErrorUnlessStatusCode(http.StatusOK), 103 autorest.ByUnmarshallingJSON(&result), 104 autorest.ByClosing()) 105 result.Response = autorest.Response{Response: resp} 106 return 107} 108 109// List the Compliance scores of the specific management group. 110// Parameters: 111// scope - scope of the query, can be subscription (/subscriptions/0b06d9ea-afe6-4779-bd59-30e5c2d9d13f) or 112// management group (/providers/Microsoft.Management/managementGroups/mgName). 113func (client CompliancesClient) List(ctx context.Context, scope string) (result ComplianceListPage, err error) { 114 if tracing.IsEnabled() { 115 ctx = tracing.StartSpan(ctx, fqdn+"/CompliancesClient.List") 116 defer func() { 117 sc := -1 118 if result.cl.Response.Response != nil { 119 sc = result.cl.Response.Response.StatusCode 120 } 121 tracing.EndSpan(ctx, sc, err) 122 }() 123 } 124 result.fn = client.listNextResults 125 req, err := client.ListPreparer(ctx, scope) 126 if err != nil { 127 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "List", nil, "Failure preparing request") 128 return 129 } 130 131 resp, err := client.ListSender(req) 132 if err != nil { 133 result.cl.Response = autorest.Response{Response: resp} 134 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "List", resp, "Failure sending request") 135 return 136 } 137 138 result.cl, err = client.ListResponder(resp) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "List", resp, "Failure responding to request") 141 return 142 } 143 if result.cl.hasNextLink() && result.cl.IsEmpty() { 144 err = result.NextWithContext(ctx) 145 return 146 } 147 148 return 149} 150 151// ListPreparer prepares the List request. 152func (client CompliancesClient) ListPreparer(ctx context.Context, scope string) (*http.Request, error) { 153 pathParameters := map[string]interface{}{ 154 "scope": scope, 155 } 156 157 const APIVersion = "2017-08-01-preview" 158 queryParameters := map[string]interface{}{ 159 "api-version": APIVersion, 160 } 161 162 preparer := autorest.CreatePreparer( 163 autorest.AsGet(), 164 autorest.WithBaseURL(client.BaseURI), 165 autorest.WithPathParameters("/{scope}/providers/Microsoft.Security/compliances", pathParameters), 166 autorest.WithQueryParameters(queryParameters)) 167 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 168} 169 170// ListSender sends the List request. The method will close the 171// http.Response Body if it receives an error. 172func (client CompliancesClient) ListSender(req *http.Request) (*http.Response, error) { 173 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 174} 175 176// ListResponder handles the response to the List request. The method always 177// closes the http.Response Body. 178func (client CompliancesClient) ListResponder(resp *http.Response) (result ComplianceList, err error) { 179 err = autorest.Respond( 180 resp, 181 azure.WithErrorUnlessStatusCode(http.StatusOK), 182 autorest.ByUnmarshallingJSON(&result), 183 autorest.ByClosing()) 184 result.Response = autorest.Response{Response: resp} 185 return 186} 187 188// listNextResults retrieves the next set of results, if any. 189func (client CompliancesClient) listNextResults(ctx context.Context, lastResults ComplianceList) (result ComplianceList, err error) { 190 req, err := lastResults.complianceListPreparer(ctx) 191 if err != nil { 192 return result, autorest.NewErrorWithError(err, "security.CompliancesClient", "listNextResults", nil, "Failure preparing next results request") 193 } 194 if req == nil { 195 return 196 } 197 resp, err := client.ListSender(req) 198 if err != nil { 199 result.Response = autorest.Response{Response: resp} 200 return result, autorest.NewErrorWithError(err, "security.CompliancesClient", "listNextResults", resp, "Failure sending next results request") 201 } 202 result, err = client.ListResponder(resp) 203 if err != nil { 204 err = autorest.NewErrorWithError(err, "security.CompliancesClient", "listNextResults", resp, "Failure responding to next results request") 205 } 206 return 207} 208 209// ListComplete enumerates all values, automatically crossing page boundaries as required. 210func (client CompliancesClient) ListComplete(ctx context.Context, scope string) (result ComplianceListIterator, err error) { 211 if tracing.IsEnabled() { 212 ctx = tracing.StartSpan(ctx, fqdn+"/CompliancesClient.List") 213 defer func() { 214 sc := -1 215 if result.Response().Response.Response != nil { 216 sc = result.page.Response().Response.Response.StatusCode 217 } 218 tracing.EndSpan(ctx, sc, err) 219 }() 220 } 221 result.page, err = client.List(ctx, scope) 222 return 223} 224