From 3e96db89e24907ed4ab3fd3a9455787123528908 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Thu, 28 Jan 2021 03:40:51 +0000 Subject: [PATCH] CodeGen from PR 12661 in Azure/azure-rest-api-specs Add Microsoft.PolicyInsights/attestations API (#12661) * Attestations API * Update definitionReferenceId description * Update owner description * Update readmes with new tag * Move to 2021-01-01 * Update api-version * Update owners --- .../policyinsights/CHANGELOG.md | 5 + .../policyinsights/attestations.go | 1257 +++++++ .../policyinsights/client.go | 52 + .../policyinsights/enums.go | 102 + .../policyinsights/models.go | 3331 +++++++++++++++++ .../policyinsights/operations.go | 109 + .../policyinsights/policyevents.go | 1347 +++++++ .../policyinsightsapi/interfaces.go | 176 + .../policyinsights/policymetadata.go | 237 ++ .../policyinsights/policyrestrictions.go | 221 ++ .../policyinsights/policystates.go | 2349 ++++++++++++ .../policyinsights/policytrackedresources.go | 571 +++ .../policyinsights/remediations.go | 2317 ++++++++++++ .../policyinsights/version.go | 30 + 14 files changed, 12104 insertions(+) create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/CHANGELOG.md create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/attestations.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/client.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/enums.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/models.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/operations.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyevents.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyinsightsapi/interfaces.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policymetadata.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyrestrictions.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policystates.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policytrackedresources.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/remediations.go create mode 100644 services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/version.go diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/CHANGELOG.md b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/CHANGELOG.md new file mode 100644 index 000000000000..941a9a184ea4 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/CHANGELOG.md @@ -0,0 +1,5 @@ +Generated from https://github.com/Azure/azure-rest-api-specs/tree/../../../../../azure-rest-api-specs/specification/policyinsights/resource-manager/readme.md tag: `package-2021-01` + +Code generator + + diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/attestations.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/attestations.go new file mode 100644 index 000000000000..b2060b71d9fa --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/attestations.go @@ -0,0 +1,1257 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// AttestationsClient is the client for the Attestations methods of the Policyinsights service. +type AttestationsClient struct { + BaseClient +} + +// NewAttestationsClient creates an instance of the AttestationsClient client. +func NewAttestationsClient(subscriptionID2 string) AttestationsClient { + return NewAttestationsClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewAttestationsClientWithBaseURI creates an instance of the AttestationsClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewAttestationsClientWithBaseURI(baseURI string, subscriptionID2 string) AttestationsClient { + return AttestationsClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// CreateOrUpdateAtResource creates or updates an attestation at resource scope. +// Parameters: +// resourceID - resource ID. +// attestationName - the name of the attestation. +// parameters - the attestation parameters. +func (client AttestationsClient) CreateOrUpdateAtResource(ctx context.Context, resourceID string, attestationName string, parameters Attestation) (result AttestationsCreateOrUpdateAtResourceFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.CreateOrUpdateAtResource") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.AttestationProperties", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.AttestationProperties.PolicyAssignmentID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "CreateOrUpdateAtResource", err.Error()) + } + + req, err := client.CreateOrUpdateAtResourcePreparer(ctx, resourceID, attestationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "CreateOrUpdateAtResource", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateAtResourceSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "CreateOrUpdateAtResource", nil, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateAtResourcePreparer prepares the CreateOrUpdateAtResource request. +func (client AttestationsClient) CreateOrUpdateAtResourcePreparer(ctx context.Context, resourceID string, attestationName string, parameters Attestation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "resourceId": resourceID, + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtResourceSender sends the CreateOrUpdateAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) CreateOrUpdateAtResourceSender(req *http.Request) (future AttestationsCreateOrUpdateAtResourceFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if err != nil { + return + } + var azf azure.Future + azf, err = azure.NewFutureFromResponse(resp) + future.FutureAPI = &azf + future.Result = func(client AttestationsClient) (a Attestation, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsCreateOrUpdateAtResourceFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("policyinsights.AttestationsCreateOrUpdateAtResourceFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if a.Response.Response, err = future.GetResult(sender); err == nil && a.Response.Response.StatusCode != http.StatusNoContent { + a, err = client.CreateOrUpdateAtResourceResponder(a.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsCreateOrUpdateAtResourceFuture", "Result", a.Response.Response, "Failure responding to request") + } + } + return + } + return +} + +// CreateOrUpdateAtResourceResponder handles the response to the CreateOrUpdateAtResource request. The method always +// closes the http.Response Body. +func (client AttestationsClient) CreateOrUpdateAtResourceResponder(resp *http.Response) (result Attestation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdateAtResourceGroup creates or updates an attestation at resource group scope. +// Parameters: +// subscriptionID - the ID of the target subscription. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// attestationName - the name of the attestation. +// parameters - the attestation parameters. +func (client AttestationsClient) CreateOrUpdateAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string, parameters Attestation) (result AttestationsCreateOrUpdateAtResourceGroupFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.CreateOrUpdateAtResourceGroup") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.AttestationProperties", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.AttestationProperties.PolicyAssignmentID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "CreateOrUpdateAtResourceGroup", err.Error()) + } + + req, err := client.CreateOrUpdateAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, attestationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "CreateOrUpdateAtResourceGroup", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateAtResourceGroupSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "CreateOrUpdateAtResourceGroup", nil, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateAtResourceGroupPreparer prepares the CreateOrUpdateAtResourceGroup request. +func (client AttestationsClient) CreateOrUpdateAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string, parameters Attestation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtResourceGroupSender sends the CreateOrUpdateAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) CreateOrUpdateAtResourceGroupSender(req *http.Request) (future AttestationsCreateOrUpdateAtResourceGroupFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + var azf azure.Future + azf, err = azure.NewFutureFromResponse(resp) + future.FutureAPI = &azf + future.Result = func(client AttestationsClient) (a Attestation, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsCreateOrUpdateAtResourceGroupFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("policyinsights.AttestationsCreateOrUpdateAtResourceGroupFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if a.Response.Response, err = future.GetResult(sender); err == nil && a.Response.Response.StatusCode != http.StatusNoContent { + a, err = client.CreateOrUpdateAtResourceGroupResponder(a.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsCreateOrUpdateAtResourceGroupFuture", "Result", a.Response.Response, "Failure responding to request") + } + } + return + } + return +} + +// CreateOrUpdateAtResourceGroupResponder handles the response to the CreateOrUpdateAtResourceGroup request. The method always +// closes the http.Response Body. +func (client AttestationsClient) CreateOrUpdateAtResourceGroupResponder(resp *http.Response) (result Attestation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdateAtSubscription creates or updates an attestation at subscription scope. +// Parameters: +// subscriptionID - the ID of the target subscription. +// attestationName - the name of the attestation. +// parameters - the attestation parameters. +func (client AttestationsClient) CreateOrUpdateAtSubscription(ctx context.Context, subscriptionID string, attestationName string, parameters Attestation) (result AttestationsCreateOrUpdateAtSubscriptionFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.CreateOrUpdateAtSubscription") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.AttestationProperties", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.AttestationProperties.PolicyAssignmentID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "CreateOrUpdateAtSubscription", err.Error()) + } + + req, err := client.CreateOrUpdateAtSubscriptionPreparer(ctx, subscriptionID, attestationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "CreateOrUpdateAtSubscription", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateAtSubscriptionSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "CreateOrUpdateAtSubscription", nil, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateAtSubscriptionPreparer prepares the CreateOrUpdateAtSubscription request. +func (client AttestationsClient) CreateOrUpdateAtSubscriptionPreparer(ctx context.Context, subscriptionID string, attestationName string, parameters Attestation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.SystemData = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtSubscriptionSender sends the CreateOrUpdateAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) CreateOrUpdateAtSubscriptionSender(req *http.Request) (future AttestationsCreateOrUpdateAtSubscriptionFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + var azf azure.Future + azf, err = azure.NewFutureFromResponse(resp) + future.FutureAPI = &azf + future.Result = func(client AttestationsClient) (a Attestation, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsCreateOrUpdateAtSubscriptionFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("policyinsights.AttestationsCreateOrUpdateAtSubscriptionFuture") + return + } + sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + if a.Response.Response, err = future.GetResult(sender); err == nil && a.Response.Response.StatusCode != http.StatusNoContent { + a, err = client.CreateOrUpdateAtSubscriptionResponder(a.Response.Response) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsCreateOrUpdateAtSubscriptionFuture", "Result", a.Response.Response, "Failure responding to request") + } + } + return + } + return +} + +// CreateOrUpdateAtSubscriptionResponder handles the response to the CreateOrUpdateAtSubscription request. The method always +// closes the http.Response Body. +func (client AttestationsClient) CreateOrUpdateAtSubscriptionResponder(resp *http.Response) (result Attestation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DeleteAtResource deletes an existing attestation at individual resource scope. +// Parameters: +// resourceID - resource ID. +// attestationName - the name of the attestation. +func (client AttestationsClient) DeleteAtResource(ctx context.Context, resourceID string, attestationName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.DeleteAtResource") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeleteAtResourcePreparer(ctx, resourceID, attestationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtResourceSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtResource", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtResource", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtResourcePreparer prepares the DeleteAtResource request. +func (client AttestationsClient) DeleteAtResourcePreparer(ctx context.Context, resourceID string, attestationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "resourceId": resourceID, + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtResourceSender sends the DeleteAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) DeleteAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteAtResourceResponder handles the response to the DeleteAtResource request. The method always +// closes the http.Response Body. +func (client AttestationsClient) DeleteAtResourceResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// DeleteAtResourceGroup deletes an existing attestation at resource group scope. +// Parameters: +// subscriptionID - the ID of the target subscription. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// attestationName - the name of the attestation. +func (client AttestationsClient) DeleteAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.DeleteAtResourceGroup") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "DeleteAtResourceGroup", err.Error()) + } + + req, err := client.DeleteAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, attestationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtResourceGroupSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtResourceGroupPreparer prepares the DeleteAtResourceGroup request. +func (client AttestationsClient) DeleteAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtResourceGroupSender sends the DeleteAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) DeleteAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteAtResourceGroupResponder handles the response to the DeleteAtResourceGroup request. The method always +// closes the http.Response Body. +func (client AttestationsClient) DeleteAtResourceGroupResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// DeleteAtSubscription deletes an existing attestation at subscription scope. +// Parameters: +// subscriptionID - the ID of the target subscription. +// attestationName - the name of the attestation. +func (client AttestationsClient) DeleteAtSubscription(ctx context.Context, subscriptionID string, attestationName string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.DeleteAtSubscription") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "DeleteAtSubscription", err.Error()) + } + + req, err := client.DeleteAtSubscriptionPreparer(ctx, subscriptionID, attestationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtSubscriptionSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtSubscription", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "DeleteAtSubscription", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtSubscriptionPreparer prepares the DeleteAtSubscription request. +func (client AttestationsClient) DeleteAtSubscriptionPreparer(ctx context.Context, subscriptionID string, attestationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtSubscriptionSender sends the DeleteAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) DeleteAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteAtSubscriptionResponder handles the response to the DeleteAtSubscription request. The method always +// closes the http.Response Body. +func (client AttestationsClient) DeleteAtSubscriptionResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// GetAtResource gets an existing attestation at resource scope. +// Parameters: +// resourceID - resource ID. +// attestationName - the name of the attestation. +func (client AttestationsClient) GetAtResource(ctx context.Context, resourceID string, attestationName string) (result Attestation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.GetAtResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAtResourcePreparer(ctx, resourceID, attestationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtResource", resp, "Failure sending request") + return + } + + result, err = client.GetAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtResource", resp, "Failure responding to request") + return + } + + return +} + +// GetAtResourcePreparer prepares the GetAtResource request. +func (client AttestationsClient) GetAtResourcePreparer(ctx context.Context, resourceID string, attestationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "resourceId": resourceID, + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtResourceSender sends the GetAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) GetAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetAtResourceResponder handles the response to the GetAtResource request. The method always +// closes the http.Response Body. +func (client AttestationsClient) GetAtResourceResponder(resp *http.Response) (result Attestation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAtResourceGroup gets an existing attestation at resource group scope. +// Parameters: +// subscriptionID - the ID of the target subscription. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// attestationName - the name of the attestation. +func (client AttestationsClient) GetAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string) (result Attestation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.GetAtResourceGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "GetAtResourceGroup", err.Error()) + } + + req, err := client.GetAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, attestationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.GetAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// GetAtResourceGroupPreparer prepares the GetAtResourceGroup request. +func (client AttestationsClient) GetAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtResourceGroupSender sends the GetAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) GetAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetAtResourceGroupResponder handles the response to the GetAtResourceGroup request. The method always +// closes the http.Response Body. +func (client AttestationsClient) GetAtResourceGroupResponder(resp *http.Response) (result Attestation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAtSubscription gets an existing attestation at subscription scope. +// Parameters: +// subscriptionID - the ID of the target subscription. +// attestationName - the name of the attestation. +func (client AttestationsClient) GetAtSubscription(ctx context.Context, subscriptionID string, attestationName string) (result Attestation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.GetAtSubscription") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "GetAtSubscription", err.Error()) + } + + req, err := client.GetAtSubscriptionPreparer(ctx, subscriptionID, attestationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtSubscription", resp, "Failure sending request") + return + } + + result, err = client.GetAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "GetAtSubscription", resp, "Failure responding to request") + return + } + + return +} + +// GetAtSubscriptionPreparer prepares the GetAtSubscription request. +func (client AttestationsClient) GetAtSubscriptionPreparer(ctx context.Context, subscriptionID string, attestationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "attestationName": autorest.Encode("path", attestationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/attestations/{attestationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtSubscriptionSender sends the GetAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) GetAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetAtSubscriptionResponder handles the response to the GetAtSubscription request. The method always +// closes the http.Response Body. +func (client AttestationsClient) GetAtSubscriptionResponder(resp *http.Response) (result Attestation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListForResource gets all attestations for a resource. +// Parameters: +// resourceID - resource ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client AttestationsClient) ListForResource(ctx context.Context, resourceID string, top *int32, filter string) (result AttestationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.ListForResource") + defer func() { + sc := -1 + if result.alr.Response.Response != nil { + sc = result.alr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "ListForResource", err.Error()) + } + + result.fn = client.listForResourceNextResults + req, err := client.ListForResourcePreparer(ctx, resourceID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForResource", nil, "Failure preparing request") + return + } + + resp, err := client.ListForResourceSender(req) + if err != nil { + result.alr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForResource", resp, "Failure sending request") + return + } + + result.alr, err = client.ListForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForResource", resp, "Failure responding to request") + return + } + if result.alr.hasNextLink() && result.alr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForResourcePreparer prepares the ListForResource request. +func (client AttestationsClient) ListForResourcePreparer(ctx context.Context, resourceID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceId": resourceID, + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/attestations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForResourceSender sends the ListForResource request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) ListForResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListForResourceResponder handles the response to the ListForResource request. The method always +// closes the http.Response Body. +func (client AttestationsClient) ListForResourceResponder(resp *http.Response) (result AttestationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForResourceNextResults retrieves the next set of results, if any. +func (client AttestationsClient) listForResourceNextResults(ctx context.Context, lastResults AttestationListResult) (result AttestationListResult, err error) { + req, err := lastResults.attestationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForResourceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForResourceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForResourceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForResourceComplete enumerates all values, automatically crossing page boundaries as required. +func (client AttestationsClient) ListForResourceComplete(ctx context.Context, resourceID string, top *int32, filter string) (result AttestationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.ListForResource") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForResource(ctx, resourceID, top, filter) + return +} + +// ListForResourceGroup gets all attestations for the resource group. +// Parameters: +// subscriptionID - the ID of the target subscription. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client AttestationsClient) ListForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result AttestationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.ListForResourceGroup") + defer func() { + sc := -1 + if result.alr.Response.Response != nil { + sc = result.alr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "ListForResourceGroup", err.Error()) + } + + result.fn = client.listForResourceGroupNextResults + req, err := client.ListForResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListForResourceGroupSender(req) + if err != nil { + result.alr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForResourceGroup", resp, "Failure sending request") + return + } + + result.alr, err = client.ListForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForResourceGroup", resp, "Failure responding to request") + return + } + if result.alr.hasNextLink() && result.alr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForResourceGroupPreparer prepares the ListForResourceGroup request. +func (client AttestationsClient) ListForResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/attestations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForResourceGroupSender sends the ListForResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListForResourceGroupResponder handles the response to the ListForResourceGroup request. The method always +// closes the http.Response Body. +func (client AttestationsClient) ListForResourceGroupResponder(resp *http.Response) (result AttestationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForResourceGroupNextResults retrieves the next set of results, if any. +func (client AttestationsClient) listForResourceGroupNextResults(ctx context.Context, lastResults AttestationListResult) (result AttestationListResult, err error) { + req, err := lastResults.attestationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client AttestationsClient) ListForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result AttestationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.ListForResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForResourceGroup(ctx, subscriptionID, resourceGroupName, top, filter) + return +} + +// ListForSubscription gets all attestations for the subscription. +// Parameters: +// subscriptionID - the ID of the target subscription. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client AttestationsClient) ListForSubscription(ctx context.Context, subscriptionID string, top *int32, filter string) (result AttestationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.ListForSubscription") + defer func() { + sc := -1 + if result.alr.Response.Response != nil { + sc = result.alr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.AttestationsClient", "ListForSubscription", err.Error()) + } + + result.fn = client.listForSubscriptionNextResults + req, err := client.ListForSubscriptionPreparer(ctx, subscriptionID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListForSubscriptionSender(req) + if err != nil { + result.alr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForSubscription", resp, "Failure sending request") + return + } + + result.alr, err = client.ListForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "ListForSubscription", resp, "Failure responding to request") + return + } + if result.alr.hasNextLink() && result.alr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForSubscriptionPreparer prepares the ListForSubscription request. +func (client AttestationsClient) ListForSubscriptionPreparer(ctx context.Context, subscriptionID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2021-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/attestations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForSubscriptionSender sends the ListForSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client AttestationsClient) ListForSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListForSubscriptionResponder handles the response to the ListForSubscription request. The method always +// closes the http.Response Body. +func (client AttestationsClient) ListForSubscriptionResponder(resp *http.Response) (result AttestationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForSubscriptionNextResults retrieves the next set of results, if any. +func (client AttestationsClient) listForSubscriptionNextResults(ctx context.Context, lastResults AttestationListResult) (result AttestationListResult, err error) { + req, err := lastResults.attestationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForSubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForSubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.AttestationsClient", "listForSubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client AttestationsClient) ListForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, filter string) (result AttestationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationsClient.ListForSubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForSubscription(ctx, subscriptionID, top, filter) + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/client.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/client.go new file mode 100644 index 000000000000..8c182816b30f --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/client.go @@ -0,0 +1,52 @@ +// Package policyinsights implements the Azure ARM Policyinsights service API version . +// +// +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Policyinsights + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Policyinsights. +type BaseClient struct { + autorest.Client + BaseURI string + SubscriptionID2 string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID2 string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with +// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewWithBaseURI(baseURI string, subscriptionID2 string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID2: subscriptionID2, + } +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/enums.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/enums.go new file mode 100644 index 000000000000..70f304d802d7 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/enums.go @@ -0,0 +1,102 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// ComplianceState enumerates the values for compliance state. +type ComplianceState string + +const ( + // Compliant The resource is in compliance with the policy. + Compliant ComplianceState = "Compliant" + // NonCompliant The resource is not in compliance with the policy. + NonCompliant ComplianceState = "NonCompliant" + // Unknown The compliance state of the resource is not known. + Unknown ComplianceState = "Unknown" +) + +// PossibleComplianceStateValues returns an array of possible values for the ComplianceState const type. +func PossibleComplianceStateValues() []ComplianceState { + return []ComplianceState{Compliant, NonCompliant, Unknown} +} + +// CreatedByType enumerates the values for created by type. +type CreatedByType string + +const ( + // Application ... + Application CreatedByType = "Application" + // Key ... + Key CreatedByType = "Key" + // ManagedIdentity ... + ManagedIdentity CreatedByType = "ManagedIdentity" + // User ... + User CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns an array of possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{Application, Key, ManagedIdentity, User} +} + +// FieldRestrictionResult enumerates the values for field restriction result. +type FieldRestrictionResult string + +const ( + // Deny The field and/or values will be denied by policy. + Deny FieldRestrictionResult = "Deny" + // Removed The field will be removed by policy. + Removed FieldRestrictionResult = "Removed" + // Required The field and/or values are required by policy. + Required FieldRestrictionResult = "Required" +) + +// PossibleFieldRestrictionResultValues returns an array of possible values for the FieldRestrictionResult const type. +func PossibleFieldRestrictionResultValues() []FieldRestrictionResult { + return []FieldRestrictionResult{Deny, Removed, Required} +} + +// PolicyStatesResource enumerates the values for policy states resource. +type PolicyStatesResource string + +const ( + // Default ... + Default PolicyStatesResource = "default" + // Latest ... + Latest PolicyStatesResource = "latest" +) + +// PossiblePolicyStatesResourceValues returns an array of possible values for the PolicyStatesResource const type. +func PossiblePolicyStatesResourceValues() []PolicyStatesResource { + return []PolicyStatesResource{Default, Latest} +} + +// ResourceDiscoveryMode enumerates the values for resource discovery mode. +type ResourceDiscoveryMode string + +const ( + // ExistingNonCompliant Remediate resources that are already known to be non-compliant. + ExistingNonCompliant ResourceDiscoveryMode = "ExistingNonCompliant" + // ReEvaluateCompliance Re-evaluate the compliance state of resources and then remediate the resources + // found to be non-compliant. + ReEvaluateCompliance ResourceDiscoveryMode = "ReEvaluateCompliance" +) + +// PossibleResourceDiscoveryModeValues returns an array of possible values for the ResourceDiscoveryMode const type. +func PossibleResourceDiscoveryModeValues() []ResourceDiscoveryMode { + return []ResourceDiscoveryMode{ExistingNonCompliant, ReEvaluateCompliance} +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/models.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/models.go new file mode 100644 index 000000000000..6a28d54c0035 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/models.go @@ -0,0 +1,3331 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights" + +// Attestation an attestation resource. +type Attestation struct { + autorest.Response `json:"-"` + // AttestationProperties - Properties for the attestation. + *AttestationProperties `json:"properties,omitempty"` + // SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData `json:"systemData,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for Attestation. +func (a Attestation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if a.AttestationProperties != nil { + objectMap["properties"] = a.AttestationProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Attestation struct. +func (a *Attestation) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var attestationProperties AttestationProperties + err = json.Unmarshal(*v, &attestationProperties) + if err != nil { + return err + } + a.AttestationProperties = &attestationProperties + } + case "systemData": + if v != nil { + var systemData SystemData + err = json.Unmarshal(*v, &systemData) + if err != nil { + return err + } + a.SystemData = &systemData + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + a.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + a.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + a.Type = &typeVar + } + } + } + + return nil +} + +// AttestationEvidence a piece of evidence supporting the compliance state set in the attestation. +type AttestationEvidence struct { + // Description - The description for this piece of evidence. + Description *string `json:"description,omitempty"` + // SourceURI - The URI location of the evidence. + SourceURI *string `json:"sourceUri,omitempty"` +} + +// AttestationListResult list of attestations. +type AttestationListResult struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Array of attestation definitions. + Value *[]Attestation `json:"value,omitempty"` + // NextLink - READ-ONLY; The URL to get the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// AttestationListResultIterator provides access to a complete listing of Attestation values. +type AttestationListResultIterator struct { + i int + page AttestationListResultPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *AttestationListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationListResultIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *AttestationListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter AttestationListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter AttestationListResultIterator) Response() AttestationListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter AttestationListResultIterator) Value() Attestation { + if !iter.page.NotDone() { + return Attestation{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the AttestationListResultIterator type. +func NewAttestationListResultIterator(page AttestationListResultPage) AttestationListResultIterator { + return AttestationListResultIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (alr AttestationListResult) IsEmpty() bool { + return alr.Value == nil || len(*alr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (alr AttestationListResult) hasNextLink() bool { + return alr.NextLink != nil && len(*alr.NextLink) != 0 +} + +// attestationListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (alr AttestationListResult) attestationListResultPreparer(ctx context.Context) (*http.Request, error) { + if !alr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(alr.NextLink))) +} + +// AttestationListResultPage contains a page of Attestation values. +type AttestationListResultPage struct { + fn func(context.Context, AttestationListResult) (AttestationListResult, error) + alr AttestationListResult +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *AttestationListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AttestationListResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.alr) + if err != nil { + return err + } + page.alr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *AttestationListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page AttestationListResultPage) NotDone() bool { + return !page.alr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page AttestationListResultPage) Response() AttestationListResult { + return page.alr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page AttestationListResultPage) Values() []Attestation { + if page.alr.IsEmpty() { + return nil + } + return *page.alr.Value +} + +// Creates a new instance of the AttestationListResultPage type. +func NewAttestationListResultPage(cur AttestationListResult, getNextPage func(context.Context, AttestationListResult) (AttestationListResult, error)) AttestationListResultPage { + return AttestationListResultPage{ + fn: getNextPage, + alr: cur, + } +} + +// AttestationProperties the properties of an attestation resource. +type AttestationProperties struct { + // PolicyAssignmentID - The resource ID of the policy assignment that the attestation is setting the state for. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` + // PolicyDefinitionReferenceID - The policy definition reference ID from a policy set definition that the attestation is setting the state for. If the policy assignment assigns a policy set definition the attestation can choose a definition within the set definition with this property or omit this and set the state for the entire set definition. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` + // ComplianceState - The compliance state that should be set on the resource. Possible values include: 'Compliant', 'NonCompliant', 'Unknown' + ComplianceState ComplianceState `json:"complianceState,omitempty"` + // ExpiresOn - The time the compliance state should expire. + ExpiresOn *date.Time `json:"expiresOn,omitempty"` + // Owner - The person responsible for setting the state of the resource. This value is typically an Azure Active Directory object ID. + Owner *string `json:"owner,omitempty"` + // Comments - Comments describing why this attestation was created. + Comments *string `json:"comments,omitempty"` + // Evidence - The evidence supporting the compliance state set in this attestation. + Evidence *[]AttestationEvidence `json:"evidence,omitempty"` + // ProvisioningState - READ-ONLY; The status of the attestation. + ProvisioningState *string `json:"provisioningState,omitempty"` + // LastComplianceStateChangeAt - READ-ONLY; The time the compliance state was last changed in this attestation. + LastComplianceStateChangeAt *date.Time `json:"lastComplianceStateChangeAt,omitempty"` +} + +// MarshalJSON is the custom marshaler for AttestationProperties. +func (ap AttestationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ap.PolicyAssignmentID != nil { + objectMap["policyAssignmentId"] = ap.PolicyAssignmentID + } + if ap.PolicyDefinitionReferenceID != nil { + objectMap["policyDefinitionReferenceId"] = ap.PolicyDefinitionReferenceID + } + if ap.ComplianceState != "" { + objectMap["complianceState"] = ap.ComplianceState + } + if ap.ExpiresOn != nil { + objectMap["expiresOn"] = ap.ExpiresOn + } + if ap.Owner != nil { + objectMap["owner"] = ap.Owner + } + if ap.Comments != nil { + objectMap["comments"] = ap.Comments + } + if ap.Evidence != nil { + objectMap["evidence"] = ap.Evidence + } + return json.Marshal(objectMap) +} + +// AttestationsCreateOrUpdateAtResourceFuture an abstraction for monitoring and retrieving the results of a +// long-running operation. +type AttestationsCreateOrUpdateAtResourceFuture struct { + azure.FutureAPI + // Result returns the result of the asynchronous operation. + // If the operation has not completed it will return an error. + Result func(AttestationsClient) (Attestation, error) +} + +// AttestationsCreateOrUpdateAtResourceGroupFuture an abstraction for monitoring and retrieving the results +// of a long-running operation. +type AttestationsCreateOrUpdateAtResourceGroupFuture struct { + azure.FutureAPI + // Result returns the result of the asynchronous operation. + // If the operation has not completed it will return an error. + Result func(AttestationsClient) (Attestation, error) +} + +// AttestationsCreateOrUpdateAtSubscriptionFuture an abstraction for monitoring and retrieving the results +// of a long-running operation. +type AttestationsCreateOrUpdateAtSubscriptionFuture struct { + azure.FutureAPI + // Result returns the result of the asynchronous operation. + // If the operation has not completed it will return an error. + Result func(AttestationsClient) (Attestation, error) +} + +// AzureEntityResource the resource model definition for an Azure Resource Manager resource with an etag. +type AzureEntityResource struct { + // Etag - READ-ONLY; Resource Etag. + Etag *string `json:"etag,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// CheckRestrictionsRequest the check policy restrictions parameters describing the resource that is being +// evaluated. +type CheckRestrictionsRequest struct { + // ResourceDetails - The information about the resource that will be evaluated. + ResourceDetails *CheckRestrictionsResourceDetails `json:"resourceDetails,omitempty"` + // PendingFields - The list of fields and values that should be evaluated for potential restrictions. + PendingFields *[]PendingField `json:"pendingFields,omitempty"` +} + +// CheckRestrictionsResourceDetails the information about the resource that will be evaluated. +type CheckRestrictionsResourceDetails struct { + // ResourceContent - The resource content. This should include whatever properties are already known and can be a partial set of all resource properties. + ResourceContent interface{} `json:"resourceContent,omitempty"` + // APIVersion - The api-version of the resource content. + APIVersion *string `json:"apiVersion,omitempty"` + // Scope - The scope where the resource is being created. For example, if the resource is a child resource this would be the parent resource's resource ID. + Scope *string `json:"scope,omitempty"` +} + +// CheckRestrictionsResult the result of a check policy restrictions evaluation on a resource. +type CheckRestrictionsResult struct { + autorest.Response `json:"-"` + // FieldRestrictions - READ-ONLY; The restrictions that will be placed on various fields in the resource by policy. + FieldRestrictions *[]FieldRestrictions `json:"fieldRestrictions,omitempty"` + // ContentEvaluationResult - READ-ONLY; Evaluation results for the provided partial resource content. + ContentEvaluationResult *CheckRestrictionsResultContentEvaluationResult `json:"contentEvaluationResult,omitempty"` +} + +// CheckRestrictionsResultContentEvaluationResult evaluation results for the provided partial resource +// content. +type CheckRestrictionsResultContentEvaluationResult struct { + // PolicyEvaluations - Policy evaluation results against the given resource content. This will indicate if the partial content that was provided will be denied as-is. + PolicyEvaluations *[]PolicyEvaluationResult `json:"policyEvaluations,omitempty"` +} + +// ComplianceDetail the compliance state rollup. +type ComplianceDetail struct { + // ComplianceState - The compliance state. + ComplianceState *string `json:"complianceState,omitempty"` + // Count - Summarized count value for this compliance state. + Count *int32 `json:"count,omitempty"` +} + +// ComponentEventDetails component event details. +type ComponentEventDetails struct { + // AdditionalProperties - Unmatched properties from the message are deserialized this collection + AdditionalProperties map[string]interface{} `json:""` + // ID - Component Id. + ID *string `json:"id,omitempty"` + // Type - Component type. + Type *string `json:"type,omitempty"` + // Name - Component name. + Name *string `json:"name,omitempty"` + // Timestamp - Timestamp for component policy event record. + Timestamp *date.Time `json:"timestamp,omitempty"` + // TenantID - Tenant ID for the policy event record. + TenantID *string `json:"tenantId,omitempty"` + // PrincipalOid - Principal object ID for the user who initiated the resource component operation that triggered the policy event. + PrincipalOid *string `json:"principalOid,omitempty"` + // PolicyDefinitionAction - Policy definition action, i.e. effect. + PolicyDefinitionAction *string `json:"policyDefinitionAction,omitempty"` +} + +// MarshalJSON is the custom marshaler for ComponentEventDetails. +func (ced ComponentEventDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ced.ID != nil { + objectMap["id"] = ced.ID + } + if ced.Type != nil { + objectMap["type"] = ced.Type + } + if ced.Name != nil { + objectMap["name"] = ced.Name + } + if ced.Timestamp != nil { + objectMap["timestamp"] = ced.Timestamp + } + if ced.TenantID != nil { + objectMap["tenantId"] = ced.TenantID + } + if ced.PrincipalOid != nil { + objectMap["principalOid"] = ced.PrincipalOid + } + if ced.PolicyDefinitionAction != nil { + objectMap["policyDefinitionAction"] = ced.PolicyDefinitionAction + } + for k, v := range ced.AdditionalProperties { + objectMap[k] = v + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ComponentEventDetails struct. +func (ced *ComponentEventDetails) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + default: + if v != nil { + var additionalProperties interface{} + err = json.Unmarshal(*v, &additionalProperties) + if err != nil { + return err + } + if ced.AdditionalProperties == nil { + ced.AdditionalProperties = make(map[string]interface{}) + } + ced.AdditionalProperties[k] = additionalProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ced.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ced.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + ced.Name = &name + } + case "timestamp": + if v != nil { + var timestamp date.Time + err = json.Unmarshal(*v, ×tamp) + if err != nil { + return err + } + ced.Timestamp = ×tamp + } + case "tenantId": + if v != nil { + var tenantID string + err = json.Unmarshal(*v, &tenantID) + if err != nil { + return err + } + ced.TenantID = &tenantID + } + case "principalOid": + if v != nil { + var principalOid string + err = json.Unmarshal(*v, &principalOid) + if err != nil { + return err + } + ced.PrincipalOid = &principalOid + } + case "policyDefinitionAction": + if v != nil { + var policyDefinitionAction string + err = json.Unmarshal(*v, &policyDefinitionAction) + if err != nil { + return err + } + ced.PolicyDefinitionAction = &policyDefinitionAction + } + } + } + + return nil +} + +// ComponentStateDetails component state details. +type ComponentStateDetails struct { + // AdditionalProperties - Unmatched properties from the message are deserialized this collection + AdditionalProperties map[string]interface{} `json:""` + // ID - Component Id. + ID *string `json:"id,omitempty"` + // Type - Component type. + Type *string `json:"type,omitempty"` + // Name - Component name. + Name *string `json:"name,omitempty"` + // Timestamp - Component compliance evaluation timestamp. + Timestamp *date.Time `json:"timestamp,omitempty"` + // ComplianceState - Component compliance state. + ComplianceState *string `json:"complianceState,omitempty"` +} + +// MarshalJSON is the custom marshaler for ComponentStateDetails. +func (csd ComponentStateDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if csd.ID != nil { + objectMap["id"] = csd.ID + } + if csd.Type != nil { + objectMap["type"] = csd.Type + } + if csd.Name != nil { + objectMap["name"] = csd.Name + } + if csd.Timestamp != nil { + objectMap["timestamp"] = csd.Timestamp + } + if csd.ComplianceState != nil { + objectMap["complianceState"] = csd.ComplianceState + } + for k, v := range csd.AdditionalProperties { + objectMap[k] = v + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ComponentStateDetails struct. +func (csd *ComponentStateDetails) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + default: + if v != nil { + var additionalProperties interface{} + err = json.Unmarshal(*v, &additionalProperties) + if err != nil { + return err + } + if csd.AdditionalProperties == nil { + csd.AdditionalProperties = make(map[string]interface{}) + } + csd.AdditionalProperties[k] = additionalProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + csd.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + csd.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + csd.Name = &name + } + case "timestamp": + if v != nil { + var timestamp date.Time + err = json.Unmarshal(*v, ×tamp) + if err != nil { + return err + } + csd.Timestamp = ×tamp + } + case "complianceState": + if v != nil { + var complianceState string + err = json.Unmarshal(*v, &complianceState) + if err != nil { + return err + } + csd.ComplianceState = &complianceState + } + } + } + + return nil +} + +// ErrorDefinition error definition. +type ErrorDefinition struct { + // Code - READ-ONLY; Service specific error code which serves as the substatus for the HTTP error code. + Code *string `json:"code,omitempty"` + // Message - READ-ONLY; Description of the error. + Message *string `json:"message,omitempty"` + // Target - READ-ONLY; The target of the error. + Target *string `json:"target,omitempty"` + // Details - READ-ONLY; Internal error details. + Details *[]ErrorDefinition `json:"details,omitempty"` + // AdditionalInfo - READ-ONLY; Additional scenario specific error details. + AdditionalInfo *[]TypedErrorInfo `json:"additionalInfo,omitempty"` +} + +// ErrorResponse error response. +type ErrorResponse struct { + // Error - The error details. + Error *ErrorDefinition `json:"error,omitempty"` +} + +// ExpressionEvaluationDetails evaluation details of policy language expressions. +type ExpressionEvaluationDetails struct { + // Result - Evaluation result. + Result *string `json:"result,omitempty"` + // Expression - Expression evaluated. + Expression *string `json:"expression,omitempty"` + // ExpressionKind - READ-ONLY; The kind of expression that was evaluated. + ExpressionKind *string `json:"expressionKind,omitempty"` + // Path - Property path if the expression is a field or an alias. + Path *string `json:"path,omitempty"` + // ExpressionValue - Value of the expression. + ExpressionValue interface{} `json:"expressionValue,omitempty"` + // TargetValue - Target value to be compared with the expression value. + TargetValue interface{} `json:"targetValue,omitempty"` + // Operator - Operator to compare the expression value and the target value. + Operator *string `json:"operator,omitempty"` +} + +// MarshalJSON is the custom marshaler for ExpressionEvaluationDetails. +func (eed ExpressionEvaluationDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if eed.Result != nil { + objectMap["result"] = eed.Result + } + if eed.Expression != nil { + objectMap["expression"] = eed.Expression + } + if eed.Path != nil { + objectMap["path"] = eed.Path + } + if eed.ExpressionValue != nil { + objectMap["expressionValue"] = eed.ExpressionValue + } + if eed.TargetValue != nil { + objectMap["targetValue"] = eed.TargetValue + } + if eed.Operator != nil { + objectMap["operator"] = eed.Operator + } + return json.Marshal(objectMap) +} + +// FieldRestriction the restrictions on a field imposed by a specific policy. +type FieldRestriction struct { + // Result - READ-ONLY; The type of restriction that is imposed on the field. Possible values include: 'Required', 'Removed', 'Deny' + Result FieldRestrictionResult `json:"result,omitempty"` + // DefaultValue - READ-ONLY; The value that policy will set for the field if the user does not provide a value. + DefaultValue *string `json:"defaultValue,omitempty"` + // Values - READ-ONLY; The values that policy either requires or denies for the field. + Values *[]string `json:"values,omitempty"` + // Policy - READ-ONLY; The details of the policy that is causing the field restriction. + Policy *PolicyReference `json:"policy,omitempty"` +} + +// FieldRestrictions the restrictions that will be placed on a field in the resource by policy. +type FieldRestrictions struct { + // Field - READ-ONLY; The name of the field. This can be a top-level property like 'name' or 'type' or an Azure Policy field alias. + Field *string `json:"field,omitempty"` + // Restrictions - The restrictions placed on that field by policy. + Restrictions *[]FieldRestriction `json:"restrictions,omitempty"` +} + +// MarshalJSON is the custom marshaler for FieldRestrictions. +func (fr FieldRestrictions) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if fr.Restrictions != nil { + objectMap["restrictions"] = fr.Restrictions + } + return json.Marshal(objectMap) +} + +// IfNotExistsEvaluationDetails evaluation details of IfNotExists effect. +type IfNotExistsEvaluationDetails struct { + // ResourceID - ID of the last evaluated resource for IfNotExists effect. + ResourceID *string `json:"resourceId,omitempty"` + // TotalResources - Total number of resources to which the existence condition is applicable. + TotalResources *int32 `json:"totalResources,omitempty"` +} + +// Operation operation definition. +type Operation struct { + // Name - Operation name. + Name *string `json:"name,omitempty"` + // Display - Display metadata associated with the operation. + Display *OperationDisplay `json:"display,omitempty"` +} + +// OperationDisplay display metadata associated with the operation. +type OperationDisplay struct { + // Provider - Resource provider name. + Provider *string `json:"provider,omitempty"` + // Resource - Resource name on which the operation is performed. + Resource *string `json:"resource,omitempty"` + // Operation - Operation name. + Operation *string `json:"operation,omitempty"` + // Description - Operation description. + Description *string `json:"description,omitempty"` +} + +// OperationsListResults list of available operations. +type OperationsListResults struct { + autorest.Response `json:"-"` + // OdataCount - OData entity count; represents the number of operations returned. + OdataCount *int32 `json:"@odata.count,omitempty"` + // Value - List of available operations. + Value *[]Operation `json:"value,omitempty"` +} + +// PendingField a field that should be evaluated against Azure Policy to determine restrictions. +type PendingField struct { + // Field - The name of the field. This can be a top-level property like 'name' or 'type' or an Azure Policy field alias. + Field *string `json:"field,omitempty"` + // Values - The list of potential values for the field that should be evaluated against Azure Policy. + Values *[]string `json:"values,omitempty"` +} + +// PolicyAssignmentSummary policy assignment summary. +type PolicyAssignmentSummary struct { + // PolicyAssignmentID - Policy assignment ID. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` + // PolicySetDefinitionID - Policy set definition ID, if the policy assignment is for a policy set. + PolicySetDefinitionID *string `json:"policySetDefinitionId,omitempty"` + // Results - Compliance summary for the policy assignment. + Results *SummaryResults `json:"results,omitempty"` + // PolicyDefinitions - Policy definitions summary. + PolicyDefinitions *[]PolicyDefinitionSummary `json:"policyDefinitions,omitempty"` + // PolicyGroups - Policy definition group summary. + PolicyGroups *[]PolicyGroupSummary `json:"policyGroups,omitempty"` +} + +// PolicyDefinitionSummary policy definition summary. +type PolicyDefinitionSummary struct { + // PolicyDefinitionID - Policy definition ID. + PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"` + // PolicyDefinitionReferenceID - Policy definition reference ID. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` + // PolicyDefinitionGroupNames - Policy definition group names. + PolicyDefinitionGroupNames *[]string `json:"policyDefinitionGroupNames,omitempty"` + // Effect - Policy effect, i.e. policy definition action. + Effect *string `json:"effect,omitempty"` + // Results - Compliance summary for the policy definition. + Results *SummaryResults `json:"results,omitempty"` +} + +// PolicyDetails the policy details. +type PolicyDetails struct { + // PolicyDefinitionID - READ-ONLY; The ID of the policy definition. + PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"` + // PolicyAssignmentID - READ-ONLY; The ID of the policy assignment. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` + // PolicyAssignmentDisplayName - READ-ONLY; The display name of the policy assignment. + PolicyAssignmentDisplayName *string `json:"policyAssignmentDisplayName,omitempty"` + // PolicyAssignmentScope - READ-ONLY; The scope of the policy assignment. + PolicyAssignmentScope *string `json:"policyAssignmentScope,omitempty"` + // PolicySetDefinitionID - READ-ONLY; The ID of the policy set definition. + PolicySetDefinitionID *string `json:"policySetDefinitionId,omitempty"` + // PolicyDefinitionReferenceID - READ-ONLY; The policy definition reference ID within the policy set definition. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` +} + +// PolicyEvaluationDetails policy evaluation details. +type PolicyEvaluationDetails struct { + // EvaluatedExpressions - Details of the evaluated expressions. + EvaluatedExpressions *[]ExpressionEvaluationDetails `json:"evaluatedExpressions,omitempty"` + // IfNotExistsDetails - Evaluation details of IfNotExists effect. + IfNotExistsDetails *IfNotExistsEvaluationDetails `json:"ifNotExistsDetails,omitempty"` +} + +// PolicyEvaluationResult the result of a non-compliant policy evaluation against the given resource +// content. +type PolicyEvaluationResult struct { + // PolicyInfo - READ-ONLY; The details of the policy that was evaluated. + PolicyInfo *PolicyReference `json:"policyInfo,omitempty"` + // EvaluationResult - READ-ONLY; The result of the policy evaluation against the resource. This will typically be 'NonCompliant' but may contain other values if errors were encountered. + EvaluationResult *string `json:"evaluationResult,omitempty"` + // EvaluationDetails - READ-ONLY; The detailed results of the policy expressions and values that were evaluated. + EvaluationDetails *PolicyEvaluationDetails `json:"evaluationDetails,omitempty"` +} + +// PolicyEvent policy event record. +type PolicyEvent struct { + // AdditionalProperties - Unmatched properties from the message are deserialized this collection + AdditionalProperties map[string]interface{} `json:""` + // OdataID - OData entity ID; always set to null since policy event records do not have an entity ID. + OdataID *string `json:"@odata.id,omitempty"` + // OdataContext - OData context string; used by OData clients to resolve type information based on metadata. + OdataContext *string `json:"@odata.context,omitempty"` + // Timestamp - Timestamp for the policy event record. + Timestamp *date.Time `json:"timestamp,omitempty"` + // ResourceID - Resource ID. + ResourceID *string `json:"resourceId,omitempty"` + // PolicyAssignmentID - Policy assignment ID. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` + // PolicyDefinitionID - Policy definition ID. + PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"` + // EffectiveParameters - Effective parameters for the policy assignment. + EffectiveParameters *string `json:"effectiveParameters,omitempty"` + // IsCompliant - Flag which states whether the resource is compliant against the policy assignment it was evaluated against. + IsCompliant *bool `json:"isCompliant,omitempty"` + // SubscriptionID - Subscription ID. + SubscriptionID *string `json:"subscriptionId,omitempty"` + // ResourceType - Resource type. + ResourceType *string `json:"resourceType,omitempty"` + // ResourceLocation - Resource location. + ResourceLocation *string `json:"resourceLocation,omitempty"` + // ResourceGroup - Resource group name. + ResourceGroup *string `json:"resourceGroup,omitempty"` + // ResourceTags - List of resource tags. + ResourceTags *string `json:"resourceTags,omitempty"` + // PolicyAssignmentName - Policy assignment name. + PolicyAssignmentName *string `json:"policyAssignmentName,omitempty"` + // PolicyAssignmentOwner - Policy assignment owner. + PolicyAssignmentOwner *string `json:"policyAssignmentOwner,omitempty"` + // PolicyAssignmentParameters - Policy assignment parameters. + PolicyAssignmentParameters *string `json:"policyAssignmentParameters,omitempty"` + // PolicyAssignmentScope - Policy assignment scope. + PolicyAssignmentScope *string `json:"policyAssignmentScope,omitempty"` + // PolicyDefinitionName - Policy definition name. + PolicyDefinitionName *string `json:"policyDefinitionName,omitempty"` + // PolicyDefinitionAction - Policy definition action, i.e. effect. + PolicyDefinitionAction *string `json:"policyDefinitionAction,omitempty"` + // PolicyDefinitionCategory - Policy definition category. + PolicyDefinitionCategory *string `json:"policyDefinitionCategory,omitempty"` + // PolicySetDefinitionID - Policy set definition ID, if the policy assignment is for a policy set. + PolicySetDefinitionID *string `json:"policySetDefinitionId,omitempty"` + // PolicySetDefinitionName - Policy set definition name, if the policy assignment is for a policy set. + PolicySetDefinitionName *string `json:"policySetDefinitionName,omitempty"` + // PolicySetDefinitionOwner - Policy set definition owner, if the policy assignment is for a policy set. + PolicySetDefinitionOwner *string `json:"policySetDefinitionOwner,omitempty"` + // PolicySetDefinitionCategory - Policy set definition category, if the policy assignment is for a policy set. + PolicySetDefinitionCategory *string `json:"policySetDefinitionCategory,omitempty"` + // PolicySetDefinitionParameters - Policy set definition parameters, if the policy assignment is for a policy set. + PolicySetDefinitionParameters *string `json:"policySetDefinitionParameters,omitempty"` + // ManagementGroupIds - Comma separated list of management group IDs, which represent the hierarchy of the management groups the resource is under. + ManagementGroupIds *string `json:"managementGroupIds,omitempty"` + // PolicyDefinitionReferenceID - Reference ID for the policy definition inside the policy set, if the policy assignment is for a policy set. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` + // ComplianceState - Compliance state of the resource. + ComplianceState *string `json:"complianceState,omitempty"` + // TenantID - Tenant ID for the policy event record. + TenantID *string `json:"tenantId,omitempty"` + // PrincipalOid - Principal object ID for the user who initiated the resource operation that triggered the policy event. + PrincipalOid *string `json:"principalOid,omitempty"` + // Components - Components events records populated only when URL contains $expand=components clause. + Components *[]ComponentEventDetails `json:"components,omitempty"` +} + +// MarshalJSON is the custom marshaler for PolicyEvent. +func (peVar PolicyEvent) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if peVar.OdataID != nil { + objectMap["@odata.id"] = peVar.OdataID + } + if peVar.OdataContext != nil { + objectMap["@odata.context"] = peVar.OdataContext + } + if peVar.Timestamp != nil { + objectMap["timestamp"] = peVar.Timestamp + } + if peVar.ResourceID != nil { + objectMap["resourceId"] = peVar.ResourceID + } + if peVar.PolicyAssignmentID != nil { + objectMap["policyAssignmentId"] = peVar.PolicyAssignmentID + } + if peVar.PolicyDefinitionID != nil { + objectMap["policyDefinitionId"] = peVar.PolicyDefinitionID + } + if peVar.EffectiveParameters != nil { + objectMap["effectiveParameters"] = peVar.EffectiveParameters + } + if peVar.IsCompliant != nil { + objectMap["isCompliant"] = peVar.IsCompliant + } + if peVar.SubscriptionID != nil { + objectMap["subscriptionId"] = peVar.SubscriptionID + } + if peVar.ResourceType != nil { + objectMap["resourceType"] = peVar.ResourceType + } + if peVar.ResourceLocation != nil { + objectMap["resourceLocation"] = peVar.ResourceLocation + } + if peVar.ResourceGroup != nil { + objectMap["resourceGroup"] = peVar.ResourceGroup + } + if peVar.ResourceTags != nil { + objectMap["resourceTags"] = peVar.ResourceTags + } + if peVar.PolicyAssignmentName != nil { + objectMap["policyAssignmentName"] = peVar.PolicyAssignmentName + } + if peVar.PolicyAssignmentOwner != nil { + objectMap["policyAssignmentOwner"] = peVar.PolicyAssignmentOwner + } + if peVar.PolicyAssignmentParameters != nil { + objectMap["policyAssignmentParameters"] = peVar.PolicyAssignmentParameters + } + if peVar.PolicyAssignmentScope != nil { + objectMap["policyAssignmentScope"] = peVar.PolicyAssignmentScope + } + if peVar.PolicyDefinitionName != nil { + objectMap["policyDefinitionName"] = peVar.PolicyDefinitionName + } + if peVar.PolicyDefinitionAction != nil { + objectMap["policyDefinitionAction"] = peVar.PolicyDefinitionAction + } + if peVar.PolicyDefinitionCategory != nil { + objectMap["policyDefinitionCategory"] = peVar.PolicyDefinitionCategory + } + if peVar.PolicySetDefinitionID != nil { + objectMap["policySetDefinitionId"] = peVar.PolicySetDefinitionID + } + if peVar.PolicySetDefinitionName != nil { + objectMap["policySetDefinitionName"] = peVar.PolicySetDefinitionName + } + if peVar.PolicySetDefinitionOwner != nil { + objectMap["policySetDefinitionOwner"] = peVar.PolicySetDefinitionOwner + } + if peVar.PolicySetDefinitionCategory != nil { + objectMap["policySetDefinitionCategory"] = peVar.PolicySetDefinitionCategory + } + if peVar.PolicySetDefinitionParameters != nil { + objectMap["policySetDefinitionParameters"] = peVar.PolicySetDefinitionParameters + } + if peVar.ManagementGroupIds != nil { + objectMap["managementGroupIds"] = peVar.ManagementGroupIds + } + if peVar.PolicyDefinitionReferenceID != nil { + objectMap["policyDefinitionReferenceId"] = peVar.PolicyDefinitionReferenceID + } + if peVar.ComplianceState != nil { + objectMap["complianceState"] = peVar.ComplianceState + } + if peVar.TenantID != nil { + objectMap["tenantId"] = peVar.TenantID + } + if peVar.PrincipalOid != nil { + objectMap["principalOid"] = peVar.PrincipalOid + } + if peVar.Components != nil { + objectMap["components"] = peVar.Components + } + for k, v := range peVar.AdditionalProperties { + objectMap[k] = v + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PolicyEvent struct. +func (peVar *PolicyEvent) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + default: + if v != nil { + var additionalProperties interface{} + err = json.Unmarshal(*v, &additionalProperties) + if err != nil { + return err + } + if peVar.AdditionalProperties == nil { + peVar.AdditionalProperties = make(map[string]interface{}) + } + peVar.AdditionalProperties[k] = additionalProperties + } + case "@odata.id": + if v != nil { + var odataID string + err = json.Unmarshal(*v, &odataID) + if err != nil { + return err + } + peVar.OdataID = &odataID + } + case "@odata.context": + if v != nil { + var odataContext string + err = json.Unmarshal(*v, &odataContext) + if err != nil { + return err + } + peVar.OdataContext = &odataContext + } + case "timestamp": + if v != nil { + var timestamp date.Time + err = json.Unmarshal(*v, ×tamp) + if err != nil { + return err + } + peVar.Timestamp = ×tamp + } + case "resourceId": + if v != nil { + var resourceID string + err = json.Unmarshal(*v, &resourceID) + if err != nil { + return err + } + peVar.ResourceID = &resourceID + } + case "policyAssignmentId": + if v != nil { + var policyAssignmentID string + err = json.Unmarshal(*v, &policyAssignmentID) + if err != nil { + return err + } + peVar.PolicyAssignmentID = &policyAssignmentID + } + case "policyDefinitionId": + if v != nil { + var policyDefinitionID string + err = json.Unmarshal(*v, &policyDefinitionID) + if err != nil { + return err + } + peVar.PolicyDefinitionID = &policyDefinitionID + } + case "effectiveParameters": + if v != nil { + var effectiveParameters string + err = json.Unmarshal(*v, &effectiveParameters) + if err != nil { + return err + } + peVar.EffectiveParameters = &effectiveParameters + } + case "isCompliant": + if v != nil { + var isCompliant bool + err = json.Unmarshal(*v, &isCompliant) + if err != nil { + return err + } + peVar.IsCompliant = &isCompliant + } + case "subscriptionId": + if v != nil { + var subscriptionID string + err = json.Unmarshal(*v, &subscriptionID) + if err != nil { + return err + } + peVar.SubscriptionID = &subscriptionID + } + case "resourceType": + if v != nil { + var resourceType string + err = json.Unmarshal(*v, &resourceType) + if err != nil { + return err + } + peVar.ResourceType = &resourceType + } + case "resourceLocation": + if v != nil { + var resourceLocation string + err = json.Unmarshal(*v, &resourceLocation) + if err != nil { + return err + } + peVar.ResourceLocation = &resourceLocation + } + case "resourceGroup": + if v != nil { + var resourceGroup string + err = json.Unmarshal(*v, &resourceGroup) + if err != nil { + return err + } + peVar.ResourceGroup = &resourceGroup + } + case "resourceTags": + if v != nil { + var resourceTags string + err = json.Unmarshal(*v, &resourceTags) + if err != nil { + return err + } + peVar.ResourceTags = &resourceTags + } + case "policyAssignmentName": + if v != nil { + var policyAssignmentName string + err = json.Unmarshal(*v, &policyAssignmentName) + if err != nil { + return err + } + peVar.PolicyAssignmentName = &policyAssignmentName + } + case "policyAssignmentOwner": + if v != nil { + var policyAssignmentOwner string + err = json.Unmarshal(*v, &policyAssignmentOwner) + if err != nil { + return err + } + peVar.PolicyAssignmentOwner = &policyAssignmentOwner + } + case "policyAssignmentParameters": + if v != nil { + var policyAssignmentParameters string + err = json.Unmarshal(*v, &policyAssignmentParameters) + if err != nil { + return err + } + peVar.PolicyAssignmentParameters = &policyAssignmentParameters + } + case "policyAssignmentScope": + if v != nil { + var policyAssignmentScope string + err = json.Unmarshal(*v, &policyAssignmentScope) + if err != nil { + return err + } + peVar.PolicyAssignmentScope = &policyAssignmentScope + } + case "policyDefinitionName": + if v != nil { + var policyDefinitionName string + err = json.Unmarshal(*v, &policyDefinitionName) + if err != nil { + return err + } + peVar.PolicyDefinitionName = &policyDefinitionName + } + case "policyDefinitionAction": + if v != nil { + var policyDefinitionAction string + err = json.Unmarshal(*v, &policyDefinitionAction) + if err != nil { + return err + } + peVar.PolicyDefinitionAction = &policyDefinitionAction + } + case "policyDefinitionCategory": + if v != nil { + var policyDefinitionCategory string + err = json.Unmarshal(*v, &policyDefinitionCategory) + if err != nil { + return err + } + peVar.PolicyDefinitionCategory = &policyDefinitionCategory + } + case "policySetDefinitionId": + if v != nil { + var policySetDefinitionID string + err = json.Unmarshal(*v, &policySetDefinitionID) + if err != nil { + return err + } + peVar.PolicySetDefinitionID = &policySetDefinitionID + } + case "policySetDefinitionName": + if v != nil { + var policySetDefinitionName string + err = json.Unmarshal(*v, &policySetDefinitionName) + if err != nil { + return err + } + peVar.PolicySetDefinitionName = &policySetDefinitionName + } + case "policySetDefinitionOwner": + if v != nil { + var policySetDefinitionOwner string + err = json.Unmarshal(*v, &policySetDefinitionOwner) + if err != nil { + return err + } + peVar.PolicySetDefinitionOwner = &policySetDefinitionOwner + } + case "policySetDefinitionCategory": + if v != nil { + var policySetDefinitionCategory string + err = json.Unmarshal(*v, &policySetDefinitionCategory) + if err != nil { + return err + } + peVar.PolicySetDefinitionCategory = &policySetDefinitionCategory + } + case "policySetDefinitionParameters": + if v != nil { + var policySetDefinitionParameters string + err = json.Unmarshal(*v, &policySetDefinitionParameters) + if err != nil { + return err + } + peVar.PolicySetDefinitionParameters = &policySetDefinitionParameters + } + case "managementGroupIds": + if v != nil { + var managementGroupIds string + err = json.Unmarshal(*v, &managementGroupIds) + if err != nil { + return err + } + peVar.ManagementGroupIds = &managementGroupIds + } + case "policyDefinitionReferenceId": + if v != nil { + var policyDefinitionReferenceID string + err = json.Unmarshal(*v, &policyDefinitionReferenceID) + if err != nil { + return err + } + peVar.PolicyDefinitionReferenceID = &policyDefinitionReferenceID + } + case "complianceState": + if v != nil { + var complianceState string + err = json.Unmarshal(*v, &complianceState) + if err != nil { + return err + } + peVar.ComplianceState = &complianceState + } + case "tenantId": + if v != nil { + var tenantID string + err = json.Unmarshal(*v, &tenantID) + if err != nil { + return err + } + peVar.TenantID = &tenantID + } + case "principalOid": + if v != nil { + var principalOid string + err = json.Unmarshal(*v, &principalOid) + if err != nil { + return err + } + peVar.PrincipalOid = &principalOid + } + case "components": + if v != nil { + var components []ComponentEventDetails + err = json.Unmarshal(*v, &components) + if err != nil { + return err + } + peVar.Components = &components + } + } + } + + return nil +} + +// PolicyEventsQueryResults query results. +type PolicyEventsQueryResults struct { + autorest.Response `json:"-"` + // OdataContext - OData context string; used by OData clients to resolve type information based on metadata. + OdataContext *string `json:"@odata.context,omitempty"` + // OdataCount - OData entity count; represents the number of policy event records returned. + OdataCount *int32 `json:"@odata.count,omitempty"` + // OdataNextLink - Odata next link; URL to get the next set of results. + OdataNextLink *string `json:"@odata.nextLink,omitempty"` + // Value - Query results. + Value *[]PolicyEvent `json:"value,omitempty"` +} + +// PolicyEventsQueryResultsIterator provides access to a complete listing of PolicyEvent values. +type PolicyEventsQueryResultsIterator struct { + i int + page PolicyEventsQueryResultsPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *PolicyEventsQueryResultsIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsQueryResultsIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *PolicyEventsQueryResultsIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter PolicyEventsQueryResultsIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter PolicyEventsQueryResultsIterator) Response() PolicyEventsQueryResults { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter PolicyEventsQueryResultsIterator) Value() PolicyEvent { + if !iter.page.NotDone() { + return PolicyEvent{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the PolicyEventsQueryResultsIterator type. +func NewPolicyEventsQueryResultsIterator(page PolicyEventsQueryResultsPage) PolicyEventsQueryResultsIterator { + return PolicyEventsQueryResultsIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (peqr PolicyEventsQueryResults) IsEmpty() bool { + return peqr.Value == nil || len(*peqr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (peqr PolicyEventsQueryResults) hasNextLink() bool { + return peqr.OdataNextLink != nil && len(*peqr.OdataNextLink) != 0 +} + +// policyEventsQueryResultsPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (peqr PolicyEventsQueryResults) policyEventsQueryResultsPreparer(ctx context.Context) (*http.Request, error) { + if !peqr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(peqr.OdataNextLink))) +} + +// PolicyEventsQueryResultsPage contains a page of PolicyEvent values. +type PolicyEventsQueryResultsPage struct { + fn func(context.Context, PolicyEventsQueryResults) (PolicyEventsQueryResults, error) + peqr PolicyEventsQueryResults +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *PolicyEventsQueryResultsPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsQueryResultsPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.peqr) + if err != nil { + return err + } + page.peqr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *PolicyEventsQueryResultsPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page PolicyEventsQueryResultsPage) NotDone() bool { + return !page.peqr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page PolicyEventsQueryResultsPage) Response() PolicyEventsQueryResults { + return page.peqr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page PolicyEventsQueryResultsPage) Values() []PolicyEvent { + if page.peqr.IsEmpty() { + return nil + } + return *page.peqr.Value +} + +// Creates a new instance of the PolicyEventsQueryResultsPage type. +func NewPolicyEventsQueryResultsPage(cur PolicyEventsQueryResults, getNextPage func(context.Context, PolicyEventsQueryResults) (PolicyEventsQueryResults, error)) PolicyEventsQueryResultsPage { + return PolicyEventsQueryResultsPage{ + fn: getNextPage, + peqr: cur, + } +} + +// PolicyGroupSummary policy definition group summary. +type PolicyGroupSummary struct { + // PolicyGroupName - Policy group name. + PolicyGroupName *string `json:"policyGroupName,omitempty"` + // Results - Compliance summary for the policy definition group. + Results *SummaryResults `json:"results,omitempty"` +} + +// PolicyMetadata policy metadata resource definition. +type PolicyMetadata struct { + autorest.Response `json:"-"` + // PolicyMetadataProperties - Properties of the policy metadata. + *PolicyMetadataProperties `json:"properties,omitempty"` + // ID - READ-ONLY; The ID of the policy metadata. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; The type of the policy metadata. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; The name of the policy metadata. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for PolicyMetadata. +func (pm PolicyMetadata) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if pm.PolicyMetadataProperties != nil { + objectMap["properties"] = pm.PolicyMetadataProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PolicyMetadata struct. +func (pm *PolicyMetadata) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var policyMetadataProperties PolicyMetadataProperties + err = json.Unmarshal(*v, &policyMetadataProperties) + if err != nil { + return err + } + pm.PolicyMetadataProperties = &policyMetadataProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + pm.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + pm.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + pm.Name = &name + } + } + } + + return nil +} + +// PolicyMetadataCollection collection of policy metadata resources. +type PolicyMetadataCollection struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Array of policy metadata definitions. + Value *[]SlimPolicyMetadata `json:"value,omitempty"` + // NextLink - READ-ONLY; The URL to get the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// PolicyMetadataCollectionIterator provides access to a complete listing of SlimPolicyMetadata values. +type PolicyMetadataCollectionIterator struct { + i int + page PolicyMetadataCollectionPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *PolicyMetadataCollectionIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyMetadataCollectionIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *PolicyMetadataCollectionIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter PolicyMetadataCollectionIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter PolicyMetadataCollectionIterator) Response() PolicyMetadataCollection { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter PolicyMetadataCollectionIterator) Value() SlimPolicyMetadata { + if !iter.page.NotDone() { + return SlimPolicyMetadata{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the PolicyMetadataCollectionIterator type. +func NewPolicyMetadataCollectionIterator(page PolicyMetadataCollectionPage) PolicyMetadataCollectionIterator { + return PolicyMetadataCollectionIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (pmc PolicyMetadataCollection) IsEmpty() bool { + return pmc.Value == nil || len(*pmc.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (pmc PolicyMetadataCollection) hasNextLink() bool { + return pmc.NextLink != nil && len(*pmc.NextLink) != 0 +} + +// policyMetadataCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (pmc PolicyMetadataCollection) policyMetadataCollectionPreparer(ctx context.Context) (*http.Request, error) { + if !pmc.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(pmc.NextLink))) +} + +// PolicyMetadataCollectionPage contains a page of SlimPolicyMetadata values. +type PolicyMetadataCollectionPage struct { + fn func(context.Context, PolicyMetadataCollection) (PolicyMetadataCollection, error) + pmc PolicyMetadataCollection +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *PolicyMetadataCollectionPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyMetadataCollectionPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.pmc) + if err != nil { + return err + } + page.pmc = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *PolicyMetadataCollectionPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page PolicyMetadataCollectionPage) NotDone() bool { + return !page.pmc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page PolicyMetadataCollectionPage) Response() PolicyMetadataCollection { + return page.pmc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page PolicyMetadataCollectionPage) Values() []SlimPolicyMetadata { + if page.pmc.IsEmpty() { + return nil + } + return *page.pmc.Value +} + +// Creates a new instance of the PolicyMetadataCollectionPage type. +func NewPolicyMetadataCollectionPage(cur PolicyMetadataCollection, getNextPage func(context.Context, PolicyMetadataCollection) (PolicyMetadataCollection, error)) PolicyMetadataCollectionPage { + return PolicyMetadataCollectionPage{ + fn: getNextPage, + pmc: cur, + } +} + +// PolicyMetadataProperties the properties of the policy metadata. +type PolicyMetadataProperties struct { + // Description - READ-ONLY; The description of the policy metadata. + Description *string `json:"description,omitempty"` + // Requirements - READ-ONLY; The requirements of the policy metadata. + Requirements *string `json:"requirements,omitempty"` + // MetadataID - READ-ONLY; The policy metadata identifier. + MetadataID *string `json:"metadataId,omitempty"` + // Category - READ-ONLY; The category of the policy metadata. + Category *string `json:"category,omitempty"` + // Title - READ-ONLY; The title of the policy metadata. + Title *string `json:"title,omitempty"` + // Owner - READ-ONLY; The owner of the policy metadata. + Owner *string `json:"owner,omitempty"` + // AdditionalContentURL - READ-ONLY; Url for getting additional content about the resource metadata. + AdditionalContentURL *string `json:"additionalContentUrl,omitempty"` + // Metadata - READ-ONLY; Additional metadata. + Metadata interface{} `json:"metadata,omitempty"` +} + +// PolicyMetadataSlimProperties the properties of the policy metadata, excluding properties containing +// large strings +type PolicyMetadataSlimProperties struct { + // MetadataID - READ-ONLY; The policy metadata identifier. + MetadataID *string `json:"metadataId,omitempty"` + // Category - READ-ONLY; The category of the policy metadata. + Category *string `json:"category,omitempty"` + // Title - READ-ONLY; The title of the policy metadata. + Title *string `json:"title,omitempty"` + // Owner - READ-ONLY; The owner of the policy metadata. + Owner *string `json:"owner,omitempty"` + // AdditionalContentURL - READ-ONLY; Url for getting additional content about the resource metadata. + AdditionalContentURL *string `json:"additionalContentUrl,omitempty"` + // Metadata - READ-ONLY; Additional metadata. + Metadata interface{} `json:"metadata,omitempty"` +} + +// PolicyReference resource identifiers for a policy. +type PolicyReference struct { + // PolicyDefinitionID - READ-ONLY; The resource identifier of the policy definition. + PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"` + // PolicySetDefinitionID - READ-ONLY; The resource identifier of the policy set definition. + PolicySetDefinitionID *string `json:"policySetDefinitionId,omitempty"` + // PolicyDefinitionReferenceID - READ-ONLY; The reference identifier of a specific policy definition within a policy set definition. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` + // PolicyAssignmentID - READ-ONLY; The resource identifier of the policy assignment. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` +} + +// PolicyState policy state record. +type PolicyState struct { + // AdditionalProperties - Unmatched properties from the message are deserialized this collection + AdditionalProperties map[string]interface{} `json:""` + // OdataID - OData entity ID; always set to null since policy state records do not have an entity ID. + OdataID *string `json:"@odata.id,omitempty"` + // OdataContext - OData context string; used by OData clients to resolve type information based on metadata. + OdataContext *string `json:"@odata.context,omitempty"` + // Timestamp - Timestamp for the policy state record. + Timestamp *date.Time `json:"timestamp,omitempty"` + // ResourceID - Resource ID. + ResourceID *string `json:"resourceId,omitempty"` + // PolicyAssignmentID - Policy assignment ID. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` + // PolicyDefinitionID - Policy definition ID. + PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"` + // EffectiveParameters - Effective parameters for the policy assignment. + EffectiveParameters *string `json:"effectiveParameters,omitempty"` + // IsCompliant - Flag which states whether the resource is compliant against the policy assignment it was evaluated against. This property is deprecated; please use ComplianceState instead. + IsCompliant *bool `json:"isCompliant,omitempty"` + // SubscriptionID - Subscription ID. + SubscriptionID *string `json:"subscriptionId,omitempty"` + // ResourceType - Resource type. + ResourceType *string `json:"resourceType,omitempty"` + // ResourceLocation - Resource location. + ResourceLocation *string `json:"resourceLocation,omitempty"` + // ResourceGroup - Resource group name. + ResourceGroup *string `json:"resourceGroup,omitempty"` + // ResourceTags - List of resource tags. + ResourceTags *string `json:"resourceTags,omitempty"` + // PolicyAssignmentName - Policy assignment name. + PolicyAssignmentName *string `json:"policyAssignmentName,omitempty"` + // PolicyAssignmentOwner - Policy assignment owner. + PolicyAssignmentOwner *string `json:"policyAssignmentOwner,omitempty"` + // PolicyAssignmentParameters - Policy assignment parameters. + PolicyAssignmentParameters *string `json:"policyAssignmentParameters,omitempty"` + // PolicyAssignmentScope - Policy assignment scope. + PolicyAssignmentScope *string `json:"policyAssignmentScope,omitempty"` + // PolicyDefinitionName - Policy definition name. + PolicyDefinitionName *string `json:"policyDefinitionName,omitempty"` + // PolicyDefinitionAction - Policy definition action, i.e. effect. + PolicyDefinitionAction *string `json:"policyDefinitionAction,omitempty"` + // PolicyDefinitionCategory - Policy definition category. + PolicyDefinitionCategory *string `json:"policyDefinitionCategory,omitempty"` + // PolicySetDefinitionID - Policy set definition ID, if the policy assignment is for a policy set. + PolicySetDefinitionID *string `json:"policySetDefinitionId,omitempty"` + // PolicySetDefinitionName - Policy set definition name, if the policy assignment is for a policy set. + PolicySetDefinitionName *string `json:"policySetDefinitionName,omitempty"` + // PolicySetDefinitionOwner - Policy set definition owner, if the policy assignment is for a policy set. + PolicySetDefinitionOwner *string `json:"policySetDefinitionOwner,omitempty"` + // PolicySetDefinitionCategory - Policy set definition category, if the policy assignment is for a policy set. + PolicySetDefinitionCategory *string `json:"policySetDefinitionCategory,omitempty"` + // PolicySetDefinitionParameters - Policy set definition parameters, if the policy assignment is for a policy set. + PolicySetDefinitionParameters *string `json:"policySetDefinitionParameters,omitempty"` + // ManagementGroupIds - Comma separated list of management group IDs, which represent the hierarchy of the management groups the resource is under. + ManagementGroupIds *string `json:"managementGroupIds,omitempty"` + // PolicyDefinitionReferenceID - Reference ID for the policy definition inside the policy set, if the policy assignment is for a policy set. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` + // ComplianceState - Compliance state of the resource. + ComplianceState *string `json:"complianceState,omitempty"` + // PolicyEvaluationDetails - Policy evaluation details. + PolicyEvaluationDetails *PolicyEvaluationDetails `json:"policyEvaluationDetails,omitempty"` + // PolicyDefinitionGroupNames - Policy definition group names. + PolicyDefinitionGroupNames *[]string `json:"policyDefinitionGroupNames,omitempty"` + // Components - Components state compliance records populated only when URL contains $expand=components clause. + Components *[]ComponentStateDetails `json:"components,omitempty"` + // PolicyDefinitionVersion - READ-ONLY; Evaluated policy definition version. + PolicyDefinitionVersion *string `json:"policyDefinitionVersion,omitempty"` + // PolicySetDefinitionVersion - READ-ONLY; Evaluated policy set definition version. + PolicySetDefinitionVersion *string `json:"policySetDefinitionVersion,omitempty"` + // PolicyAssignmentVersion - READ-ONLY; Evaluated policy assignment version. + PolicyAssignmentVersion *string `json:"policyAssignmentVersion,omitempty"` +} + +// MarshalJSON is the custom marshaler for PolicyState. +func (ps PolicyState) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ps.OdataID != nil { + objectMap["@odata.id"] = ps.OdataID + } + if ps.OdataContext != nil { + objectMap["@odata.context"] = ps.OdataContext + } + if ps.Timestamp != nil { + objectMap["timestamp"] = ps.Timestamp + } + if ps.ResourceID != nil { + objectMap["resourceId"] = ps.ResourceID + } + if ps.PolicyAssignmentID != nil { + objectMap["policyAssignmentId"] = ps.PolicyAssignmentID + } + if ps.PolicyDefinitionID != nil { + objectMap["policyDefinitionId"] = ps.PolicyDefinitionID + } + if ps.EffectiveParameters != nil { + objectMap["effectiveParameters"] = ps.EffectiveParameters + } + if ps.IsCompliant != nil { + objectMap["isCompliant"] = ps.IsCompliant + } + if ps.SubscriptionID != nil { + objectMap["subscriptionId"] = ps.SubscriptionID + } + if ps.ResourceType != nil { + objectMap["resourceType"] = ps.ResourceType + } + if ps.ResourceLocation != nil { + objectMap["resourceLocation"] = ps.ResourceLocation + } + if ps.ResourceGroup != nil { + objectMap["resourceGroup"] = ps.ResourceGroup + } + if ps.ResourceTags != nil { + objectMap["resourceTags"] = ps.ResourceTags + } + if ps.PolicyAssignmentName != nil { + objectMap["policyAssignmentName"] = ps.PolicyAssignmentName + } + if ps.PolicyAssignmentOwner != nil { + objectMap["policyAssignmentOwner"] = ps.PolicyAssignmentOwner + } + if ps.PolicyAssignmentParameters != nil { + objectMap["policyAssignmentParameters"] = ps.PolicyAssignmentParameters + } + if ps.PolicyAssignmentScope != nil { + objectMap["policyAssignmentScope"] = ps.PolicyAssignmentScope + } + if ps.PolicyDefinitionName != nil { + objectMap["policyDefinitionName"] = ps.PolicyDefinitionName + } + if ps.PolicyDefinitionAction != nil { + objectMap["policyDefinitionAction"] = ps.PolicyDefinitionAction + } + if ps.PolicyDefinitionCategory != nil { + objectMap["policyDefinitionCategory"] = ps.PolicyDefinitionCategory + } + if ps.PolicySetDefinitionID != nil { + objectMap["policySetDefinitionId"] = ps.PolicySetDefinitionID + } + if ps.PolicySetDefinitionName != nil { + objectMap["policySetDefinitionName"] = ps.PolicySetDefinitionName + } + if ps.PolicySetDefinitionOwner != nil { + objectMap["policySetDefinitionOwner"] = ps.PolicySetDefinitionOwner + } + if ps.PolicySetDefinitionCategory != nil { + objectMap["policySetDefinitionCategory"] = ps.PolicySetDefinitionCategory + } + if ps.PolicySetDefinitionParameters != nil { + objectMap["policySetDefinitionParameters"] = ps.PolicySetDefinitionParameters + } + if ps.ManagementGroupIds != nil { + objectMap["managementGroupIds"] = ps.ManagementGroupIds + } + if ps.PolicyDefinitionReferenceID != nil { + objectMap["policyDefinitionReferenceId"] = ps.PolicyDefinitionReferenceID + } + if ps.ComplianceState != nil { + objectMap["complianceState"] = ps.ComplianceState + } + if ps.PolicyEvaluationDetails != nil { + objectMap["policyEvaluationDetails"] = ps.PolicyEvaluationDetails + } + if ps.PolicyDefinitionGroupNames != nil { + objectMap["policyDefinitionGroupNames"] = ps.PolicyDefinitionGroupNames + } + if ps.Components != nil { + objectMap["components"] = ps.Components + } + for k, v := range ps.AdditionalProperties { + objectMap[k] = v + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for PolicyState struct. +func (ps *PolicyState) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + default: + if v != nil { + var additionalProperties interface{} + err = json.Unmarshal(*v, &additionalProperties) + if err != nil { + return err + } + if ps.AdditionalProperties == nil { + ps.AdditionalProperties = make(map[string]interface{}) + } + ps.AdditionalProperties[k] = additionalProperties + } + case "@odata.id": + if v != nil { + var odataID string + err = json.Unmarshal(*v, &odataID) + if err != nil { + return err + } + ps.OdataID = &odataID + } + case "@odata.context": + if v != nil { + var odataContext string + err = json.Unmarshal(*v, &odataContext) + if err != nil { + return err + } + ps.OdataContext = &odataContext + } + case "timestamp": + if v != nil { + var timestamp date.Time + err = json.Unmarshal(*v, ×tamp) + if err != nil { + return err + } + ps.Timestamp = ×tamp + } + case "resourceId": + if v != nil { + var resourceID string + err = json.Unmarshal(*v, &resourceID) + if err != nil { + return err + } + ps.ResourceID = &resourceID + } + case "policyAssignmentId": + if v != nil { + var policyAssignmentID string + err = json.Unmarshal(*v, &policyAssignmentID) + if err != nil { + return err + } + ps.PolicyAssignmentID = &policyAssignmentID + } + case "policyDefinitionId": + if v != nil { + var policyDefinitionID string + err = json.Unmarshal(*v, &policyDefinitionID) + if err != nil { + return err + } + ps.PolicyDefinitionID = &policyDefinitionID + } + case "effectiveParameters": + if v != nil { + var effectiveParameters string + err = json.Unmarshal(*v, &effectiveParameters) + if err != nil { + return err + } + ps.EffectiveParameters = &effectiveParameters + } + case "isCompliant": + if v != nil { + var isCompliant bool + err = json.Unmarshal(*v, &isCompliant) + if err != nil { + return err + } + ps.IsCompliant = &isCompliant + } + case "subscriptionId": + if v != nil { + var subscriptionID string + err = json.Unmarshal(*v, &subscriptionID) + if err != nil { + return err + } + ps.SubscriptionID = &subscriptionID + } + case "resourceType": + if v != nil { + var resourceType string + err = json.Unmarshal(*v, &resourceType) + if err != nil { + return err + } + ps.ResourceType = &resourceType + } + case "resourceLocation": + if v != nil { + var resourceLocation string + err = json.Unmarshal(*v, &resourceLocation) + if err != nil { + return err + } + ps.ResourceLocation = &resourceLocation + } + case "resourceGroup": + if v != nil { + var resourceGroup string + err = json.Unmarshal(*v, &resourceGroup) + if err != nil { + return err + } + ps.ResourceGroup = &resourceGroup + } + case "resourceTags": + if v != nil { + var resourceTags string + err = json.Unmarshal(*v, &resourceTags) + if err != nil { + return err + } + ps.ResourceTags = &resourceTags + } + case "policyAssignmentName": + if v != nil { + var policyAssignmentName string + err = json.Unmarshal(*v, &policyAssignmentName) + if err != nil { + return err + } + ps.PolicyAssignmentName = &policyAssignmentName + } + case "policyAssignmentOwner": + if v != nil { + var policyAssignmentOwner string + err = json.Unmarshal(*v, &policyAssignmentOwner) + if err != nil { + return err + } + ps.PolicyAssignmentOwner = &policyAssignmentOwner + } + case "policyAssignmentParameters": + if v != nil { + var policyAssignmentParameters string + err = json.Unmarshal(*v, &policyAssignmentParameters) + if err != nil { + return err + } + ps.PolicyAssignmentParameters = &policyAssignmentParameters + } + case "policyAssignmentScope": + if v != nil { + var policyAssignmentScope string + err = json.Unmarshal(*v, &policyAssignmentScope) + if err != nil { + return err + } + ps.PolicyAssignmentScope = &policyAssignmentScope + } + case "policyDefinitionName": + if v != nil { + var policyDefinitionName string + err = json.Unmarshal(*v, &policyDefinitionName) + if err != nil { + return err + } + ps.PolicyDefinitionName = &policyDefinitionName + } + case "policyDefinitionAction": + if v != nil { + var policyDefinitionAction string + err = json.Unmarshal(*v, &policyDefinitionAction) + if err != nil { + return err + } + ps.PolicyDefinitionAction = &policyDefinitionAction + } + case "policyDefinitionCategory": + if v != nil { + var policyDefinitionCategory string + err = json.Unmarshal(*v, &policyDefinitionCategory) + if err != nil { + return err + } + ps.PolicyDefinitionCategory = &policyDefinitionCategory + } + case "policySetDefinitionId": + if v != nil { + var policySetDefinitionID string + err = json.Unmarshal(*v, &policySetDefinitionID) + if err != nil { + return err + } + ps.PolicySetDefinitionID = &policySetDefinitionID + } + case "policySetDefinitionName": + if v != nil { + var policySetDefinitionName string + err = json.Unmarshal(*v, &policySetDefinitionName) + if err != nil { + return err + } + ps.PolicySetDefinitionName = &policySetDefinitionName + } + case "policySetDefinitionOwner": + if v != nil { + var policySetDefinitionOwner string + err = json.Unmarshal(*v, &policySetDefinitionOwner) + if err != nil { + return err + } + ps.PolicySetDefinitionOwner = &policySetDefinitionOwner + } + case "policySetDefinitionCategory": + if v != nil { + var policySetDefinitionCategory string + err = json.Unmarshal(*v, &policySetDefinitionCategory) + if err != nil { + return err + } + ps.PolicySetDefinitionCategory = &policySetDefinitionCategory + } + case "policySetDefinitionParameters": + if v != nil { + var policySetDefinitionParameters string + err = json.Unmarshal(*v, &policySetDefinitionParameters) + if err != nil { + return err + } + ps.PolicySetDefinitionParameters = &policySetDefinitionParameters + } + case "managementGroupIds": + if v != nil { + var managementGroupIds string + err = json.Unmarshal(*v, &managementGroupIds) + if err != nil { + return err + } + ps.ManagementGroupIds = &managementGroupIds + } + case "policyDefinitionReferenceId": + if v != nil { + var policyDefinitionReferenceID string + err = json.Unmarshal(*v, &policyDefinitionReferenceID) + if err != nil { + return err + } + ps.PolicyDefinitionReferenceID = &policyDefinitionReferenceID + } + case "complianceState": + if v != nil { + var complianceState string + err = json.Unmarshal(*v, &complianceState) + if err != nil { + return err + } + ps.ComplianceState = &complianceState + } + case "policyEvaluationDetails": + if v != nil { + var policyEvaluationDetails PolicyEvaluationDetails + err = json.Unmarshal(*v, &policyEvaluationDetails) + if err != nil { + return err + } + ps.PolicyEvaluationDetails = &policyEvaluationDetails + } + case "policyDefinitionGroupNames": + if v != nil { + var policyDefinitionGroupNames []string + err = json.Unmarshal(*v, &policyDefinitionGroupNames) + if err != nil { + return err + } + ps.PolicyDefinitionGroupNames = &policyDefinitionGroupNames + } + case "components": + if v != nil { + var components []ComponentStateDetails + err = json.Unmarshal(*v, &components) + if err != nil { + return err + } + ps.Components = &components + } + case "policyDefinitionVersion": + if v != nil { + var policyDefinitionVersion string + err = json.Unmarshal(*v, &policyDefinitionVersion) + if err != nil { + return err + } + ps.PolicyDefinitionVersion = &policyDefinitionVersion + } + case "policySetDefinitionVersion": + if v != nil { + var policySetDefinitionVersion string + err = json.Unmarshal(*v, &policySetDefinitionVersion) + if err != nil { + return err + } + ps.PolicySetDefinitionVersion = &policySetDefinitionVersion + } + case "policyAssignmentVersion": + if v != nil { + var policyAssignmentVersion string + err = json.Unmarshal(*v, &policyAssignmentVersion) + if err != nil { + return err + } + ps.PolicyAssignmentVersion = &policyAssignmentVersion + } + } + } + + return nil +} + +// PolicyStatesQueryResults query results. +type PolicyStatesQueryResults struct { + autorest.Response `json:"-"` + // OdataContext - OData context string; used by OData clients to resolve type information based on metadata. + OdataContext *string `json:"@odata.context,omitempty"` + // OdataCount - OData entity count; represents the number of policy state records returned. + OdataCount *int32 `json:"@odata.count,omitempty"` + // OdataNextLink - Odata next link; URL to get the next set of results. + OdataNextLink *string `json:"@odata.nextLink,omitempty"` + // Value - Query results. + Value *[]PolicyState `json:"value,omitempty"` +} + +// PolicyStatesQueryResultsIterator provides access to a complete listing of PolicyState values. +type PolicyStatesQueryResultsIterator struct { + i int + page PolicyStatesQueryResultsPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *PolicyStatesQueryResultsIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesQueryResultsIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *PolicyStatesQueryResultsIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter PolicyStatesQueryResultsIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter PolicyStatesQueryResultsIterator) Response() PolicyStatesQueryResults { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter PolicyStatesQueryResultsIterator) Value() PolicyState { + if !iter.page.NotDone() { + return PolicyState{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the PolicyStatesQueryResultsIterator type. +func NewPolicyStatesQueryResultsIterator(page PolicyStatesQueryResultsPage) PolicyStatesQueryResultsIterator { + return PolicyStatesQueryResultsIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (psqr PolicyStatesQueryResults) IsEmpty() bool { + return psqr.Value == nil || len(*psqr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (psqr PolicyStatesQueryResults) hasNextLink() bool { + return psqr.OdataNextLink != nil && len(*psqr.OdataNextLink) != 0 +} + +// policyStatesQueryResultsPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (psqr PolicyStatesQueryResults) policyStatesQueryResultsPreparer(ctx context.Context) (*http.Request, error) { + if !psqr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(psqr.OdataNextLink))) +} + +// PolicyStatesQueryResultsPage contains a page of PolicyState values. +type PolicyStatesQueryResultsPage struct { + fn func(context.Context, PolicyStatesQueryResults) (PolicyStatesQueryResults, error) + psqr PolicyStatesQueryResults +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *PolicyStatesQueryResultsPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesQueryResultsPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.psqr) + if err != nil { + return err + } + page.psqr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *PolicyStatesQueryResultsPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page PolicyStatesQueryResultsPage) NotDone() bool { + return !page.psqr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page PolicyStatesQueryResultsPage) Response() PolicyStatesQueryResults { + return page.psqr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page PolicyStatesQueryResultsPage) Values() []PolicyState { + if page.psqr.IsEmpty() { + return nil + } + return *page.psqr.Value +} + +// Creates a new instance of the PolicyStatesQueryResultsPage type. +func NewPolicyStatesQueryResultsPage(cur PolicyStatesQueryResults, getNextPage func(context.Context, PolicyStatesQueryResults) (PolicyStatesQueryResults, error)) PolicyStatesQueryResultsPage { + return PolicyStatesQueryResultsPage{ + fn: getNextPage, + psqr: cur, + } +} + +// PolicyStatesTriggerResourceGroupEvaluationFuture an abstraction for monitoring and retrieving the +// results of a long-running operation. +type PolicyStatesTriggerResourceGroupEvaluationFuture struct { + azure.FutureAPI + // Result returns the result of the asynchronous operation. + // If the operation has not completed it will return an error. + Result func(PolicyStatesClient) (autorest.Response, error) +} + +// PolicyStatesTriggerSubscriptionEvaluationFuture an abstraction for monitoring and retrieving the results +// of a long-running operation. +type PolicyStatesTriggerSubscriptionEvaluationFuture struct { + azure.FutureAPI + // Result returns the result of the asynchronous operation. + // If the operation has not completed it will return an error. + Result func(PolicyStatesClient) (autorest.Response, error) +} + +// PolicyTrackedResource policy tracked resource record. +type PolicyTrackedResource struct { + // TrackedResourceID - READ-ONLY; The ID of the policy tracked resource. + TrackedResourceID *string `json:"trackedResourceId,omitempty"` + // PolicyDetails - READ-ONLY; The details of the policy that require the tracked resource. + PolicyDetails *PolicyDetails `json:"policyDetails,omitempty"` + // CreatedBy - READ-ONLY; The details of the policy triggered deployment that created the tracked resource. + CreatedBy *TrackedResourceModificationDetails `json:"createdBy,omitempty"` + // LastModifiedBy - READ-ONLY; The details of the policy triggered deployment that modified the tracked resource. + LastModifiedBy *TrackedResourceModificationDetails `json:"lastModifiedBy,omitempty"` + // LastUpdateUtc - READ-ONLY; Timestamp of the last update to the tracked resource. + LastUpdateUtc *date.Time `json:"lastUpdateUtc,omitempty"` +} + +// PolicyTrackedResourcesQueryResults query results. +type PolicyTrackedResourcesQueryResults struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Query results. + Value *[]PolicyTrackedResource `json:"value,omitempty"` + // NextLink - READ-ONLY; The URL to get the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// PolicyTrackedResourcesQueryResultsIterator provides access to a complete listing of +// PolicyTrackedResource values. +type PolicyTrackedResourcesQueryResultsIterator struct { + i int + page PolicyTrackedResourcesQueryResultsPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *PolicyTrackedResourcesQueryResultsIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesQueryResultsIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *PolicyTrackedResourcesQueryResultsIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter PolicyTrackedResourcesQueryResultsIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter PolicyTrackedResourcesQueryResultsIterator) Response() PolicyTrackedResourcesQueryResults { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter PolicyTrackedResourcesQueryResultsIterator) Value() PolicyTrackedResource { + if !iter.page.NotDone() { + return PolicyTrackedResource{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the PolicyTrackedResourcesQueryResultsIterator type. +func NewPolicyTrackedResourcesQueryResultsIterator(page PolicyTrackedResourcesQueryResultsPage) PolicyTrackedResourcesQueryResultsIterator { + return PolicyTrackedResourcesQueryResultsIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (ptrqr PolicyTrackedResourcesQueryResults) IsEmpty() bool { + return ptrqr.Value == nil || len(*ptrqr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (ptrqr PolicyTrackedResourcesQueryResults) hasNextLink() bool { + return ptrqr.NextLink != nil && len(*ptrqr.NextLink) != 0 +} + +// policyTrackedResourcesQueryResultsPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (ptrqr PolicyTrackedResourcesQueryResults) policyTrackedResourcesQueryResultsPreparer(ctx context.Context) (*http.Request, error) { + if !ptrqr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(ptrqr.NextLink))) +} + +// PolicyTrackedResourcesQueryResultsPage contains a page of PolicyTrackedResource values. +type PolicyTrackedResourcesQueryResultsPage struct { + fn func(context.Context, PolicyTrackedResourcesQueryResults) (PolicyTrackedResourcesQueryResults, error) + ptrqr PolicyTrackedResourcesQueryResults +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *PolicyTrackedResourcesQueryResultsPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesQueryResultsPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.ptrqr) + if err != nil { + return err + } + page.ptrqr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *PolicyTrackedResourcesQueryResultsPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page PolicyTrackedResourcesQueryResultsPage) NotDone() bool { + return !page.ptrqr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page PolicyTrackedResourcesQueryResultsPage) Response() PolicyTrackedResourcesQueryResults { + return page.ptrqr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page PolicyTrackedResourcesQueryResultsPage) Values() []PolicyTrackedResource { + if page.ptrqr.IsEmpty() { + return nil + } + return *page.ptrqr.Value +} + +// Creates a new instance of the PolicyTrackedResourcesQueryResultsPage type. +func NewPolicyTrackedResourcesQueryResultsPage(cur PolicyTrackedResourcesQueryResults, getNextPage func(context.Context, PolicyTrackedResourcesQueryResults) (PolicyTrackedResourcesQueryResults, error)) PolicyTrackedResourcesQueryResultsPage { + return PolicyTrackedResourcesQueryResultsPage{ + fn: getNextPage, + ptrqr: cur, + } +} + +// ProxyResource the resource model definition for a Azure Resource Manager proxy resource. It will not +// have tags and a location +type ProxyResource struct { + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// QueryFailure error response. +type QueryFailure struct { + // Error - Error definition. + Error *QueryFailureError `json:"error,omitempty"` +} + +// QueryFailureError error definition. +type QueryFailureError struct { + // Code - READ-ONLY; Service specific error code which serves as the substatus for the HTTP error code. + Code *string `json:"code,omitempty"` + // Message - READ-ONLY; Description of the error. + Message *string `json:"message,omitempty"` +} + +// Remediation the remediation definition. +type Remediation struct { + autorest.Response `json:"-"` + // RemediationProperties - Properties for the remediation. + *RemediationProperties `json:"properties,omitempty"` + // ID - READ-ONLY; The ID of the remediation. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; The type of the remediation. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; The name of the remediation. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for Remediation. +func (r Remediation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if r.RemediationProperties != nil { + objectMap["properties"] = r.RemediationProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Remediation struct. +func (r *Remediation) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var remediationProperties RemediationProperties + err = json.Unmarshal(*v, &remediationProperties) + if err != nil { + return err + } + r.RemediationProperties = &remediationProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + r.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + r.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + r.Name = &name + } + } + } + + return nil +} + +// RemediationDeployment details of a single deployment created by the remediation. +type RemediationDeployment struct { + // RemediatedResourceID - READ-ONLY; Resource ID of the resource that is being remediated by the deployment. + RemediatedResourceID *string `json:"remediatedResourceId,omitempty"` + // DeploymentID - READ-ONLY; Resource ID of the template deployment that will remediate the resource. + DeploymentID *string `json:"deploymentId,omitempty"` + // Status - READ-ONLY; Status of the remediation deployment. + Status *string `json:"status,omitempty"` + // ResourceLocation - READ-ONLY; Location of the resource that is being remediated. + ResourceLocation *string `json:"resourceLocation,omitempty"` + // Error - READ-ONLY; Error encountered while remediated the resource. + Error *ErrorDefinition `json:"error,omitempty"` + // CreatedOn - READ-ONLY; The time at which the remediation was created. + CreatedOn *date.Time `json:"createdOn,omitempty"` + // LastUpdatedOn - READ-ONLY; The time at which the remediation deployment was last updated. + LastUpdatedOn *date.Time `json:"lastUpdatedOn,omitempty"` +} + +// RemediationDeploymentsListResult list of deployments for a remediation. +type RemediationDeploymentsListResult struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Array of deployments for the remediation. + Value *[]RemediationDeployment `json:"value,omitempty"` + // NextLink - READ-ONLY; The URL to get the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// RemediationDeploymentsListResultIterator provides access to a complete listing of RemediationDeployment +// values. +type RemediationDeploymentsListResultIterator struct { + i int + page RemediationDeploymentsListResultPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *RemediationDeploymentsListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationDeploymentsListResultIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *RemediationDeploymentsListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter RemediationDeploymentsListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter RemediationDeploymentsListResultIterator) Response() RemediationDeploymentsListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter RemediationDeploymentsListResultIterator) Value() RemediationDeployment { + if !iter.page.NotDone() { + return RemediationDeployment{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the RemediationDeploymentsListResultIterator type. +func NewRemediationDeploymentsListResultIterator(page RemediationDeploymentsListResultPage) RemediationDeploymentsListResultIterator { + return RemediationDeploymentsListResultIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (rdlr RemediationDeploymentsListResult) IsEmpty() bool { + return rdlr.Value == nil || len(*rdlr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (rdlr RemediationDeploymentsListResult) hasNextLink() bool { + return rdlr.NextLink != nil && len(*rdlr.NextLink) != 0 +} + +// remediationDeploymentsListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (rdlr RemediationDeploymentsListResult) remediationDeploymentsListResultPreparer(ctx context.Context) (*http.Request, error) { + if !rdlr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(rdlr.NextLink))) +} + +// RemediationDeploymentsListResultPage contains a page of RemediationDeployment values. +type RemediationDeploymentsListResultPage struct { + fn func(context.Context, RemediationDeploymentsListResult) (RemediationDeploymentsListResult, error) + rdlr RemediationDeploymentsListResult +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *RemediationDeploymentsListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationDeploymentsListResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.rdlr) + if err != nil { + return err + } + page.rdlr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *RemediationDeploymentsListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page RemediationDeploymentsListResultPage) NotDone() bool { + return !page.rdlr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page RemediationDeploymentsListResultPage) Response() RemediationDeploymentsListResult { + return page.rdlr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page RemediationDeploymentsListResultPage) Values() []RemediationDeployment { + if page.rdlr.IsEmpty() { + return nil + } + return *page.rdlr.Value +} + +// Creates a new instance of the RemediationDeploymentsListResultPage type. +func NewRemediationDeploymentsListResultPage(cur RemediationDeploymentsListResult, getNextPage func(context.Context, RemediationDeploymentsListResult) (RemediationDeploymentsListResult, error)) RemediationDeploymentsListResultPage { + return RemediationDeploymentsListResultPage{ + fn: getNextPage, + rdlr: cur, + } +} + +// RemediationDeploymentSummary the deployment status summary for all deployments created by the +// remediation. +type RemediationDeploymentSummary struct { + // TotalDeployments - READ-ONLY; The number of deployments required by the remediation. + TotalDeployments *int32 `json:"totalDeployments,omitempty"` + // SuccessfulDeployments - READ-ONLY; The number of deployments required by the remediation that have succeeded. + SuccessfulDeployments *int32 `json:"successfulDeployments,omitempty"` + // FailedDeployments - READ-ONLY; The number of deployments required by the remediation that have failed. + FailedDeployments *int32 `json:"failedDeployments,omitempty"` +} + +// RemediationFilters the filters that will be applied to determine which resources to remediate. +type RemediationFilters struct { + // Locations - The resource locations that will be remediated. + Locations *[]string `json:"locations,omitempty"` +} + +// RemediationListResult list of remediations. +type RemediationListResult struct { + autorest.Response `json:"-"` + // Value - READ-ONLY; Array of remediation definitions. + Value *[]Remediation `json:"value,omitempty"` + // NextLink - READ-ONLY; The URL to get the next set of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// RemediationListResultIterator provides access to a complete listing of Remediation values. +type RemediationListResultIterator struct { + i int + page RemediationListResultPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *RemediationListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationListResultIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *RemediationListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter RemediationListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter RemediationListResultIterator) Response() RemediationListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter RemediationListResultIterator) Value() Remediation { + if !iter.page.NotDone() { + return Remediation{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the RemediationListResultIterator type. +func NewRemediationListResultIterator(page RemediationListResultPage) RemediationListResultIterator { + return RemediationListResultIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (rlr RemediationListResult) IsEmpty() bool { + return rlr.Value == nil || len(*rlr.Value) == 0 +} + +// hasNextLink returns true if the NextLink is not empty. +func (rlr RemediationListResult) hasNextLink() bool { + return rlr.NextLink != nil && len(*rlr.NextLink) != 0 +} + +// remediationListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (rlr RemediationListResult) remediationListResultPreparer(ctx context.Context) (*http.Request, error) { + if !rlr.hasNextLink() { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(rlr.NextLink))) +} + +// RemediationListResultPage contains a page of Remediation values. +type RemediationListResultPage struct { + fn func(context.Context, RemediationListResult) (RemediationListResult, error) + rlr RemediationListResult +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *RemediationListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationListResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + for { + next, err := page.fn(ctx, page.rlr) + if err != nil { + return err + } + page.rlr = next + if !next.hasNextLink() || !next.IsEmpty() { + break + } + } + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *RemediationListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page RemediationListResultPage) NotDone() bool { + return !page.rlr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page RemediationListResultPage) Response() RemediationListResult { + return page.rlr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page RemediationListResultPage) Values() []Remediation { + if page.rlr.IsEmpty() { + return nil + } + return *page.rlr.Value +} + +// Creates a new instance of the RemediationListResultPage type. +func NewRemediationListResultPage(cur RemediationListResult, getNextPage func(context.Context, RemediationListResult) (RemediationListResult, error)) RemediationListResultPage { + return RemediationListResultPage{ + fn: getNextPage, + rlr: cur, + } +} + +// RemediationProperties the remediation properties. +type RemediationProperties struct { + // PolicyAssignmentID - The resource ID of the policy assignment that should be remediated. + PolicyAssignmentID *string `json:"policyAssignmentId,omitempty"` + // PolicyDefinitionReferenceID - The policy definition reference ID of the individual definition that should be remediated. Required when the policy assignment being remediated assigns a policy set definition. + PolicyDefinitionReferenceID *string `json:"policyDefinitionReferenceId,omitempty"` + // ResourceDiscoveryMode - The way resources to remediate are discovered. Defaults to ExistingNonCompliant if not specified. Possible values include: 'ExistingNonCompliant', 'ReEvaluateCompliance' + ResourceDiscoveryMode ResourceDiscoveryMode `json:"resourceDiscoveryMode,omitempty"` + // ProvisioningState - READ-ONLY; The status of the remediation. + ProvisioningState *string `json:"provisioningState,omitempty"` + // CreatedOn - READ-ONLY; The time at which the remediation was created. + CreatedOn *date.Time `json:"createdOn,omitempty"` + // LastUpdatedOn - READ-ONLY; The time at which the remediation was last updated. + LastUpdatedOn *date.Time `json:"lastUpdatedOn,omitempty"` + // Filters - The filters that will be applied to determine which resources to remediate. + Filters *RemediationFilters `json:"filters,omitempty"` + // DeploymentStatus - READ-ONLY; The deployment status summary for all deployments created by the remediation. + DeploymentStatus *RemediationDeploymentSummary `json:"deploymentStatus,omitempty"` +} + +// MarshalJSON is the custom marshaler for RemediationProperties. +func (rp RemediationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if rp.PolicyAssignmentID != nil { + objectMap["policyAssignmentId"] = rp.PolicyAssignmentID + } + if rp.PolicyDefinitionReferenceID != nil { + objectMap["policyDefinitionReferenceId"] = rp.PolicyDefinitionReferenceID + } + if rp.ResourceDiscoveryMode != "" { + objectMap["resourceDiscoveryMode"] = rp.ResourceDiscoveryMode + } + if rp.Filters != nil { + objectMap["filters"] = rp.Filters + } + return json.Marshal(objectMap) +} + +// Resource common fields that are returned in the response for all Azure Resource Manager resources +type Resource struct { + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// SlimPolicyMetadata slim version of policy metadata resource definition, excluding properties with large +// strings +type SlimPolicyMetadata struct { + // PolicyMetadataSlimProperties - Properties of the policy metadata. + *PolicyMetadataSlimProperties `json:"properties,omitempty"` + // ID - READ-ONLY; The ID of the policy metadata. + ID *string `json:"id,omitempty"` + // Type - READ-ONLY; The type of the policy metadata. + Type *string `json:"type,omitempty"` + // Name - READ-ONLY; The name of the policy metadata. + Name *string `json:"name,omitempty"` +} + +// MarshalJSON is the custom marshaler for SlimPolicyMetadata. +func (spm SlimPolicyMetadata) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if spm.PolicyMetadataSlimProperties != nil { + objectMap["properties"] = spm.PolicyMetadataSlimProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for SlimPolicyMetadata struct. +func (spm *SlimPolicyMetadata) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var policyMetadataSlimProperties PolicyMetadataSlimProperties + err = json.Unmarshal(*v, &policyMetadataSlimProperties) + if err != nil { + return err + } + spm.PolicyMetadataSlimProperties = &policyMetadataSlimProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + spm.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + spm.Type = &typeVar + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + spm.Name = &name + } + } + } + + return nil +} + +// SummarizeResults summarize action results. +type SummarizeResults struct { + autorest.Response `json:"-"` + // OdataContext - OData context string; used by OData clients to resolve type information based on metadata. + OdataContext *string `json:"@odata.context,omitempty"` + // OdataCount - OData entity count; represents the number of summaries returned; always set to 1. + OdataCount *int32 `json:"@odata.count,omitempty"` + // Value - Summarize action results. + Value *[]Summary `json:"value,omitempty"` +} + +// Summary summary results. +type Summary struct { + // OdataID - OData entity ID; always set to null since summaries do not have an entity ID. + OdataID *string `json:"@odata.id,omitempty"` + // OdataContext - OData context string; used by OData clients to resolve type information based on metadata. + OdataContext *string `json:"@odata.context,omitempty"` + // Results - Compliance summary for all policy assignments. + Results *SummaryResults `json:"results,omitempty"` + // PolicyAssignments - Policy assignments summary. + PolicyAssignments *[]PolicyAssignmentSummary `json:"policyAssignments,omitempty"` +} + +// SummaryResults compliance summary on a particular summary level. +type SummaryResults struct { + // QueryResultsURI - HTTP POST URI for queryResults action on Microsoft.PolicyInsights to retrieve raw results for the compliance summary. This property will not be available by default in future API versions, but could be queried explicitly. + QueryResultsURI *string `json:"queryResultsUri,omitempty"` + // NonCompliantResources - Number of non-compliant resources. + NonCompliantResources *int32 `json:"nonCompliantResources,omitempty"` + // NonCompliantPolicies - Number of non-compliant policies. + NonCompliantPolicies *int32 `json:"nonCompliantPolicies,omitempty"` + // ResourceDetails - The resources summary at this level. + ResourceDetails *[]ComplianceDetail `json:"resourceDetails,omitempty"` + // PolicyDetails - The policy artifact summary at this level. For query scope level, it represents policy assignment summary. For policy assignment level, it represents policy definitions summary. + PolicyDetails *[]ComplianceDetail `json:"policyDetails,omitempty"` + // PolicyGroupDetails - The policy definition group summary at this level. + PolicyGroupDetails *[]ComplianceDetail `json:"policyGroupDetails,omitempty"` +} + +// SystemData metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // CreatedBy - The identity that created the resource. + CreatedBy *string `json:"createdBy,omitempty"` + // CreatedByType - The type of identity that created the resource. Possible values include: 'User', 'Application', 'ManagedIdentity', 'Key' + CreatedByType CreatedByType `json:"createdByType,omitempty"` + // CreatedAt - The timestamp of resource creation (UTC). + CreatedAt *date.Time `json:"createdAt,omitempty"` + // LastModifiedBy - The identity that last modified the resource. + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + // LastModifiedByType - The type of identity that last modified the resource. Possible values include: 'User', 'Application', 'ManagedIdentity', 'Key' + LastModifiedByType CreatedByType `json:"lastModifiedByType,omitempty"` + // LastModifiedAt - The type of identity that last modified the resource. + LastModifiedAt *date.Time `json:"lastModifiedAt,omitempty"` +} + +// TrackedResource the resource model definition for an Azure Resource Manager tracked top level resource +// which has 'tags' and a 'location' +type TrackedResource struct { + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` + // Location - The geo-location where the resource lives + Location *string `json:"location,omitempty"` + // ID - READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty"` + // Name - READ-ONLY; The name of the resource + Name *string `json:"name,omitempty"` + // Type - READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for TrackedResource. +func (tr TrackedResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if tr.Tags != nil { + objectMap["tags"] = tr.Tags + } + if tr.Location != nil { + objectMap["location"] = tr.Location + } + return json.Marshal(objectMap) +} + +// TrackedResourceModificationDetails the details of the policy triggered deployment that created or +// modified the tracked resource. +type TrackedResourceModificationDetails struct { + // PolicyDetails - READ-ONLY; The details of the policy that created or modified the tracked resource. + PolicyDetails *PolicyDetails `json:"policyDetails,omitempty"` + // DeploymentID - READ-ONLY; The ID of the deployment that created or modified the tracked resource. + DeploymentID *string `json:"deploymentId,omitempty"` + // DeploymentTime - READ-ONLY; Timestamp of the deployment that created or modified the tracked resource. + DeploymentTime *date.Time `json:"deploymentTime,omitempty"` +} + +// TypedErrorInfo scenario specific error details. +type TypedErrorInfo struct { + // Type - READ-ONLY; The type of included error details. + Type *string `json:"type,omitempty"` + // Info - READ-ONLY; The scenario specific error details. + Info interface{} `json:"info,omitempty"` +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/operations.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/operations.go new file mode 100644 index 000000000000..7a1267242810 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/operations.go @@ -0,0 +1,109 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// OperationsClient is the client for the Operations methods of the Policyinsights service. +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID2 string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint. Use this +// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID2 string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// List lists available operations. +func (client OperationsClient) List(ctx context.Context) (result OperationsListResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.OperationsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.OperationsClient", "List", resp, "Failure responding to request") + return + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.PolicyInsights/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result OperationsListResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyevents.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyevents.go new file mode 100644 index 000000000000..0c3f79cbb606 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyevents.go @@ -0,0 +1,1347 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PolicyEventsClient is the client for the PolicyEvents methods of the Policyinsights service. +type PolicyEventsClient struct { + BaseClient +} + +// NewPolicyEventsClient creates an instance of the PolicyEventsClient client. +func NewPolicyEventsClient(subscriptionID2 string) PolicyEventsClient { + return NewPolicyEventsClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewPolicyEventsClientWithBaseURI creates an instance of the PolicyEventsClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewPolicyEventsClientWithBaseURI(baseURI string, subscriptionID2 string) PolicyEventsClient { + return PolicyEventsClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// ListQueryResultsForManagementGroup queries policy events for the resources under the management group. +// Parameters: +// managementGroupName - management group name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForManagementGroup(ctx context.Context, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForManagementGroup") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForManagementGroup", err.Error()) + } + + result.fn = client.listQueryResultsForManagementGroupNextResults + req, err := client.ListQueryResultsForManagementGroupPreparer(ctx, managementGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForManagementGroupSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForManagementGroup", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForManagementGroup", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForManagementGroupPreparer prepares the ListQueryResultsForManagementGroup request. +func (client PolicyEventsClient) ListQueryResultsForManagementGroupPreparer(ctx context.Context, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupName": autorest.Encode("path", managementGroupName), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "policyEventsResource": autorest.Encode("path", "default"), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForManagementGroupSender sends the ListQueryResultsForManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListQueryResultsForManagementGroupResponder handles the response to the ListQueryResultsForManagementGroup request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForManagementGroupResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForManagementGroupNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForManagementGroupNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForManagementGroupComplete(ctx context.Context, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForManagementGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForManagementGroup(ctx, managementGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForPolicyDefinition queries policy events for the subscription level policy definition. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// policyDefinitionName - policy definition name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForPolicyDefinition(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForPolicyDefinition") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForPolicyDefinition", err.Error()) + } + + result.fn = client.listQueryResultsForPolicyDefinitionNextResults + req, err := client.ListQueryResultsForPolicyDefinitionPreparer(ctx, subscriptionID, policyDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForPolicyDefinition", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForPolicyDefinitionSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForPolicyDefinition", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForPolicyDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForPolicyDefinition", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForPolicyDefinitionPreparer prepares the ListQueryResultsForPolicyDefinition request. +func (client PolicyEventsClient) ListQueryResultsForPolicyDefinitionPreparer(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyDefinitionName": autorest.Encode("path", policyDefinitionName), + "policyEventsResource": autorest.Encode("path", "default"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForPolicyDefinitionSender sends the ListQueryResultsForPolicyDefinition request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForPolicyDefinitionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForPolicyDefinitionResponder handles the response to the ListQueryResultsForPolicyDefinition request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForPolicyDefinitionResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForPolicyDefinitionNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForPolicyDefinitionNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForPolicyDefinitionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForPolicyDefinitionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForPolicyDefinitionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForPolicyDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForPolicyDefinitionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForPolicyDefinitionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForPolicyDefinitionComplete(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForPolicyDefinition") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForPolicyDefinition(ctx, subscriptionID, policyDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForPolicySetDefinition queries policy events for the subscription level policy set definition. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// policySetDefinitionName - policy set definition name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForPolicySetDefinition(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForPolicySetDefinition") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForPolicySetDefinition", err.Error()) + } + + result.fn = client.listQueryResultsForPolicySetDefinitionNextResults + req, err := client.ListQueryResultsForPolicySetDefinitionPreparer(ctx, subscriptionID, policySetDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForPolicySetDefinition", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForPolicySetDefinitionSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForPolicySetDefinition", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForPolicySetDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForPolicySetDefinition", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForPolicySetDefinitionPreparer prepares the ListQueryResultsForPolicySetDefinition request. +func (client PolicyEventsClient) ListQueryResultsForPolicySetDefinitionPreparer(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyEventsResource": autorest.Encode("path", "default"), + "policySetDefinitionName": autorest.Encode("path", policySetDefinitionName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForPolicySetDefinitionSender sends the ListQueryResultsForPolicySetDefinition request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForPolicySetDefinitionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForPolicySetDefinitionResponder handles the response to the ListQueryResultsForPolicySetDefinition request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForPolicySetDefinitionResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForPolicySetDefinitionNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForPolicySetDefinitionNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForPolicySetDefinitionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForPolicySetDefinitionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForPolicySetDefinitionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForPolicySetDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForPolicySetDefinitionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForPolicySetDefinitionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForPolicySetDefinitionComplete(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForPolicySetDefinition") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForPolicySetDefinition(ctx, subscriptionID, policySetDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForResource queries policy events for the resource. +// Parameters: +// resourceID - resource ID. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// expand - the $expand query parameter. For example, to expand components use $expand=components +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForResource(ctx context.Context, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForResource") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForResource", err.Error()) + } + + result.fn = client.listQueryResultsForResourceNextResults + req, err := client.ListQueryResultsForResourcePreparer(ctx, resourceID, top, orderBy, selectParameter, from, toParameter, filter, apply, expand, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResource", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResource", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResource", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourcePreparer prepares the ListQueryResultsForResource request. +func (client PolicyEventsClient) ListQueryResultsForResourcePreparer(ctx context.Context, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyEventsResource": autorest.Encode("path", "default"), + "resourceId": resourceID, + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceSender sends the ListQueryResultsForResource request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListQueryResultsForResourceResponder handles the response to the ListQueryResultsForResource request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForResourceResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForResourceNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForResourceComplete(ctx context.Context, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForResource") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResource(ctx, resourceID, top, orderBy, selectParameter, from, toParameter, filter, apply, expand, skipToken) + return +} + +// ListQueryResultsForResourceGroup queries policy events for the resources under the resource group. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForResourceGroup") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroup", err.Error()) + } + + result.fn = client.listQueryResultsForResourceGroupNextResults + req, err := client.ListQueryResultsForResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceGroupSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroup", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroup", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourceGroupPreparer prepares the ListQueryResultsForResourceGroup request. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyEventsResource": autorest.Encode("path", "default"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceGroupSender sends the ListQueryResultsForResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForResourceGroupResponder handles the response to the ListQueryResultsForResourceGroup request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceGroupNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForResourceGroupNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResourceGroup(ctx, subscriptionID, resourceGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignment queries policy events for the resource group level policy +// assignment. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// policyAssignmentName - policy assignment name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupLevelPolicyAssignment(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForResourceGroupLevelPolicyAssignment") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", err.Error()) + } + + result.fn = client.listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults + req, err := client.ListQueryResultsForResourceGroupLevelPolicyAssignmentPreparer(ctx, subscriptionID, resourceGroupName, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceGroupLevelPolicyAssignmentSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentPreparer prepares the ListQueryResultsForResourceGroupLevelPolicyAssignment request. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyAssignmentName": autorest.Encode("path", policyAssignmentName), + "policyEventsResource": autorest.Encode("path", "default"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentSender sends the ListQueryResultsForResourceGroupLevelPolicyAssignment request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder handles the response to the ListQueryResultsForResourceGroupLevelPolicyAssignment request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceGroupLevelPolicyAssignmentSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentComplete(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForResourceGroupLevelPolicyAssignment") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResourceGroupLevelPolicyAssignment(ctx, subscriptionID, resourceGroupName, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForSubscription queries policy events for the resources under the subscription. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForSubscription(ctx context.Context, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForSubscription") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForSubscription", err.Error()) + } + + result.fn = client.listQueryResultsForSubscriptionNextResults + req, err := client.ListQueryResultsForSubscriptionPreparer(ctx, subscriptionID, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForSubscriptionSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForSubscription", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForSubscription", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForSubscriptionPreparer prepares the ListQueryResultsForSubscription request. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionPreparer(ctx context.Context, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyEventsResource": autorest.Encode("path", "default"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForSubscriptionSender sends the ListQueryResultsForSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForSubscriptionResponder handles the response to the ListQueryResultsForSubscription request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForSubscriptionNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForSubscriptionNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForSubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForSubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForSubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForSubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForSubscription(ctx, subscriptionID, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignment queries policy events for the subscription level policy +// assignment. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// policyAssignmentName - policy assignment name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionLevelPolicyAssignment(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForSubscriptionLevelPolicyAssignment") + defer func() { + sc := -1 + if result.peqr.Response.Response != nil { + sc = result.peqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyEventsClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", err.Error()) + } + + result.fn = client.listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults + req, err := client.ListQueryResultsForSubscriptionLevelPolicyAssignmentPreparer(ctx, subscriptionID, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForSubscriptionLevelPolicyAssignmentSender(req) + if err != nil { + result.peqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", resp, "Failure sending request") + return + } + + result.peqr, err = client.ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", resp, "Failure responding to request") + return + } + if result.peqr.hasNextLink() && result.peqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentPreparer prepares the ListQueryResultsForSubscriptionLevelPolicyAssignment request. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentPreparer(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyAssignmentName": autorest.Encode("path", policyAssignmentName), + "policyEventsResource": autorest.Encode("path", "default"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyEvents/{policyEventsResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentSender sends the ListQueryResultsForSubscriptionLevelPolicyAssignment request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder handles the response to the ListQueryResultsForSubscriptionLevelPolicyAssignment request. The method always +// closes the http.Response Body. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder(resp *http.Response) (result PolicyEventsQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults retrieves the next set of results, if any. +func (client PolicyEventsClient) listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults(ctx context.Context, lastResults PolicyEventsQueryResults) (result PolicyEventsQueryResults, err error) { + req, err := lastResults.policyEventsQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForSubscriptionLevelPolicyAssignmentSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyEventsClient", "listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyEventsClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentComplete(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyEventsQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyEventsClient.ListQueryResultsForSubscriptionLevelPolicyAssignment") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForSubscriptionLevelPolicyAssignment(ctx, subscriptionID, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyinsightsapi/interfaces.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyinsightsapi/interfaces.go new file mode 100644 index 000000000000..4ededb615a78 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyinsightsapi/interfaces.go @@ -0,0 +1,176 @@ +package policyinsightsapi + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/date" +) + +// PolicyTrackedResourcesClientAPI contains the set of methods on the PolicyTrackedResourcesClient type. +type PolicyTrackedResourcesClientAPI interface { + ListQueryResultsForManagementGroup(ctx context.Context, managementGroupName string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsPage, err error) + ListQueryResultsForManagementGroupComplete(ctx context.Context, managementGroupName string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsIterator, err error) + ListQueryResultsForResource(ctx context.Context, resourceID string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsPage, err error) + ListQueryResultsForResourceComplete(ctx context.Context, resourceID string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsIterator, err error) + ListQueryResultsForResourceGroup(ctx context.Context, resourceGroupName string, subscriptionID string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsPage, err error) + ListQueryResultsForResourceGroupComplete(ctx context.Context, resourceGroupName string, subscriptionID string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsIterator, err error) + ListQueryResultsForSubscription(ctx context.Context, subscriptionID string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsPage, err error) + ListQueryResultsForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, filter string) (result policyinsights.PolicyTrackedResourcesQueryResultsIterator, err error) +} + +var _ PolicyTrackedResourcesClientAPI = (*policyinsights.PolicyTrackedResourcesClient)(nil) + +// RemediationsClientAPI contains the set of methods on the RemediationsClient type. +type RemediationsClientAPI interface { + CancelAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string) (result policyinsights.Remediation, err error) + CancelAtResource(ctx context.Context, resourceID string, remediationName string) (result policyinsights.Remediation, err error) + CancelAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (result policyinsights.Remediation, err error) + CancelAtSubscription(ctx context.Context, subscriptionID string, remediationName string) (result policyinsights.Remediation, err error) + CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string, parameters policyinsights.Remediation) (result policyinsights.Remediation, err error) + CreateOrUpdateAtResource(ctx context.Context, resourceID string, remediationName string, parameters policyinsights.Remediation) (result policyinsights.Remediation, err error) + CreateOrUpdateAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, parameters policyinsights.Remediation) (result policyinsights.Remediation, err error) + CreateOrUpdateAtSubscription(ctx context.Context, subscriptionID string, remediationName string, parameters policyinsights.Remediation) (result policyinsights.Remediation, err error) + DeleteAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string) (result policyinsights.Remediation, err error) + DeleteAtResource(ctx context.Context, resourceID string, remediationName string) (result policyinsights.Remediation, err error) + DeleteAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (result policyinsights.Remediation, err error) + DeleteAtSubscription(ctx context.Context, subscriptionID string, remediationName string) (result policyinsights.Remediation, err error) + GetAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string) (result policyinsights.Remediation, err error) + GetAtResource(ctx context.Context, resourceID string, remediationName string) (result policyinsights.Remediation, err error) + GetAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (result policyinsights.Remediation, err error) + GetAtSubscription(ctx context.Context, subscriptionID string, remediationName string) (result policyinsights.Remediation, err error) + ListDeploymentsAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultPage, err error) + ListDeploymentsAtManagementGroupComplete(ctx context.Context, managementGroupID string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultIterator, err error) + ListDeploymentsAtResource(ctx context.Context, resourceID string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultPage, err error) + ListDeploymentsAtResourceComplete(ctx context.Context, resourceID string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultIterator, err error) + ListDeploymentsAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultPage, err error) + ListDeploymentsAtResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultIterator, err error) + ListDeploymentsAtSubscription(ctx context.Context, subscriptionID string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultPage, err error) + ListDeploymentsAtSubscriptionComplete(ctx context.Context, subscriptionID string, remediationName string, top *int32) (result policyinsights.RemediationDeploymentsListResultIterator, err error) + ListForManagementGroup(ctx context.Context, managementGroupID string, top *int32, filter string) (result policyinsights.RemediationListResultPage, err error) + ListForManagementGroupComplete(ctx context.Context, managementGroupID string, top *int32, filter string) (result policyinsights.RemediationListResultIterator, err error) + ListForResource(ctx context.Context, resourceID string, top *int32, filter string) (result policyinsights.RemediationListResultPage, err error) + ListForResourceComplete(ctx context.Context, resourceID string, top *int32, filter string) (result policyinsights.RemediationListResultIterator, err error) + ListForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result policyinsights.RemediationListResultPage, err error) + ListForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result policyinsights.RemediationListResultIterator, err error) + ListForSubscription(ctx context.Context, subscriptionID string, top *int32, filter string) (result policyinsights.RemediationListResultPage, err error) + ListForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, filter string) (result policyinsights.RemediationListResultIterator, err error) +} + +var _ RemediationsClientAPI = (*policyinsights.RemediationsClient)(nil) + +// PolicyEventsClientAPI contains the set of methods on the PolicyEventsClient type. +type PolicyEventsClientAPI interface { + ListQueryResultsForManagementGroup(ctx context.Context, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForManagementGroupComplete(ctx context.Context, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForPolicyDefinition(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForPolicyDefinitionComplete(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForPolicySetDefinition(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForPolicySetDefinitionComplete(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForResource(ctx context.Context, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForResourceComplete(ctx context.Context, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForResourceGroupLevelPolicyAssignment(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForResourceGroupLevelPolicyAssignmentComplete(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForSubscription(ctx context.Context, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) + ListQueryResultsForSubscriptionLevelPolicyAssignment(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsPage, err error) + ListQueryResultsForSubscriptionLevelPolicyAssignmentComplete(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyEventsQueryResultsIterator, err error) +} + +var _ PolicyEventsClientAPI = (*policyinsights.PolicyEventsClient)(nil) + +// PolicyStatesClientAPI contains the set of methods on the PolicyStatesClient type. +type PolicyStatesClientAPI interface { + ListQueryResultsForManagementGroup(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForManagementGroupComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForPolicyDefinition(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForPolicyDefinitionComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForPolicySetDefinition(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForPolicySetDefinitionComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForResource(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForResourceComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForResourceGroup(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForResourceGroupComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForResourceGroupLevelPolicyAssignment(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForResourceGroupLevelPolicyAssignmentComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForSubscription(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForSubscriptionComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + ListQueryResultsForSubscriptionLevelPolicyAssignment(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsPage, err error) + ListQueryResultsForSubscriptionLevelPolicyAssignmentComplete(ctx context.Context, policyStatesResource policyinsights.PolicyStatesResource, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result policyinsights.PolicyStatesQueryResultsIterator, err error) + SummarizeForManagementGroup(ctx context.Context, managementGroupName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForPolicyDefinition(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForPolicySetDefinition(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForResource(ctx context.Context, resourceID string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForResourceGroupLevelPolicyAssignment(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForSubscription(ctx context.Context, subscriptionID string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + SummarizeForSubscriptionLevelPolicyAssignment(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result policyinsights.SummarizeResults, err error) + TriggerResourceGroupEvaluation(ctx context.Context, subscriptionID string, resourceGroupName string) (result policyinsights.PolicyStatesTriggerResourceGroupEvaluationFuture, err error) + TriggerSubscriptionEvaluation(ctx context.Context, subscriptionID string) (result policyinsights.PolicyStatesTriggerSubscriptionEvaluationFuture, err error) +} + +var _ PolicyStatesClientAPI = (*policyinsights.PolicyStatesClient)(nil) + +// OperationsClientAPI contains the set of methods on the OperationsClient type. +type OperationsClientAPI interface { + List(ctx context.Context) (result policyinsights.OperationsListResults, err error) +} + +var _ OperationsClientAPI = (*policyinsights.OperationsClient)(nil) + +// PolicyMetadataClientAPI contains the set of methods on the PolicyMetadataClient type. +type PolicyMetadataClientAPI interface { + GetResource(ctx context.Context, resourceName string) (result policyinsights.PolicyMetadata, err error) + List(ctx context.Context, top *int32) (result policyinsights.PolicyMetadataCollectionPage, err error) + ListComplete(ctx context.Context, top *int32) (result policyinsights.PolicyMetadataCollectionIterator, err error) +} + +var _ PolicyMetadataClientAPI = (*policyinsights.PolicyMetadataClient)(nil) + +// PolicyRestrictionsClientAPI contains the set of methods on the PolicyRestrictionsClient type. +type PolicyRestrictionsClientAPI interface { + CheckAtResourceGroupScope(ctx context.Context, subscriptionID string, resourceGroupName string, parameters policyinsights.CheckRestrictionsRequest) (result policyinsights.CheckRestrictionsResult, err error) + CheckAtSubscriptionScope(ctx context.Context, subscriptionID string, parameters policyinsights.CheckRestrictionsRequest) (result policyinsights.CheckRestrictionsResult, err error) +} + +var _ PolicyRestrictionsClientAPI = (*policyinsights.PolicyRestrictionsClient)(nil) + +// AttestationsClientAPI contains the set of methods on the AttestationsClient type. +type AttestationsClientAPI interface { + CreateOrUpdateAtResource(ctx context.Context, resourceID string, attestationName string, parameters policyinsights.Attestation) (result policyinsights.AttestationsCreateOrUpdateAtResourceFuture, err error) + CreateOrUpdateAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string, parameters policyinsights.Attestation) (result policyinsights.AttestationsCreateOrUpdateAtResourceGroupFuture, err error) + CreateOrUpdateAtSubscription(ctx context.Context, subscriptionID string, attestationName string, parameters policyinsights.Attestation) (result policyinsights.AttestationsCreateOrUpdateAtSubscriptionFuture, err error) + DeleteAtResource(ctx context.Context, resourceID string, attestationName string) (result autorest.Response, err error) + DeleteAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string) (result autorest.Response, err error) + DeleteAtSubscription(ctx context.Context, subscriptionID string, attestationName string) (result autorest.Response, err error) + GetAtResource(ctx context.Context, resourceID string, attestationName string) (result policyinsights.Attestation, err error) + GetAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, attestationName string) (result policyinsights.Attestation, err error) + GetAtSubscription(ctx context.Context, subscriptionID string, attestationName string) (result policyinsights.Attestation, err error) + ListForResource(ctx context.Context, resourceID string, top *int32, filter string) (result policyinsights.AttestationListResultPage, err error) + ListForResourceComplete(ctx context.Context, resourceID string, top *int32, filter string) (result policyinsights.AttestationListResultIterator, err error) + ListForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result policyinsights.AttestationListResultPage, err error) + ListForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result policyinsights.AttestationListResultIterator, err error) + ListForSubscription(ctx context.Context, subscriptionID string, top *int32, filter string) (result policyinsights.AttestationListResultPage, err error) + ListForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, filter string) (result policyinsights.AttestationListResultIterator, err error) +} + +var _ AttestationsClientAPI = (*policyinsights.AttestationsClient)(nil) diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policymetadata.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policymetadata.go new file mode 100644 index 000000000000..4c22d98eeca5 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policymetadata.go @@ -0,0 +1,237 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PolicyMetadataClient is the client for the PolicyMetadata methods of the Policyinsights service. +type PolicyMetadataClient struct { + BaseClient +} + +// NewPolicyMetadataClient creates an instance of the PolicyMetadataClient client. +func NewPolicyMetadataClient(subscriptionID2 string) PolicyMetadataClient { + return NewPolicyMetadataClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewPolicyMetadataClientWithBaseURI creates an instance of the PolicyMetadataClient client using a custom endpoint. +// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewPolicyMetadataClientWithBaseURI(baseURI string, subscriptionID2 string) PolicyMetadataClient { + return PolicyMetadataClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// GetResource get policy metadata resource. +// Parameters: +// resourceName - the name of the policy metadata resource. +func (client PolicyMetadataClient) GetResource(ctx context.Context, resourceName string) (result PolicyMetadata, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyMetadataClient.GetResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetResourcePreparer(ctx, resourceName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "GetResource", nil, "Failure preparing request") + return + } + + resp, err := client.GetResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "GetResource", resp, "Failure sending request") + return + } + + result, err = client.GetResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "GetResource", resp, "Failure responding to request") + return + } + + return +} + +// GetResourcePreparer prepares the GetResource request. +func (client PolicyMetadataClient) GetResourcePreparer(ctx context.Context, resourceName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceName": resourceName, + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.PolicyInsights/policyMetadata/{resourceName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetResourceSender sends the GetResource request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyMetadataClient) GetResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResourceResponder handles the response to the GetResource request. The method always +// closes the http.Response Body. +func (client PolicyMetadataClient) GetResourceResponder(resp *http.Response) (result PolicyMetadata, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List get a list of the policy metadata resources. +// Parameters: +// top - maximum number of records to return. +func (client PolicyMetadataClient) List(ctx context.Context, top *int32) (result PolicyMetadataCollectionPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyMetadataClient.List") + defer func() { + sc := -1 + if result.pmc.Response.Response != nil { + sc = result.pmc.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyMetadataClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, top) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.pmc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "List", resp, "Failure sending request") + return + } + + result.pmc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "List", resp, "Failure responding to request") + return + } + if result.pmc.hasNextLink() && result.pmc.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListPreparer prepares the List request. +func (client PolicyMetadataClient) ListPreparer(ctx context.Context, top *int32) (*http.Request, error) { + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.PolicyInsights/policyMetadata"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyMetadataClient) ListSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client PolicyMetadataClient) ListResponder(resp *http.Response) (result PolicyMetadataCollection, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client PolicyMetadataClient) listNextResults(ctx context.Context, lastResults PolicyMetadataCollection) (result PolicyMetadataCollection, err error) { + req, err := lastResults.policyMetadataCollectionPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyMetadataClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyMetadataClient) ListComplete(ctx context.Context, top *int32) (result PolicyMetadataCollectionIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyMetadataClient.List") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.List(ctx, top) + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyrestrictions.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyrestrictions.go new file mode 100644 index 000000000000..69f071ad5346 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policyrestrictions.go @@ -0,0 +1,221 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PolicyRestrictionsClient is the client for the PolicyRestrictions methods of the Policyinsights service. +type PolicyRestrictionsClient struct { + BaseClient +} + +// NewPolicyRestrictionsClient creates an instance of the PolicyRestrictionsClient client. +func NewPolicyRestrictionsClient(subscriptionID2 string) PolicyRestrictionsClient { + return NewPolicyRestrictionsClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewPolicyRestrictionsClientWithBaseURI creates an instance of the PolicyRestrictionsClient client using a custom +// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure +// stack). +func NewPolicyRestrictionsClientWithBaseURI(baseURI string, subscriptionID2 string) PolicyRestrictionsClient { + return PolicyRestrictionsClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// CheckAtResourceGroupScope checks what restrictions Azure Policy will place on a resource within a resource group. +// Use this when the resource group the resource will be created in is already known. +// Parameters: +// subscriptionID - the ID of the target subscription. +// resourceGroupName - the name of the resource group. The name is case insensitive. +// parameters - the check policy restrictions parameters. +func (client PolicyRestrictionsClient) CheckAtResourceGroupScope(ctx context.Context, subscriptionID string, resourceGroupName string, parameters CheckRestrictionsRequest) (result CheckRestrictionsResult, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyRestrictionsClient.CheckAtResourceGroupScope") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.ResourceDetails", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.ResourceDetails.ResourceContent", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyRestrictionsClient", "CheckAtResourceGroupScope", err.Error()) + } + + req, err := client.CheckAtResourceGroupScopePreparer(ctx, subscriptionID, resourceGroupName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyRestrictionsClient", "CheckAtResourceGroupScope", nil, "Failure preparing request") + return + } + + resp, err := client.CheckAtResourceGroupScopeSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyRestrictionsClient", "CheckAtResourceGroupScope", resp, "Failure sending request") + return + } + + result, err = client.CheckAtResourceGroupScopeResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyRestrictionsClient", "CheckAtResourceGroupScope", resp, "Failure responding to request") + return + } + + return +} + +// CheckAtResourceGroupScopePreparer prepares the CheckAtResourceGroupScope request. +func (client PolicyRestrictionsClient) CheckAtResourceGroupScopePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, parameters CheckRestrictionsRequest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2020-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/checkPolicyRestrictions", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CheckAtResourceGroupScopeSender sends the CheckAtResourceGroupScope request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyRestrictionsClient) CheckAtResourceGroupScopeSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CheckAtResourceGroupScopeResponder handles the response to the CheckAtResourceGroupScope request. The method always +// closes the http.Response Body. +func (client PolicyRestrictionsClient) CheckAtResourceGroupScopeResponder(resp *http.Response) (result CheckRestrictionsResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CheckAtSubscriptionScope checks what restrictions Azure Policy will place on a resource within a subscription. +// Parameters: +// subscriptionID - the ID of the target subscription. +// parameters - the check policy restrictions parameters. +func (client PolicyRestrictionsClient) CheckAtSubscriptionScope(ctx context.Context, subscriptionID string, parameters CheckRestrictionsRequest) (result CheckRestrictionsResult, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyRestrictionsClient.CheckAtSubscriptionScope") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: subscriptionID, + Constraints: []validation.Constraint{{Target: "subscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.ResourceDetails", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.ResourceDetails.ResourceContent", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyRestrictionsClient", "CheckAtSubscriptionScope", err.Error()) + } + + req, err := client.CheckAtSubscriptionScopePreparer(ctx, subscriptionID, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyRestrictionsClient", "CheckAtSubscriptionScope", nil, "Failure preparing request") + return + } + + resp, err := client.CheckAtSubscriptionScopeSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyRestrictionsClient", "CheckAtSubscriptionScope", resp, "Failure sending request") + return + } + + result, err = client.CheckAtSubscriptionScopeResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyRestrictionsClient", "CheckAtSubscriptionScope", resp, "Failure responding to request") + return + } + + return +} + +// CheckAtSubscriptionScopePreparer prepares the CheckAtSubscriptionScope request. +func (client PolicyRestrictionsClient) CheckAtSubscriptionScopePreparer(ctx context.Context, subscriptionID string, parameters CheckRestrictionsRequest) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2020-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/checkPolicyRestrictions", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CheckAtSubscriptionScopeSender sends the CheckAtSubscriptionScope request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyRestrictionsClient) CheckAtSubscriptionScopeSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CheckAtSubscriptionScopeResponder handles the response to the CheckAtSubscriptionScope request. The method always +// closes the http.Response Body. +func (client PolicyRestrictionsClient) CheckAtSubscriptionScopeResponder(resp *http.Response) (result CheckRestrictionsResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policystates.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policystates.go new file mode 100644 index 000000000000..8bb0f9abc801 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policystates.go @@ -0,0 +1,2349 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/date" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PolicyStatesClient is the client for the PolicyStates methods of the Policyinsights service. +type PolicyStatesClient struct { + BaseClient +} + +// NewPolicyStatesClient creates an instance of the PolicyStatesClient client. +func NewPolicyStatesClient(subscriptionID2 string) PolicyStatesClient { + return NewPolicyStatesClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewPolicyStatesClientWithBaseURI creates an instance of the PolicyStatesClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewPolicyStatesClientWithBaseURI(baseURI string, subscriptionID2 string) PolicyStatesClient { + return PolicyStatesClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// ListQueryResultsForManagementGroup queries policy states for the resources under the management group. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// managementGroupName - management group name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForManagementGroup(ctx context.Context, policyStatesResource PolicyStatesResource, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForManagementGroup") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForManagementGroup", err.Error()) + } + + result.fn = client.listQueryResultsForManagementGroupNextResults + req, err := client.ListQueryResultsForManagementGroupPreparer(ctx, policyStatesResource, managementGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForManagementGroupSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForManagementGroup", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForManagementGroup", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForManagementGroupPreparer prepares the ListQueryResultsForManagementGroup request. +func (client PolicyStatesClient) ListQueryResultsForManagementGroupPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupName": autorest.Encode("path", managementGroupName), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "policyStatesResource": autorest.Encode("path", policyStatesResource), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForManagementGroupSender sends the ListQueryResultsForManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListQueryResultsForManagementGroupResponder handles the response to the ListQueryResultsForManagementGroup request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForManagementGroupResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForManagementGroupNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForManagementGroupNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForManagementGroupComplete(ctx context.Context, policyStatesResource PolicyStatesResource, managementGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForManagementGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForManagementGroup(ctx, policyStatesResource, managementGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForPolicyDefinition queries policy states for the subscription level policy definition. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// subscriptionID - microsoft Azure subscription ID. +// policyDefinitionName - policy definition name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForPolicyDefinition(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForPolicyDefinition") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForPolicyDefinition", err.Error()) + } + + result.fn = client.listQueryResultsForPolicyDefinitionNextResults + req, err := client.ListQueryResultsForPolicyDefinitionPreparer(ctx, policyStatesResource, subscriptionID, policyDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForPolicyDefinition", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForPolicyDefinitionSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForPolicyDefinition", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForPolicyDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForPolicyDefinition", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForPolicyDefinitionPreparer prepares the ListQueryResultsForPolicyDefinition request. +func (client PolicyStatesClient) ListQueryResultsForPolicyDefinitionPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyDefinitionName": autorest.Encode("path", policyDefinitionName), + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForPolicyDefinitionSender sends the ListQueryResultsForPolicyDefinition request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForPolicyDefinitionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForPolicyDefinitionResponder handles the response to the ListQueryResultsForPolicyDefinition request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForPolicyDefinitionResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForPolicyDefinitionNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForPolicyDefinitionNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForPolicyDefinitionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForPolicyDefinitionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForPolicyDefinitionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForPolicyDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForPolicyDefinitionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForPolicyDefinitionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForPolicyDefinitionComplete(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policyDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForPolicyDefinition") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForPolicyDefinition(ctx, policyStatesResource, subscriptionID, policyDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForPolicySetDefinition queries policy states for the subscription level policy set definition. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// subscriptionID - microsoft Azure subscription ID. +// policySetDefinitionName - policy set definition name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForPolicySetDefinition(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForPolicySetDefinition") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForPolicySetDefinition", err.Error()) + } + + result.fn = client.listQueryResultsForPolicySetDefinitionNextResults + req, err := client.ListQueryResultsForPolicySetDefinitionPreparer(ctx, policyStatesResource, subscriptionID, policySetDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForPolicySetDefinition", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForPolicySetDefinitionSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForPolicySetDefinition", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForPolicySetDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForPolicySetDefinition", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForPolicySetDefinitionPreparer prepares the ListQueryResultsForPolicySetDefinition request. +func (client PolicyStatesClient) ListQueryResultsForPolicySetDefinitionPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policySetDefinitionName": autorest.Encode("path", policySetDefinitionName), + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForPolicySetDefinitionSender sends the ListQueryResultsForPolicySetDefinition request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForPolicySetDefinitionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForPolicySetDefinitionResponder handles the response to the ListQueryResultsForPolicySetDefinition request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForPolicySetDefinitionResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForPolicySetDefinitionNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForPolicySetDefinitionNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForPolicySetDefinitionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForPolicySetDefinitionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForPolicySetDefinitionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForPolicySetDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForPolicySetDefinitionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForPolicySetDefinitionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForPolicySetDefinitionComplete(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policySetDefinitionName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForPolicySetDefinition") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForPolicySetDefinition(ctx, policyStatesResource, subscriptionID, policySetDefinitionName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForResource queries policy states for the resource. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// resourceID - resource ID. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// expand - the $expand query parameter. For example, to expand components use $expand=components +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForResource(ctx context.Context, policyStatesResource PolicyStatesResource, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForResource") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForResource", err.Error()) + } + + result.fn = client.listQueryResultsForResourceNextResults + req, err := client.ListQueryResultsForResourcePreparer(ctx, policyStatesResource, resourceID, top, orderBy, selectParameter, from, toParameter, filter, apply, expand, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResource", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResource", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResource", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourcePreparer prepares the ListQueryResultsForResource request. +func (client PolicyStatesClient) ListQueryResultsForResourcePreparer(ctx context.Context, policyStatesResource PolicyStatesResource, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "resourceId": resourceID, + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceSender sends the ListQueryResultsForResource request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListQueryResultsForResourceResponder handles the response to the ListQueryResultsForResource request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForResourceResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForResourceNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForResourceComplete(ctx context.Context, policyStatesResource PolicyStatesResource, resourceID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, expand string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForResource") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResource(ctx, policyStatesResource, resourceID, top, orderBy, selectParameter, from, toParameter, filter, apply, expand, skipToken) + return +} + +// ListQueryResultsForResourceGroup queries policy states for the resources under the resource group. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForResourceGroup(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForResourceGroup") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroup", err.Error()) + } + + result.fn = client.listQueryResultsForResourceGroupNextResults + req, err := client.ListQueryResultsForResourceGroupPreparer(ctx, policyStatesResource, subscriptionID, resourceGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceGroupSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroup", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroup", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourceGroupPreparer prepares the ListQueryResultsForResourceGroup request. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceGroupSender sends the ListQueryResultsForResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForResourceGroupResponder handles the response to the ListQueryResultsForResourceGroup request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceGroupNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForResourceGroupNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupComplete(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, resourceGroupName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResourceGroup(ctx, policyStatesResource, subscriptionID, resourceGroupName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignment queries policy states for the resource group level policy +// assignment. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// policyAssignmentName - policy assignment name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupLevelPolicyAssignment(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForResourceGroupLevelPolicyAssignment") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", err.Error()) + } + + result.fn = client.listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults + req, err := client.ListQueryResultsForResourceGroupLevelPolicyAssignmentPreparer(ctx, policyStatesResource, subscriptionID, resourceGroupName, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceGroupLevelPolicyAssignmentSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForResourceGroupLevelPolicyAssignment", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentPreparer prepares the ListQueryResultsForResourceGroupLevelPolicyAssignment request. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyAssignmentName": autorest.Encode("path", policyAssignmentName), + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentSender sends the ListQueryResultsForResourceGroupLevelPolicyAssignment request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder handles the response to the ListQueryResultsForResourceGroupLevelPolicyAssignment request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceGroupLevelPolicyAssignmentSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceGroupLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForResourceGroupLevelPolicyAssignmentNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceGroupLevelPolicyAssignmentComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForResourceGroupLevelPolicyAssignmentComplete(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForResourceGroupLevelPolicyAssignment") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResourceGroupLevelPolicyAssignment(ctx, policyStatesResource, subscriptionID, resourceGroupName, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForSubscription queries policy states for the resources under the subscription. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// subscriptionID - microsoft Azure subscription ID. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForSubscription(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForSubscription") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForSubscription", err.Error()) + } + + result.fn = client.listQueryResultsForSubscriptionNextResults + req, err := client.ListQueryResultsForSubscriptionPreparer(ctx, policyStatesResource, subscriptionID, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForSubscriptionSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForSubscription", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForSubscription", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForSubscriptionPreparer prepares the ListQueryResultsForSubscription request. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForSubscriptionSender sends the ListQueryResultsForSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForSubscriptionResponder handles the response to the ListQueryResultsForSubscription request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForSubscriptionNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForSubscriptionNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForSubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForSubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForSubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionComplete(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForSubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForSubscription(ctx, policyStatesResource, subscriptionID, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignment queries policy states for the subscription level policy +// assignment. +// Parameters: +// policyStatesResource - the virtual resource under PolicyStates resource type. In a given time range, +// 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s). +// subscriptionID - microsoft Azure subscription ID. +// policyAssignmentName - policy assignment name. +// top - maximum number of records to return. +// orderBy - ordering expression using OData notation. One or more comma-separated column names with an +// optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc". +// selectParameter - select expression using OData notation. Limits the columns on each record to just those +// requested, e.g. "$select=PolicyAssignmentId, ResourceId". +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +// apply - oData apply expression for aggregations. +// skipToken - skiptoken is only provided if a previous response returned a partial result as a part of +// nextLink element. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionLevelPolicyAssignment(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForSubscriptionLevelPolicyAssignment") + defer func() { + sc := -1 + if result.psqr.Response.Response != nil { + sc = result.psqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", err.Error()) + } + + result.fn = client.listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults + req, err := client.ListQueryResultsForSubscriptionLevelPolicyAssignmentPreparer(ctx, policyStatesResource, subscriptionID, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForSubscriptionLevelPolicyAssignmentSender(req) + if err != nil { + result.psqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", resp, "Failure sending request") + return + } + + result.psqr, err = client.ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "ListQueryResultsForSubscriptionLevelPolicyAssignment", resp, "Failure responding to request") + return + } + if result.psqr.hasNextLink() && result.psqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentPreparer prepares the ListQueryResultsForSubscriptionLevelPolicyAssignment request. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentPreparer(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyAssignmentName": autorest.Encode("path", policyAssignmentName), + "policyStatesResource": autorest.Encode("path", policyStatesResource), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(orderBy) > 0 { + queryParameters["$orderby"] = autorest.Encode("query", orderBy) + } + if len(selectParameter) > 0 { + queryParameters["$select"] = autorest.Encode("query", selectParameter) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skipToken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skipToken) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentSender sends the ListQueryResultsForSubscriptionLevelPolicyAssignment request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder handles the response to the ListQueryResultsForSubscriptionLevelPolicyAssignment request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder(resp *http.Response) (result PolicyStatesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults retrieves the next set of results, if any. +func (client PolicyStatesClient) listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults(ctx context.Context, lastResults PolicyStatesQueryResults) (result PolicyStatesQueryResults, err error) { + req, err := lastResults.policyStatesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForSubscriptionLevelPolicyAssignmentSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForSubscriptionLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "listQueryResultsForSubscriptionLevelPolicyAssignmentNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForSubscriptionLevelPolicyAssignmentComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyStatesClient) ListQueryResultsForSubscriptionLevelPolicyAssignmentComplete(ctx context.Context, policyStatesResource PolicyStatesResource, subscriptionID string, policyAssignmentName string, top *int32, orderBy string, selectParameter string, from *date.Time, toParameter *date.Time, filter string, apply string, skipToken string) (result PolicyStatesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.ListQueryResultsForSubscriptionLevelPolicyAssignment") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForSubscriptionLevelPolicyAssignment(ctx, policyStatesResource, subscriptionID, policyAssignmentName, top, orderBy, selectParameter, from, toParameter, filter, apply, skipToken) + return +} + +// SummarizeForManagementGroup summarizes policy states for the resources under the management group. +// Parameters: +// managementGroupName - management group name. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForManagementGroup(ctx context.Context, managementGroupName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForManagementGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForManagementGroup", err.Error()) + } + + req, err := client.SummarizeForManagementGroupPreparer(ctx, managementGroupName, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForManagementGroup", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForManagementGroupPreparer prepares the SummarizeForManagementGroup request. +func (client PolicyStatesClient) SummarizeForManagementGroupPreparer(ctx context.Context, managementGroupName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupName": autorest.Encode("path", managementGroupName), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForManagementGroupSender sends the SummarizeForManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// SummarizeForManagementGroupResponder handles the response to the SummarizeForManagementGroup request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForManagementGroupResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForPolicyDefinition summarizes policy states for the subscription level policy definition. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// policyDefinitionName - policy definition name. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForPolicyDefinition(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForPolicyDefinition") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForPolicyDefinition", err.Error()) + } + + req, err := client.SummarizeForPolicyDefinitionPreparer(ctx, subscriptionID, policyDefinitionName, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForPolicyDefinition", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForPolicyDefinitionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForPolicyDefinition", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForPolicyDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForPolicyDefinition", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForPolicyDefinitionPreparer prepares the SummarizeForPolicyDefinition request. +func (client PolicyStatesClient) SummarizeForPolicyDefinitionPreparer(ctx context.Context, subscriptionID string, policyDefinitionName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyDefinitionName": autorest.Encode("path", policyDefinitionName), + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyDefinitions/{policyDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForPolicyDefinitionSender sends the SummarizeForPolicyDefinition request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForPolicyDefinitionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// SummarizeForPolicyDefinitionResponder handles the response to the SummarizeForPolicyDefinition request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForPolicyDefinitionResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForPolicySetDefinition summarizes policy states for the subscription level policy set definition. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// policySetDefinitionName - policy set definition name. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForPolicySetDefinition(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForPolicySetDefinition") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForPolicySetDefinition", err.Error()) + } + + req, err := client.SummarizeForPolicySetDefinitionPreparer(ctx, subscriptionID, policySetDefinitionName, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForPolicySetDefinition", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForPolicySetDefinitionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForPolicySetDefinition", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForPolicySetDefinitionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForPolicySetDefinition", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForPolicySetDefinitionPreparer prepares the SummarizeForPolicySetDefinition request. +func (client PolicyStatesClient) SummarizeForPolicySetDefinitionPreparer(ctx context.Context, subscriptionID string, policySetDefinitionName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policySetDefinitionName": autorest.Encode("path", policySetDefinitionName), + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policySetDefinitions/{policySetDefinitionName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForPolicySetDefinitionSender sends the SummarizeForPolicySetDefinition request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForPolicySetDefinitionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// SummarizeForPolicySetDefinitionResponder handles the response to the SummarizeForPolicySetDefinition request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForPolicySetDefinitionResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForResource summarizes policy states for the resource. +// Parameters: +// resourceID - resource ID. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForResource(ctx context.Context, resourceID string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForResource", err.Error()) + } + + req, err := client.SummarizeForResourcePreparer(ctx, resourceID, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResource", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResource", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResource", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForResourcePreparer prepares the SummarizeForResource request. +func (client PolicyStatesClient) SummarizeForResourcePreparer(ctx context.Context, resourceID string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "resourceId": resourceID, + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForResourceSender sends the SummarizeForResource request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// SummarizeForResourceResponder handles the response to the SummarizeForResource request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForResourceResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForResourceGroup summarizes policy states for the resources under the resource group. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForResourceGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForResourceGroup", err.Error()) + } + + req, err := client.SummarizeForResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForResourceGroupPreparer prepares the SummarizeForResourceGroup request. +func (client PolicyStatesClient) SummarizeForResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForResourceGroupSender sends the SummarizeForResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// SummarizeForResourceGroupResponder handles the response to the SummarizeForResourceGroup request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForResourceGroupResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForResourceGroupLevelPolicyAssignment summarizes policy states for the resource group level policy +// assignment. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// policyAssignmentName - policy assignment name. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForResourceGroupLevelPolicyAssignment(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForResourceGroupLevelPolicyAssignment") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForResourceGroupLevelPolicyAssignment", err.Error()) + } + + req, err := client.SummarizeForResourceGroupLevelPolicyAssignmentPreparer(ctx, subscriptionID, resourceGroupName, policyAssignmentName, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResourceGroupLevelPolicyAssignment", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForResourceGroupLevelPolicyAssignmentSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResourceGroupLevelPolicyAssignment", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForResourceGroupLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForResourceGroupLevelPolicyAssignment", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForResourceGroupLevelPolicyAssignmentPreparer prepares the SummarizeForResourceGroupLevelPolicyAssignment request. +func (client PolicyStatesClient) SummarizeForResourceGroupLevelPolicyAssignmentPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, policyAssignmentName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyAssignmentName": autorest.Encode("path", policyAssignmentName), + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForResourceGroupLevelPolicyAssignmentSender sends the SummarizeForResourceGroupLevelPolicyAssignment request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForResourceGroupLevelPolicyAssignmentSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// SummarizeForResourceGroupLevelPolicyAssignmentResponder handles the response to the SummarizeForResourceGroupLevelPolicyAssignment request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForResourceGroupLevelPolicyAssignmentResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForSubscription summarizes policy states for the resources under the subscription. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForSubscription(ctx context.Context, subscriptionID string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForSubscription") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForSubscription", err.Error()) + } + + req, err := client.SummarizeForSubscriptionPreparer(ctx, subscriptionID, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForSubscription", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForSubscription", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForSubscriptionPreparer prepares the SummarizeForSubscription request. +func (client PolicyStatesClient) SummarizeForSubscriptionPreparer(ctx context.Context, subscriptionID string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForSubscriptionSender sends the SummarizeForSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// SummarizeForSubscriptionResponder handles the response to the SummarizeForSubscription request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForSubscriptionResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// SummarizeForSubscriptionLevelPolicyAssignment summarizes policy states for the subscription level policy assignment. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// policyAssignmentName - policy assignment name. +// top - maximum number of records to return. +// from - ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, +// the service uses ($to - 1-day). +// toParameter - ISO 8601 formatted timestamp specifying the end time of the interval to query. When not +// specified, the service uses request time. +// filter - oData filter expression. +func (client PolicyStatesClient) SummarizeForSubscriptionLevelPolicyAssignment(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (result SummarizeResults, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.SummarizeForSubscriptionLevelPolicyAssignment") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyStatesClient", "SummarizeForSubscriptionLevelPolicyAssignment", err.Error()) + } + + req, err := client.SummarizeForSubscriptionLevelPolicyAssignmentPreparer(ctx, subscriptionID, policyAssignmentName, top, from, toParameter, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForSubscriptionLevelPolicyAssignment", nil, "Failure preparing request") + return + } + + resp, err := client.SummarizeForSubscriptionLevelPolicyAssignmentSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForSubscriptionLevelPolicyAssignment", resp, "Failure sending request") + return + } + + result, err = client.SummarizeForSubscriptionLevelPolicyAssignmentResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "SummarizeForSubscriptionLevelPolicyAssignment", resp, "Failure responding to request") + return + } + + return +} + +// SummarizeForSubscriptionLevelPolicyAssignmentPreparer prepares the SummarizeForSubscriptionLevelPolicyAssignment request. +func (client PolicyStatesClient) SummarizeForSubscriptionLevelPolicyAssignmentPreparer(ctx context.Context, subscriptionID string, policyAssignmentName string, top *int32, from *date.Time, toParameter *date.Time, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "authorizationNamespace": autorest.Encode("path", "Microsoft.Authorization"), + "policyAssignmentName": autorest.Encode("path", policyAssignmentName), + "policyStatesSummaryResource": autorest.Encode("path", "latest"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if from != nil { + queryParameters["$from"] = autorest.Encode("query", *from) + } + if toParameter != nil { + queryParameters["$to"] = autorest.Encode("query", *toParameter) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/{authorizationNamespace}/policyAssignments/{policyAssignmentName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesSummaryResource}/summarize", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// SummarizeForSubscriptionLevelPolicyAssignmentSender sends the SummarizeForSubscriptionLevelPolicyAssignment request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) SummarizeForSubscriptionLevelPolicyAssignmentSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// SummarizeForSubscriptionLevelPolicyAssignmentResponder handles the response to the SummarizeForSubscriptionLevelPolicyAssignment request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) SummarizeForSubscriptionLevelPolicyAssignmentResponder(resp *http.Response) (result SummarizeResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// TriggerResourceGroupEvaluation triggers a policy evaluation scan for all the resources under the resource group. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +func (client PolicyStatesClient) TriggerResourceGroupEvaluation(ctx context.Context, subscriptionID string, resourceGroupName string) (result PolicyStatesTriggerResourceGroupEvaluationFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.TriggerResourceGroupEvaluation") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.TriggerResourceGroupEvaluationPreparer(ctx, subscriptionID, resourceGroupName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "TriggerResourceGroupEvaluation", nil, "Failure preparing request") + return + } + + result, err = client.TriggerResourceGroupEvaluationSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "TriggerResourceGroupEvaluation", nil, "Failure sending request") + return + } + + return +} + +// TriggerResourceGroupEvaluationPreparer prepares the TriggerResourceGroupEvaluation request. +func (client PolicyStatesClient) TriggerResourceGroupEvaluationPreparer(ctx context.Context, subscriptionID string, resourceGroupName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// TriggerResourceGroupEvaluationSender sends the TriggerResourceGroupEvaluation request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) TriggerResourceGroupEvaluationSender(req *http.Request) (future PolicyStatesTriggerResourceGroupEvaluationFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + var azf azure.Future + azf, err = azure.NewFutureFromResponse(resp) + future.FutureAPI = &azf + future.Result = func(client PolicyStatesClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesTriggerResourceGroupEvaluationFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("policyinsights.PolicyStatesTriggerResourceGroupEvaluationFuture") + return + } + ar.Response = future.Response() + return + } + return +} + +// TriggerResourceGroupEvaluationResponder handles the response to the TriggerResourceGroupEvaluation request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) TriggerResourceGroupEvaluationResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// TriggerSubscriptionEvaluation triggers a policy evaluation scan for all the resources under the subscription +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +func (client PolicyStatesClient) TriggerSubscriptionEvaluation(ctx context.Context, subscriptionID string) (result PolicyStatesTriggerSubscriptionEvaluationFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyStatesClient.TriggerSubscriptionEvaluation") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.TriggerSubscriptionEvaluationPreparer(ctx, subscriptionID) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "TriggerSubscriptionEvaluation", nil, "Failure preparing request") + return + } + + result, err = client.TriggerSubscriptionEvaluationSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesClient", "TriggerSubscriptionEvaluation", nil, "Failure sending request") + return + } + + return +} + +// TriggerSubscriptionEvaluationPreparer prepares the TriggerSubscriptionEvaluation request. +func (client PolicyStatesClient) TriggerSubscriptionEvaluationPreparer(ctx context.Context, subscriptionID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-10-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// TriggerSubscriptionEvaluationSender sends the TriggerSubscriptionEvaluation request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyStatesClient) TriggerSubscriptionEvaluationSender(req *http.Request) (future PolicyStatesTriggerSubscriptionEvaluationFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + var azf azure.Future + azf, err = azure.NewFutureFromResponse(resp) + future.FutureAPI = &azf + future.Result = func(client PolicyStatesClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyStatesTriggerSubscriptionEvaluationFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("policyinsights.PolicyStatesTriggerSubscriptionEvaluationFuture") + return + } + ar.Response = future.Response() + return + } + return +} + +// TriggerSubscriptionEvaluationResponder handles the response to the TriggerSubscriptionEvaluation request. The method always +// closes the http.Response Body. +func (client PolicyStatesClient) TriggerSubscriptionEvaluationResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policytrackedresources.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policytrackedresources.go new file mode 100644 index 000000000000..f92a0d46faac --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/policytrackedresources.go @@ -0,0 +1,571 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// PolicyTrackedResourcesClient is the client for the PolicyTrackedResources methods of the Policyinsights service. +type PolicyTrackedResourcesClient struct { + BaseClient +} + +// NewPolicyTrackedResourcesClient creates an instance of the PolicyTrackedResourcesClient client. +func NewPolicyTrackedResourcesClient(subscriptionID2 string) PolicyTrackedResourcesClient { + return NewPolicyTrackedResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewPolicyTrackedResourcesClientWithBaseURI creates an instance of the PolicyTrackedResourcesClient client using a +// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, +// Azure stack). +func NewPolicyTrackedResourcesClientWithBaseURI(baseURI string, subscriptionID2 string) PolicyTrackedResourcesClient { + return PolicyTrackedResourcesClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// ListQueryResultsForManagementGroup queries policy tracked resources under the management group. +// Parameters: +// managementGroupName - management group name. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client PolicyTrackedResourcesClient) ListQueryResultsForManagementGroup(ctx context.Context, managementGroupName string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForManagementGroup") + defer func() { + sc := -1 + if result.ptrqr.Response.Response != nil { + sc = result.ptrqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForManagementGroup", err.Error()) + } + + result.fn = client.listQueryResultsForManagementGroupNextResults + req, err := client.ListQueryResultsForManagementGroupPreparer(ctx, managementGroupName, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForManagementGroupSender(req) + if err != nil { + result.ptrqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForManagementGroup", resp, "Failure sending request") + return + } + + result.ptrqr, err = client.ListQueryResultsForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForManagementGroup", resp, "Failure responding to request") + return + } + if result.ptrqr.hasNextLink() && result.ptrqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForManagementGroupPreparer prepares the ListQueryResultsForManagementGroup request. +func (client PolicyTrackedResourcesClient) ListQueryResultsForManagementGroupPreparer(ctx context.Context, managementGroupName string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupName": autorest.Encode("path", managementGroupName), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "policyTrackedResourcesResource": autorest.Encode("path", "default"), + } + + const APIVersion = "2018-07-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForManagementGroupSender sends the ListQueryResultsForManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyTrackedResourcesClient) ListQueryResultsForManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListQueryResultsForManagementGroupResponder handles the response to the ListQueryResultsForManagementGroup request. The method always +// closes the http.Response Body. +func (client PolicyTrackedResourcesClient) ListQueryResultsForManagementGroupResponder(resp *http.Response) (result PolicyTrackedResourcesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForManagementGroupNextResults retrieves the next set of results, if any. +func (client PolicyTrackedResourcesClient) listQueryResultsForManagementGroupNextResults(ctx context.Context, lastResults PolicyTrackedResourcesQueryResults) (result PolicyTrackedResourcesQueryResults, err error) { + req, err := lastResults.policyTrackedResourcesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyTrackedResourcesClient) ListQueryResultsForManagementGroupComplete(ctx context.Context, managementGroupName string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForManagementGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForManagementGroup(ctx, managementGroupName, top, filter) + return +} + +// ListQueryResultsForResource queries policy tracked resources under the resource. +// Parameters: +// resourceID - resource ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResource(ctx context.Context, resourceID string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForResource") + defer func() { + sc := -1 + if result.ptrqr.Response.Response != nil { + sc = result.ptrqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResource", err.Error()) + } + + result.fn = client.listQueryResultsForResourceNextResults + req, err := client.ListQueryResultsForResourcePreparer(ctx, resourceID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResource", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceSender(req) + if err != nil { + result.ptrqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResource", resp, "Failure sending request") + return + } + + result.ptrqr, err = client.ListQueryResultsForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResource", resp, "Failure responding to request") + return + } + if result.ptrqr.hasNextLink() && result.ptrqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourcePreparer prepares the ListQueryResultsForResource request. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourcePreparer(ctx context.Context, resourceID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyTrackedResourcesResource": autorest.Encode("path", "default"), + "resourceId": resourceID, + } + + const APIVersion = "2018-07-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceSender sends the ListQueryResultsForResource request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListQueryResultsForResourceResponder handles the response to the ListQueryResultsForResource request. The method always +// closes the http.Response Body. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceResponder(resp *http.Response) (result PolicyTrackedResourcesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceNextResults retrieves the next set of results, if any. +func (client PolicyTrackedResourcesClient) listQueryResultsForResourceNextResults(ctx context.Context, lastResults PolicyTrackedResourcesQueryResults) (result PolicyTrackedResourcesQueryResults, err error) { + req, err := lastResults.policyTrackedResourcesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForResourceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForResourceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForResourceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceComplete(ctx context.Context, resourceID string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForResource") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResource(ctx, resourceID, top, filter) + return +} + +// ListQueryResultsForResourceGroup queries policy tracked resources under the resource group. +// Parameters: +// resourceGroupName - resource group name. +// subscriptionID - microsoft Azure subscription ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceGroup(ctx context.Context, resourceGroupName string, subscriptionID string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForResourceGroup") + defer func() { + sc := -1 + if result.ptrqr.Response.Response != nil { + sc = result.ptrqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResourceGroup", err.Error()) + } + + result.fn = client.listQueryResultsForResourceGroupNextResults + req, err := client.ListQueryResultsForResourceGroupPreparer(ctx, resourceGroupName, subscriptionID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForResourceGroupSender(req) + if err != nil { + result.ptrqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResourceGroup", resp, "Failure sending request") + return + } + + result.ptrqr, err = client.ListQueryResultsForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForResourceGroup", resp, "Failure responding to request") + return + } + if result.ptrqr.hasNextLink() && result.ptrqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForResourceGroupPreparer prepares the ListQueryResultsForResourceGroup request. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceGroupPreparer(ctx context.Context, resourceGroupName string, subscriptionID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyTrackedResourcesResource": autorest.Encode("path", "default"), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2018-07-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForResourceGroupSender sends the ListQueryResultsForResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForResourceGroupResponder handles the response to the ListQueryResultsForResourceGroup request. The method always +// closes the http.Response Body. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceGroupResponder(resp *http.Response) (result PolicyTrackedResourcesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForResourceGroupNextResults retrieves the next set of results, if any. +func (client PolicyTrackedResourcesClient) listQueryResultsForResourceGroupNextResults(ctx context.Context, lastResults PolicyTrackedResourcesQueryResults) (result PolicyTrackedResourcesQueryResults, err error) { + req, err := lastResults.policyTrackedResourcesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyTrackedResourcesClient) ListQueryResultsForResourceGroupComplete(ctx context.Context, resourceGroupName string, subscriptionID string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForResourceGroup(ctx, resourceGroupName, subscriptionID, top, filter) + return +} + +// ListQueryResultsForSubscription queries policy tracked resources under the subscription. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client PolicyTrackedResourcesClient) ListQueryResultsForSubscription(ctx context.Context, subscriptionID string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForSubscription") + defer func() { + sc := -1 + if result.ptrqr.Response.Response != nil { + sc = result.ptrqr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForSubscription", err.Error()) + } + + result.fn = client.listQueryResultsForSubscriptionNextResults + req, err := client.ListQueryResultsForSubscriptionPreparer(ctx, subscriptionID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListQueryResultsForSubscriptionSender(req) + if err != nil { + result.ptrqr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForSubscription", resp, "Failure sending request") + return + } + + result.ptrqr, err = client.ListQueryResultsForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "ListQueryResultsForSubscription", resp, "Failure responding to request") + return + } + if result.ptrqr.hasNextLink() && result.ptrqr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListQueryResultsForSubscriptionPreparer prepares the ListQueryResultsForSubscription request. +func (client PolicyTrackedResourcesClient) ListQueryResultsForSubscriptionPreparer(ctx context.Context, subscriptionID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "policyTrackedResourcesResource": autorest.Encode("path", "default"), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2018-07-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListQueryResultsForSubscriptionSender sends the ListQueryResultsForSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client PolicyTrackedResourcesClient) ListQueryResultsForSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListQueryResultsForSubscriptionResponder handles the response to the ListQueryResultsForSubscription request. The method always +// closes the http.Response Body. +func (client PolicyTrackedResourcesClient) ListQueryResultsForSubscriptionResponder(resp *http.Response) (result PolicyTrackedResourcesQueryResults, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listQueryResultsForSubscriptionNextResults retrieves the next set of results, if any. +func (client PolicyTrackedResourcesClient) listQueryResultsForSubscriptionNextResults(ctx context.Context, lastResults PolicyTrackedResourcesQueryResults) (result PolicyTrackedResourcesQueryResults, err error) { + req, err := lastResults.policyTrackedResourcesQueryResultsPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForSubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListQueryResultsForSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForSubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListQueryResultsForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.PolicyTrackedResourcesClient", "listQueryResultsForSubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListQueryResultsForSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client PolicyTrackedResourcesClient) ListQueryResultsForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, filter string) (result PolicyTrackedResourcesQueryResultsIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/PolicyTrackedResourcesClient.ListQueryResultsForSubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListQueryResultsForSubscription(ctx, subscriptionID, top, filter) + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/remediations.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/remediations.go new file mode 100644 index 000000000000..f48d2e554a33 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/remediations.go @@ -0,0 +1,2317 @@ +package policyinsights + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// RemediationsClient is the client for the Remediations methods of the Policyinsights service. +type RemediationsClient struct { + BaseClient +} + +// NewRemediationsClient creates an instance of the RemediationsClient client. +func NewRemediationsClient(subscriptionID2 string) RemediationsClient { + return NewRemediationsClientWithBaseURI(DefaultBaseURI, subscriptionID2) +} + +// NewRemediationsClientWithBaseURI creates an instance of the RemediationsClient client using a custom endpoint. Use +// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). +func NewRemediationsClientWithBaseURI(baseURI string, subscriptionID2 string) RemediationsClient { + return RemediationsClient{NewWithBaseURI(baseURI, subscriptionID2)} +} + +// CancelAtManagementGroup cancels a remediation at management group scope. +// Parameters: +// managementGroupID - management group ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) CancelAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CancelAtManagementGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CancelAtManagementGroupPreparer(ctx, managementGroupID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.CancelAtManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.CancelAtManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtManagementGroup", resp, "Failure responding to request") + return + } + + return +} + +// CancelAtManagementGroupPreparer prepares the CancelAtManagementGroup request. +func (client RemediationsClient) CancelAtManagementGroupPreparer(ctx context.Context, managementGroupID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "remediationName": autorest.Encode("path", remediationName), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CancelAtManagementGroupSender sends the CancelAtManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CancelAtManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CancelAtManagementGroupResponder handles the response to the CancelAtManagementGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CancelAtManagementGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CancelAtResource cancel a remediation at resource scope. +// Parameters: +// resourceID - resource ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) CancelAtResource(ctx context.Context, resourceID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CancelAtResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CancelAtResourcePreparer(ctx, resourceID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.CancelAtResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtResource", resp, "Failure sending request") + return + } + + result, err = client.CancelAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtResource", resp, "Failure responding to request") + return + } + + return +} + +// CancelAtResourcePreparer prepares the CancelAtResource request. +func (client RemediationsClient) CancelAtResourcePreparer(ctx context.Context, resourceID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceId": resourceID, + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CancelAtResourceSender sends the CancelAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CancelAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CancelAtResourceResponder handles the response to the CancelAtResource request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CancelAtResourceResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CancelAtResourceGroup cancels a remediation at resource group scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// remediationName - the name of the remediation. +func (client RemediationsClient) CancelAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CancelAtResourceGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CancelAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.CancelAtResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.CancelAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// CancelAtResourceGroupPreparer prepares the CancelAtResourceGroup request. +func (client RemediationsClient) CancelAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CancelAtResourceGroupSender sends the CancelAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CancelAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CancelAtResourceGroupResponder handles the response to the CancelAtResourceGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CancelAtResourceGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CancelAtSubscription cancels a remediation at subscription scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) CancelAtSubscription(ctx context.Context, subscriptionID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CancelAtSubscription") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CancelAtSubscriptionPreparer(ctx, subscriptionID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.CancelAtSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtSubscription", resp, "Failure sending request") + return + } + + result, err = client.CancelAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CancelAtSubscription", resp, "Failure responding to request") + return + } + + return +} + +// CancelAtSubscriptionPreparer prepares the CancelAtSubscription request. +func (client RemediationsClient) CancelAtSubscriptionPreparer(ctx context.Context, subscriptionID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CancelAtSubscriptionSender sends the CancelAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CancelAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CancelAtSubscriptionResponder handles the response to the CancelAtSubscription request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CancelAtSubscriptionResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdateAtManagementGroup creates or updates a remediation at management group scope. +// Parameters: +// managementGroupID - management group ID. +// remediationName - the name of the remediation. +// parameters - the remediation parameters. +func (client RemediationsClient) CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string, parameters Remediation) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CreateOrUpdateAtManagementGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdateAtManagementGroupPreparer(ctx, managementGroupID, remediationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateAtManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateAtManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtManagementGroup", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdateAtManagementGroupPreparer prepares the CreateOrUpdateAtManagementGroup request. +func (client RemediationsClient) CreateOrUpdateAtManagementGroupPreparer(ctx context.Context, managementGroupID string, remediationName string, parameters Remediation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "remediationName": autorest.Encode("path", remediationName), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ID = nil + parameters.Type = nil + parameters.Name = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtManagementGroupSender sends the CreateOrUpdateAtManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CreateOrUpdateAtManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateOrUpdateAtManagementGroupResponder handles the response to the CreateOrUpdateAtManagementGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CreateOrUpdateAtManagementGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdateAtResource creates or updates a remediation at resource scope. +// Parameters: +// resourceID - resource ID. +// remediationName - the name of the remediation. +// parameters - the remediation parameters. +func (client RemediationsClient) CreateOrUpdateAtResource(ctx context.Context, resourceID string, remediationName string, parameters Remediation) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CreateOrUpdateAtResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdateAtResourcePreparer(ctx, resourceID, remediationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateAtResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtResource", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtResource", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdateAtResourcePreparer prepares the CreateOrUpdateAtResource request. +func (client RemediationsClient) CreateOrUpdateAtResourcePreparer(ctx context.Context, resourceID string, remediationName string, parameters Remediation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceId": resourceID, + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ID = nil + parameters.Type = nil + parameters.Name = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtResourceSender sends the CreateOrUpdateAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CreateOrUpdateAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateOrUpdateAtResourceResponder handles the response to the CreateOrUpdateAtResource request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CreateOrUpdateAtResourceResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdateAtResourceGroup creates or updates a remediation at resource group scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// remediationName - the name of the remediation. +// parameters - the remediation parameters. +func (client RemediationsClient) CreateOrUpdateAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, parameters Remediation) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CreateOrUpdateAtResourceGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdateAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, remediationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateAtResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdateAtResourceGroupPreparer prepares the CreateOrUpdateAtResourceGroup request. +func (client RemediationsClient) CreateOrUpdateAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, parameters Remediation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ID = nil + parameters.Type = nil + parameters.Name = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtResourceGroupSender sends the CreateOrUpdateAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CreateOrUpdateAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateAtResourceGroupResponder handles the response to the CreateOrUpdateAtResourceGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CreateOrUpdateAtResourceGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// CreateOrUpdateAtSubscription creates or updates a remediation at subscription scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// remediationName - the name of the remediation. +// parameters - the remediation parameters. +func (client RemediationsClient) CreateOrUpdateAtSubscription(ctx context.Context, subscriptionID string, remediationName string, parameters Remediation) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.CreateOrUpdateAtSubscription") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.CreateOrUpdateAtSubscriptionPreparer(ctx, subscriptionID, remediationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateAtSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtSubscription", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "CreateOrUpdateAtSubscription", resp, "Failure responding to request") + return + } + + return +} + +// CreateOrUpdateAtSubscriptionPreparer prepares the CreateOrUpdateAtSubscription request. +func (client RemediationsClient) CreateOrUpdateAtSubscriptionPreparer(ctx context.Context, subscriptionID string, remediationName string, parameters Remediation) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.ID = nil + parameters.Type = nil + parameters.Name = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateAtSubscriptionSender sends the CreateOrUpdateAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) CreateOrUpdateAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateAtSubscriptionResponder handles the response to the CreateOrUpdateAtSubscription request. The method always +// closes the http.Response Body. +func (client RemediationsClient) CreateOrUpdateAtSubscriptionResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DeleteAtManagementGroup deletes an existing remediation at management group scope. +// Parameters: +// managementGroupID - management group ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) DeleteAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.DeleteAtManagementGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeleteAtManagementGroupPreparer(ctx, managementGroupID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtManagementGroup", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtManagementGroupPreparer prepares the DeleteAtManagementGroup request. +func (client RemediationsClient) DeleteAtManagementGroupPreparer(ctx context.Context, managementGroupID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "remediationName": autorest.Encode("path", remediationName), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtManagementGroupSender sends the DeleteAtManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) DeleteAtManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteAtManagementGroupResponder handles the response to the DeleteAtManagementGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) DeleteAtManagementGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DeleteAtResource deletes an existing remediation at individual resource scope. +// Parameters: +// resourceID - resource ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) DeleteAtResource(ctx context.Context, resourceID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.DeleteAtResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeleteAtResourcePreparer(ctx, resourceID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtResource", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtResource", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtResourcePreparer prepares the DeleteAtResource request. +func (client RemediationsClient) DeleteAtResourcePreparer(ctx context.Context, resourceID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceId": resourceID, + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtResourceSender sends the DeleteAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) DeleteAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteAtResourceResponder handles the response to the DeleteAtResource request. The method always +// closes the http.Response Body. +func (client RemediationsClient) DeleteAtResourceResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DeleteAtResourceGroup deletes an existing remediation at resource group scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// remediationName - the name of the remediation. +func (client RemediationsClient) DeleteAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.DeleteAtResourceGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeleteAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtResourceGroupPreparer prepares the DeleteAtResourceGroup request. +func (client RemediationsClient) DeleteAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtResourceGroupSender sends the DeleteAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) DeleteAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteAtResourceGroupResponder handles the response to the DeleteAtResourceGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) DeleteAtResourceGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// DeleteAtSubscription deletes an existing remediation at subscription scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) DeleteAtSubscription(ctx context.Context, subscriptionID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.DeleteAtSubscription") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeleteAtSubscriptionPreparer(ctx, subscriptionID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteAtSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtSubscription", resp, "Failure sending request") + return + } + + result, err = client.DeleteAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "DeleteAtSubscription", resp, "Failure responding to request") + return + } + + return +} + +// DeleteAtSubscriptionPreparer prepares the DeleteAtSubscription request. +func (client RemediationsClient) DeleteAtSubscriptionPreparer(ctx context.Context, subscriptionID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteAtSubscriptionSender sends the DeleteAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) DeleteAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteAtSubscriptionResponder handles the response to the DeleteAtSubscription request. The method always +// closes the http.Response Body. +func (client RemediationsClient) DeleteAtSubscriptionResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAtManagementGroup gets an existing remediation at management group scope. +// Parameters: +// managementGroupID - management group ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) GetAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.GetAtManagementGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAtManagementGroupPreparer(ctx, managementGroupID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.GetAtManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtManagementGroup", resp, "Failure responding to request") + return + } + + return +} + +// GetAtManagementGroupPreparer prepares the GetAtManagementGroup request. +func (client RemediationsClient) GetAtManagementGroupPreparer(ctx context.Context, managementGroupID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "remediationName": autorest.Encode("path", remediationName), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtManagementGroupSender sends the GetAtManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) GetAtManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetAtManagementGroupResponder handles the response to the GetAtManagementGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) GetAtManagementGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAtResource gets an existing remediation at resource scope. +// Parameters: +// resourceID - resource ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) GetAtResource(ctx context.Context, resourceID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.GetAtResource") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAtResourcePreparer(ctx, resourceID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtResource", resp, "Failure sending request") + return + } + + result, err = client.GetAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtResource", resp, "Failure responding to request") + return + } + + return +} + +// GetAtResourcePreparer prepares the GetAtResource request. +func (client RemediationsClient) GetAtResourcePreparer(ctx context.Context, resourceID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceId": resourceID, + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtResourceSender sends the GetAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) GetAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetAtResourceResponder handles the response to the GetAtResource request. The method always +// closes the http.Response Body. +func (client RemediationsClient) GetAtResourceResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAtResourceGroup gets an existing remediation at resource group scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// remediationName - the name of the remediation. +func (client RemediationsClient) GetAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.GetAtResourceGroup") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtResourceGroup", resp, "Failure sending request") + return + } + + result, err = client.GetAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtResourceGroup", resp, "Failure responding to request") + return + } + + return +} + +// GetAtResourceGroupPreparer prepares the GetAtResourceGroup request. +func (client RemediationsClient) GetAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtResourceGroupSender sends the GetAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) GetAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetAtResourceGroupResponder handles the response to the GetAtResourceGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) GetAtResourceGroupResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetAtSubscription gets an existing remediation at subscription scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// remediationName - the name of the remediation. +func (client RemediationsClient) GetAtSubscription(ctx context.Context, subscriptionID string, remediationName string) (result Remediation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.GetAtSubscription") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetAtSubscriptionPreparer(ctx, subscriptionID, remediationName) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.GetAtSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtSubscription", resp, "Failure sending request") + return + } + + result, err = client.GetAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "GetAtSubscription", resp, "Failure responding to request") + return + } + + return +} + +// GetAtSubscriptionPreparer prepares the GetAtSubscription request. +func (client RemediationsClient) GetAtSubscriptionPreparer(ctx context.Context, subscriptionID string, remediationName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetAtSubscriptionSender sends the GetAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) GetAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// GetAtSubscriptionResponder handles the response to the GetAtSubscription request. The method always +// closes the http.Response Body. +func (client RemediationsClient) GetAtSubscriptionResponder(resp *http.Response) (result Remediation, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListDeploymentsAtManagementGroup gets all deployments for a remediation at management group scope. +// Parameters: +// managementGroupID - management group ID. +// remediationName - the name of the remediation. +// top - maximum number of records to return. +func (client RemediationsClient) ListDeploymentsAtManagementGroup(ctx context.Context, managementGroupID string, remediationName string, top *int32) (result RemediationDeploymentsListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtManagementGroup") + defer func() { + sc := -1 + if result.rdlr.Response.Response != nil { + sc = result.rdlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListDeploymentsAtManagementGroup", err.Error()) + } + + result.fn = client.listDeploymentsAtManagementGroupNextResults + req, err := client.ListDeploymentsAtManagementGroupPreparer(ctx, managementGroupID, remediationName, top) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListDeploymentsAtManagementGroupSender(req) + if err != nil { + result.rdlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtManagementGroup", resp, "Failure sending request") + return + } + + result.rdlr, err = client.ListDeploymentsAtManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtManagementGroup", resp, "Failure responding to request") + return + } + if result.rdlr.hasNextLink() && result.rdlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListDeploymentsAtManagementGroupPreparer prepares the ListDeploymentsAtManagementGroup request. +func (client RemediationsClient) ListDeploymentsAtManagementGroupPreparer(ctx context.Context, managementGroupID string, remediationName string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + "remediationName": autorest.Encode("path", remediationName), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListDeploymentsAtManagementGroupSender sends the ListDeploymentsAtManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListDeploymentsAtManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListDeploymentsAtManagementGroupResponder handles the response to the ListDeploymentsAtManagementGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListDeploymentsAtManagementGroupResponder(resp *http.Response) (result RemediationDeploymentsListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listDeploymentsAtManagementGroupNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listDeploymentsAtManagementGroupNextResults(ctx context.Context, lastResults RemediationDeploymentsListResult) (result RemediationDeploymentsListResult, err error) { + req, err := lastResults.remediationDeploymentsListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListDeploymentsAtManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListDeploymentsAtManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListDeploymentsAtManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListDeploymentsAtManagementGroupComplete(ctx context.Context, managementGroupID string, remediationName string, top *int32) (result RemediationDeploymentsListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtManagementGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListDeploymentsAtManagementGroup(ctx, managementGroupID, remediationName, top) + return +} + +// ListDeploymentsAtResource gets all deployments for a remediation at resource scope. +// Parameters: +// resourceID - resource ID. +// remediationName - the name of the remediation. +// top - maximum number of records to return. +func (client RemediationsClient) ListDeploymentsAtResource(ctx context.Context, resourceID string, remediationName string, top *int32) (result RemediationDeploymentsListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtResource") + defer func() { + sc := -1 + if result.rdlr.Response.Response != nil { + sc = result.rdlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListDeploymentsAtResource", err.Error()) + } + + result.fn = client.listDeploymentsAtResourceNextResults + req, err := client.ListDeploymentsAtResourcePreparer(ctx, resourceID, remediationName, top) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtResource", nil, "Failure preparing request") + return + } + + resp, err := client.ListDeploymentsAtResourceSender(req) + if err != nil { + result.rdlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtResource", resp, "Failure sending request") + return + } + + result.rdlr, err = client.ListDeploymentsAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtResource", resp, "Failure responding to request") + return + } + if result.rdlr.hasNextLink() && result.rdlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListDeploymentsAtResourcePreparer prepares the ListDeploymentsAtResource request. +func (client RemediationsClient) ListDeploymentsAtResourcePreparer(ctx context.Context, resourceID string, remediationName string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceId": resourceID, + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListDeploymentsAtResourceSender sends the ListDeploymentsAtResource request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListDeploymentsAtResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListDeploymentsAtResourceResponder handles the response to the ListDeploymentsAtResource request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListDeploymentsAtResourceResponder(resp *http.Response) (result RemediationDeploymentsListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listDeploymentsAtResourceNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listDeploymentsAtResourceNextResults(ctx context.Context, lastResults RemediationDeploymentsListResult) (result RemediationDeploymentsListResult, err error) { + req, err := lastResults.remediationDeploymentsListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtResourceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListDeploymentsAtResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtResourceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListDeploymentsAtResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtResourceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListDeploymentsAtResourceComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListDeploymentsAtResourceComplete(ctx context.Context, resourceID string, remediationName string, top *int32) (result RemediationDeploymentsListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtResource") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListDeploymentsAtResource(ctx, resourceID, remediationName, top) + return +} + +// ListDeploymentsAtResourceGroup gets all deployments for a remediation at resource group scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// remediationName - the name of the remediation. +// top - maximum number of records to return. +func (client RemediationsClient) ListDeploymentsAtResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, top *int32) (result RemediationDeploymentsListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtResourceGroup") + defer func() { + sc := -1 + if result.rdlr.Response.Response != nil { + sc = result.rdlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListDeploymentsAtResourceGroup", err.Error()) + } + + result.fn = client.listDeploymentsAtResourceGroupNextResults + req, err := client.ListDeploymentsAtResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, remediationName, top) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListDeploymentsAtResourceGroupSender(req) + if err != nil { + result.rdlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtResourceGroup", resp, "Failure sending request") + return + } + + result.rdlr, err = client.ListDeploymentsAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtResourceGroup", resp, "Failure responding to request") + return + } + if result.rdlr.hasNextLink() && result.rdlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListDeploymentsAtResourceGroupPreparer prepares the ListDeploymentsAtResourceGroup request. +func (client RemediationsClient) ListDeploymentsAtResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListDeploymentsAtResourceGroupSender sends the ListDeploymentsAtResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListDeploymentsAtResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListDeploymentsAtResourceGroupResponder handles the response to the ListDeploymentsAtResourceGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListDeploymentsAtResourceGroupResponder(resp *http.Response) (result RemediationDeploymentsListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listDeploymentsAtResourceGroupNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listDeploymentsAtResourceGroupNextResults(ctx context.Context, lastResults RemediationDeploymentsListResult) (result RemediationDeploymentsListResult, err error) { + req, err := lastResults.remediationDeploymentsListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListDeploymentsAtResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListDeploymentsAtResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListDeploymentsAtResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListDeploymentsAtResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, remediationName string, top *int32) (result RemediationDeploymentsListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListDeploymentsAtResourceGroup(ctx, subscriptionID, resourceGroupName, remediationName, top) + return +} + +// ListDeploymentsAtSubscription gets all deployments for a remediation at subscription scope. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// remediationName - the name of the remediation. +// top - maximum number of records to return. +func (client RemediationsClient) ListDeploymentsAtSubscription(ctx context.Context, subscriptionID string, remediationName string, top *int32) (result RemediationDeploymentsListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtSubscription") + defer func() { + sc := -1 + if result.rdlr.Response.Response != nil { + sc = result.rdlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListDeploymentsAtSubscription", err.Error()) + } + + result.fn = client.listDeploymentsAtSubscriptionNextResults + req, err := client.ListDeploymentsAtSubscriptionPreparer(ctx, subscriptionID, remediationName, top) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListDeploymentsAtSubscriptionSender(req) + if err != nil { + result.rdlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtSubscription", resp, "Failure sending request") + return + } + + result.rdlr, err = client.ListDeploymentsAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListDeploymentsAtSubscription", resp, "Failure responding to request") + return + } + if result.rdlr.hasNextLink() && result.rdlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListDeploymentsAtSubscriptionPreparer prepares the ListDeploymentsAtSubscription request. +func (client RemediationsClient) ListDeploymentsAtSubscriptionPreparer(ctx context.Context, subscriptionID string, remediationName string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "remediationName": autorest.Encode("path", remediationName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListDeploymentsAtSubscriptionSender sends the ListDeploymentsAtSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListDeploymentsAtSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListDeploymentsAtSubscriptionResponder handles the response to the ListDeploymentsAtSubscription request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListDeploymentsAtSubscriptionResponder(resp *http.Response) (result RemediationDeploymentsListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listDeploymentsAtSubscriptionNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listDeploymentsAtSubscriptionNextResults(ctx context.Context, lastResults RemediationDeploymentsListResult) (result RemediationDeploymentsListResult, err error) { + req, err := lastResults.remediationDeploymentsListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtSubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListDeploymentsAtSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtSubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListDeploymentsAtSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listDeploymentsAtSubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListDeploymentsAtSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListDeploymentsAtSubscriptionComplete(ctx context.Context, subscriptionID string, remediationName string, top *int32) (result RemediationDeploymentsListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListDeploymentsAtSubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListDeploymentsAtSubscription(ctx, subscriptionID, remediationName, top) + return +} + +// ListForManagementGroup gets all remediations for the management group. +// Parameters: +// managementGroupID - management group ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client RemediationsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, top *int32, filter string) (result RemediationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForManagementGroup") + defer func() { + sc := -1 + if result.rlr.Response.Response != nil { + sc = result.rlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListForManagementGroup", err.Error()) + } + + result.fn = client.listForManagementGroupNextResults + req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListForManagementGroupSender(req) + if err != nil { + result.rlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForManagementGroup", resp, "Failure sending request") + return + } + + result.rlr, err = client.ListForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForManagementGroup", resp, "Failure responding to request") + return + } + if result.rlr.hasNextLink() && result.rlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForManagementGroupPreparer prepares the ListForManagementGroup request. +func (client RemediationsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + "managementGroupsNamespace": autorest.Encode("path", "Microsoft.Management"), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers/Microsoft.PolicyInsights/remediations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForManagementGroupSender sends the ListForManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListForManagementGroupResponder handles the response to the ListForManagementGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListForManagementGroupResponder(resp *http.Response) (result RemediationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForManagementGroupNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listForManagementGroupNextResults(ctx context.Context, lastResults RemediationListResult) (result RemediationListResult, err error) { + req, err := lastResults.remediationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, top *int32, filter string) (result RemediationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForManagementGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForManagementGroup(ctx, managementGroupID, top, filter) + return +} + +// ListForResource gets all remediations for a resource. +// Parameters: +// resourceID - resource ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client RemediationsClient) ListForResource(ctx context.Context, resourceID string, top *int32, filter string) (result RemediationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForResource") + defer func() { + sc := -1 + if result.rlr.Response.Response != nil { + sc = result.rlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListForResource", err.Error()) + } + + result.fn = client.listForResourceNextResults + req, err := client.ListForResourcePreparer(ctx, resourceID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForResource", nil, "Failure preparing request") + return + } + + resp, err := client.ListForResourceSender(req) + if err != nil { + result.rlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForResource", resp, "Failure sending request") + return + } + + result.rlr, err = client.ListForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForResource", resp, "Failure responding to request") + return + } + if result.rlr.hasNextLink() && result.rlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForResourcePreparer prepares the ListForResource request. +func (client RemediationsClient) ListForResourcePreparer(ctx context.Context, resourceID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceId": resourceID, + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{resourceId}/providers/Microsoft.PolicyInsights/remediations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForResourceSender sends the ListForResource request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListForResourceSender(req *http.Request) (*http.Response, error) { + return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListForResourceResponder handles the response to the ListForResource request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListForResourceResponder(resp *http.Response) (result RemediationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForResourceNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listForResourceNextResults(ctx context.Context, lastResults RemediationListResult) (result RemediationListResult, err error) { + req, err := lastResults.remediationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForResourceNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForResourceSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForResourceNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForResourceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForResourceNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForResourceComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListForResourceComplete(ctx context.Context, resourceID string, top *int32, filter string) (result RemediationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForResource") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForResource(ctx, resourceID, top, filter) + return +} + +// ListForResourceGroup gets all remediations for the subscription. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// resourceGroupName - resource group name. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client RemediationsClient) ListForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result RemediationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForResourceGroup") + defer func() { + sc := -1 + if result.rlr.Response.Response != nil { + sc = result.rlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListForResourceGroup", err.Error()) + } + + result.fn = client.listForResourceGroupNextResults + req, err := client.ListForResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForResourceGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListForResourceGroupSender(req) + if err != nil { + result.rlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForResourceGroup", resp, "Failure sending request") + return + } + + result.rlr, err = client.ListForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForResourceGroup", resp, "Failure responding to request") + return + } + if result.rlr.hasNextLink() && result.rlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForResourceGroupPreparer prepares the ListForResourceGroup request. +func (client RemediationsClient) ListForResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/remediations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForResourceGroupSender sends the ListForResourceGroup request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListForResourceGroupResponder handles the response to the ListForResourceGroup request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListForResourceGroupResponder(resp *http.Response) (result RemediationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForResourceGroupNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listForResourceGroupNextResults(ctx context.Context, lastResults RemediationListResult) (result RemediationListResult, err error) { + req, err := lastResults.remediationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForResourceGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForResourceGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, top *int32, filter string) (result RemediationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForResourceGroup") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForResourceGroup(ctx, subscriptionID, resourceGroupName, top, filter) + return +} + +// ListForSubscription gets all remediations for the subscription. +// Parameters: +// subscriptionID - microsoft Azure subscription ID. +// top - maximum number of records to return. +// filter - oData filter expression. +func (client RemediationsClient) ListForSubscription(ctx context.Context, subscriptionID string, top *int32, filter string) (result RemediationListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForSubscription") + defer func() { + sc := -1 + if result.rlr.Response.Response != nil { + sc = result.rlr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}}}}}); err != nil { + return result, validation.NewError("policyinsights.RemediationsClient", "ListForSubscription", err.Error()) + } + + result.fn = client.listForSubscriptionNextResults + req, err := client.ListForSubscriptionPreparer(ctx, subscriptionID, top, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForSubscription", nil, "Failure preparing request") + return + } + + resp, err := client.ListForSubscriptionSender(req) + if err != nil { + result.rlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForSubscription", resp, "Failure sending request") + return + } + + result.rlr, err = client.ListForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "ListForSubscription", resp, "Failure responding to request") + return + } + if result.rlr.hasNextLink() && result.rlr.IsEmpty() { + err = result.NextWithContext(ctx) + return + } + + return +} + +// ListForSubscriptionPreparer prepares the ListForSubscription request. +func (client RemediationsClient) ListForSubscriptionPreparer(ctx context.Context, subscriptionID string, top *int32, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", subscriptionID), + } + + const APIVersion = "2019-07-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForSubscriptionSender sends the ListForSubscription request. The method will close the +// http.Response Body if it receives an error. +func (client RemediationsClient) ListForSubscriptionSender(req *http.Request) (*http.Response, error) { + return client.Send(req, azure.DoRetryWithRegistration(client.Client)) +} + +// ListForSubscriptionResponder handles the response to the ListForSubscription request. The method always +// closes the http.Response Body. +func (client RemediationsClient) ListForSubscriptionResponder(resp *http.Response) (result RemediationListResult, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForSubscriptionNextResults retrieves the next set of results, if any. +func (client RemediationsClient) listForSubscriptionNextResults(ctx context.Context, lastResults RemediationListResult) (result RemediationListResult, err error) { + req, err := lastResults.remediationListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForSubscriptionNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForSubscriptionSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForSubscriptionNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForSubscriptionResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "policyinsights.RemediationsClient", "listForSubscriptionNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForSubscriptionComplete enumerates all values, automatically crossing page boundaries as required. +func (client RemediationsClient) ListForSubscriptionComplete(ctx context.Context, subscriptionID string, top *int32, filter string) (result RemediationListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/RemediationsClient.ListForSubscription") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListForSubscription(ctx, subscriptionID, top, filter) + return +} diff --git a/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/version.go b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/version.go new file mode 100644 index 000000000000..215a7a34c4a1 --- /dev/null +++ b/services/preview/policyinsights/mgmt/2021-01-01-preview/policyinsights/version.go @@ -0,0 +1,30 @@ +package policyinsights + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + Version() + " policyinsights/2021-01-01-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +}