diff --git a/profiles/latest/policyinsights/mgmt/policyinsights/models.go b/profiles/latest/policyinsights/mgmt/policyinsights/models.go index 792fa9b13ca8..9861c54b8df7 100644 --- a/profiles/latest/policyinsights/mgmt/policyinsights/models.go +++ b/profiles/latest/policyinsights/mgmt/policyinsights/models.go @@ -54,6 +54,13 @@ type PolicyEvent = original.PolicyEvent type PolicyEventsClient = original.PolicyEventsClient type PolicyEventsQueryResults = original.PolicyEventsQueryResults type PolicyGroupSummary = original.PolicyGroupSummary +type PolicyMetadata = original.PolicyMetadata +type PolicyMetadataClient = original.PolicyMetadataClient +type PolicyMetadataCollection = original.PolicyMetadataCollection +type PolicyMetadataCollectionIterator = original.PolicyMetadataCollectionIterator +type PolicyMetadataCollectionPage = original.PolicyMetadataCollectionPage +type PolicyMetadataProperties = original.PolicyMetadataProperties +type PolicyMetadataSlimProperties = original.PolicyMetadataSlimProperties type PolicyState = original.PolicyState type PolicyStatesClient = original.PolicyStatesClient type PolicyStatesQueryResults = original.PolicyStatesQueryResults @@ -76,6 +83,7 @@ type RemediationListResultIterator = original.RemediationListResultIterator type RemediationListResultPage = original.RemediationListResultPage type RemediationProperties = original.RemediationProperties type RemediationsClient = original.RemediationsClient +type SlimPolicyMetadata = original.SlimPolicyMetadata type String = original.String type SummarizeResults = original.SummarizeResults type Summary = original.Summary @@ -98,6 +106,18 @@ func NewPolicyEventsClient() PolicyEventsClient { func NewPolicyEventsClientWithBaseURI(baseURI string) PolicyEventsClient { return original.NewPolicyEventsClientWithBaseURI(baseURI) } +func NewPolicyMetadataClient() PolicyMetadataClient { + return original.NewPolicyMetadataClient() +} +func NewPolicyMetadataClientWithBaseURI(baseURI string) PolicyMetadataClient { + return original.NewPolicyMetadataClientWithBaseURI(baseURI) +} +func NewPolicyMetadataCollectionIterator(page PolicyMetadataCollectionPage) PolicyMetadataCollectionIterator { + return original.NewPolicyMetadataCollectionIterator(page) +} +func NewPolicyMetadataCollectionPage(getNextPage func(context.Context, PolicyMetadataCollection) (PolicyMetadataCollection, error)) PolicyMetadataCollectionPage { + return original.NewPolicyMetadataCollectionPage(getNextPage) +} func NewPolicyStatesClient() PolicyStatesClient { return original.NewPolicyStatesClient() } diff --git a/profiles/latest/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go b/profiles/latest/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go index 3f4601162208..093f733e0044 100644 --- a/profiles/latest/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go +++ b/profiles/latest/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go @@ -23,6 +23,7 @@ import original "github.com/Azure/azure-sdk-for-go/services/policyinsights/mgmt/ type OperationsClientAPI = original.OperationsClientAPI type PolicyEventsClientAPI = original.PolicyEventsClientAPI +type PolicyMetadataClientAPI = original.PolicyMetadataClientAPI type PolicyStatesClientAPI = original.PolicyStatesClientAPI type PolicyTrackedResourcesClientAPI = original.PolicyTrackedResourcesClientAPI type RemediationsClientAPI = original.RemediationsClientAPI diff --git a/profiles/preview/policyinsights/mgmt/policyinsights/models.go b/profiles/preview/policyinsights/mgmt/policyinsights/models.go index b615e657622b..190a0584ed03 100644 --- a/profiles/preview/policyinsights/mgmt/policyinsights/models.go +++ b/profiles/preview/policyinsights/mgmt/policyinsights/models.go @@ -54,6 +54,13 @@ type PolicyEvent = original.PolicyEvent type PolicyEventsClient = original.PolicyEventsClient type PolicyEventsQueryResults = original.PolicyEventsQueryResults type PolicyGroupSummary = original.PolicyGroupSummary +type PolicyMetadata = original.PolicyMetadata +type PolicyMetadataClient = original.PolicyMetadataClient +type PolicyMetadataCollection = original.PolicyMetadataCollection +type PolicyMetadataCollectionIterator = original.PolicyMetadataCollectionIterator +type PolicyMetadataCollectionPage = original.PolicyMetadataCollectionPage +type PolicyMetadataProperties = original.PolicyMetadataProperties +type PolicyMetadataSlimProperties = original.PolicyMetadataSlimProperties type PolicyState = original.PolicyState type PolicyStatesClient = original.PolicyStatesClient type PolicyStatesQueryResults = original.PolicyStatesQueryResults @@ -76,6 +83,7 @@ type RemediationListResultIterator = original.RemediationListResultIterator type RemediationListResultPage = original.RemediationListResultPage type RemediationProperties = original.RemediationProperties type RemediationsClient = original.RemediationsClient +type SlimPolicyMetadata = original.SlimPolicyMetadata type String = original.String type SummarizeResults = original.SummarizeResults type Summary = original.Summary @@ -98,6 +106,18 @@ func NewPolicyEventsClient() PolicyEventsClient { func NewPolicyEventsClientWithBaseURI(baseURI string) PolicyEventsClient { return original.NewPolicyEventsClientWithBaseURI(baseURI) } +func NewPolicyMetadataClient() PolicyMetadataClient { + return original.NewPolicyMetadataClient() +} +func NewPolicyMetadataClientWithBaseURI(baseURI string) PolicyMetadataClient { + return original.NewPolicyMetadataClientWithBaseURI(baseURI) +} +func NewPolicyMetadataCollectionIterator(page PolicyMetadataCollectionPage) PolicyMetadataCollectionIterator { + return original.NewPolicyMetadataCollectionIterator(page) +} +func NewPolicyMetadataCollectionPage(getNextPage func(context.Context, PolicyMetadataCollection) (PolicyMetadataCollection, error)) PolicyMetadataCollectionPage { + return original.NewPolicyMetadataCollectionPage(getNextPage) +} func NewPolicyStatesClient() PolicyStatesClient { return original.NewPolicyStatesClient() } diff --git a/profiles/preview/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go b/profiles/preview/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go index 3f4601162208..093f733e0044 100644 --- a/profiles/preview/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go +++ b/profiles/preview/policyinsights/mgmt/policyinsights/policyinsightsapi/models.go @@ -23,6 +23,7 @@ import original "github.com/Azure/azure-sdk-for-go/services/policyinsights/mgmt/ type OperationsClientAPI = original.OperationsClientAPI type PolicyEventsClientAPI = original.PolicyEventsClientAPI +type PolicyMetadataClientAPI = original.PolicyMetadataClientAPI type PolicyStatesClientAPI = original.PolicyStatesClientAPI type PolicyTrackedResourcesClientAPI = original.PolicyTrackedResourcesClientAPI type RemediationsClientAPI = original.RemediationsClientAPI diff --git a/services/policyinsights/mgmt/2019-10-01/policyinsights/models.go b/services/policyinsights/mgmt/2019-10-01/policyinsights/models.go index 214dcc0b1605..1a0401236c62 100644 --- a/services/policyinsights/mgmt/2019-10-01/policyinsights/models.go +++ b/services/policyinsights/mgmt/2019-10-01/policyinsights/models.go @@ -645,6 +645,266 @@ type PolicyGroupSummary struct { 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 +} + +// 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.NextLink == nil || len(to.String(pmc.NextLink)) < 1 { + 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) + }() + } + next, err := page.fn(ctx, page.pmc) + if err != nil { + return err + } + page.pmc = next + 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(getNextPage func(context.Context, PolicyMetadataCollection) (PolicyMetadataCollection, error)) PolicyMetadataCollectionPage { + return PolicyMetadataCollectionPage{fn: getNextPage} +} + +// PolicyMetadataProperties the properties of the policy metadata. +type PolicyMetadataProperties 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"` + // 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"` + // 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"` + // 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"` + // 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"` +} + // PolicyState policy state record. type PolicyState struct { // AdditionalProperties - Unmatched properties from the message are deserialized this collection @@ -1712,6 +1972,79 @@ type RemediationProperties struct { DeploymentStatus *RemediationDeploymentSummary `json:"deploymentStatus,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 +} + // String ... type String struct { autorest.Response `json:"-"` diff --git a/services/policyinsights/mgmt/2019-10-01/policyinsights/policyinsightsapi/interfaces.go b/services/policyinsights/mgmt/2019-10-01/policyinsights/policyinsightsapi/interfaces.go index aeb5b3244156..bbde33f3e249 100644 --- a/services/policyinsights/mgmt/2019-10-01/policyinsights/policyinsightsapi/interfaces.go +++ b/services/policyinsights/mgmt/2019-10-01/policyinsights/policyinsightsapi/interfaces.go @@ -106,3 +106,11 @@ type OperationsClientAPI interface { } 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) (result policyinsights.PolicyMetadataCollectionPage, err error) +} + +var _ PolicyMetadataClientAPI = (*policyinsights.PolicyMetadataClient)(nil) diff --git a/services/policyinsights/mgmt/2019-10-01/policyinsights/policymetadata.go b/services/policyinsights/mgmt/2019-10-01/policyinsights/policymetadata.go new file mode 100644 index 000000000000..052f628353d0 --- /dev/null +++ b/services/policyinsights/mgmt/2019-10-01/policyinsights/policymetadata.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/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() PolicyMetadataClient { + return NewPolicyMetadataClientWithBaseURI(DefaultBaseURI) +} + +// NewPolicyMetadataClientWithBaseURI creates an instance of the PolicyMetadataClient client. +func NewPolicyMetadataClientWithBaseURI(baseURI string) PolicyMetadataClient { + return PolicyMetadataClient{NewWithBaseURI(baseURI)} +} + +// 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 +} + +// 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) { + sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return autorest.SendWithSender(client, req, sd...) +} + +// 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, + client.ByInspecting(), + 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. +func (client PolicyMetadataClient) List(ctx context.Context) (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) + }() + } + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + 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 +} + +// ListPreparer prepares the List request. +func (client PolicyMetadataClient) 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/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) { + sd := autorest.GetSendDecorators(req.Context(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) + return autorest.SendWithSender(client, req, sd...) +} + +// 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, + client.ByInspecting(), + 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) (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) + return +}