...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2021-06-01-preview/policy/datapolicymanifests.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2021-06-01-preview/policy

     1  package policy
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // DataPolicyManifestsClient is the client for the DataPolicyManifests methods of the Policy service.
    18  type DataPolicyManifestsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewDataPolicyManifestsClient creates an instance of the DataPolicyManifestsClient client.
    23  func NewDataPolicyManifestsClient(subscriptionID string) DataPolicyManifestsClient {
    24  	return NewDataPolicyManifestsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewDataPolicyManifestsClientWithBaseURI creates an instance of the DataPolicyManifestsClient client using a custom
    28  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    29  // stack).
    30  func NewDataPolicyManifestsClientWithBaseURI(baseURI string, subscriptionID string) DataPolicyManifestsClient {
    31  	return DataPolicyManifestsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // GetByPolicyMode this operation retrieves the data policy manifest with the given policy mode.
    35  // Parameters:
    36  // policyMode - the policy mode of the data policy manifest to get.
    37  func (client DataPolicyManifestsClient) GetByPolicyMode(ctx context.Context, policyMode string) (result DataPolicyManifest, err error) {
    38  	if tracing.IsEnabled() {
    39  		ctx = tracing.StartSpan(ctx, fqdn+"/DataPolicyManifestsClient.GetByPolicyMode")
    40  		defer func() {
    41  			sc := -1
    42  			if result.Response.Response != nil {
    43  				sc = result.Response.Response.StatusCode
    44  			}
    45  			tracing.EndSpan(ctx, sc, err)
    46  		}()
    47  	}
    48  	req, err := client.GetByPolicyModePreparer(ctx, policyMode)
    49  	if err != nil {
    50  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "GetByPolicyMode", nil, "Failure preparing request")
    51  		return
    52  	}
    53  
    54  	resp, err := client.GetByPolicyModeSender(req)
    55  	if err != nil {
    56  		result.Response = autorest.Response{Response: resp}
    57  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "GetByPolicyMode", resp, "Failure sending request")
    58  		return
    59  	}
    60  
    61  	result, err = client.GetByPolicyModeResponder(resp)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "GetByPolicyMode", resp, "Failure responding to request")
    64  		return
    65  	}
    66  
    67  	return
    68  }
    69  
    70  // GetByPolicyModePreparer prepares the GetByPolicyMode request.
    71  func (client DataPolicyManifestsClient) GetByPolicyModePreparer(ctx context.Context, policyMode string) (*http.Request, error) {
    72  	pathParameters := map[string]interface{}{
    73  		"policyMode": autorest.Encode("path", policyMode),
    74  	}
    75  
    76  	const APIVersion = "2020-09-01"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	preparer := autorest.CreatePreparer(
    82  		autorest.AsGet(),
    83  		autorest.WithBaseURL(client.BaseURI),
    84  		autorest.WithPathParameters("/providers/Microsoft.Authorization/dataPolicyManifests/{policyMode}", pathParameters),
    85  		autorest.WithQueryParameters(queryParameters))
    86  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    87  }
    88  
    89  // GetByPolicyModeSender sends the GetByPolicyMode request. The method will close the
    90  // http.Response Body if it receives an error.
    91  func (client DataPolicyManifestsClient) GetByPolicyModeSender(req *http.Request) (*http.Response, error) {
    92  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    93  }
    94  
    95  // GetByPolicyModeResponder handles the response to the GetByPolicyMode request. The method always
    96  // closes the http.Response Body.
    97  func (client DataPolicyManifestsClient) GetByPolicyModeResponder(resp *http.Response) (result DataPolicyManifest, err error) {
    98  	err = autorest.Respond(
    99  		resp,
   100  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   101  		autorest.ByUnmarshallingJSON(&result),
   102  		autorest.ByClosing())
   103  	result.Response = autorest.Response{Response: resp}
   104  	return
   105  }
   106  
   107  // List this operation retrieves a list of all the data policy manifests that match the optional given $filter. Valid
   108  // values for $filter are: "$filter=namespace eq '{0}'". If $filter is not provided, the unfiltered list includes all
   109  // data policy manifests for data resource types. If $filter=namespace is provided, the returned list only includes all
   110  // data policy manifests that have a namespace matching the provided value.
   111  // Parameters:
   112  // filter - the filter to apply on the operation. Valid values for $filter are: "namespace eq '{value}'". If
   113  // $filter is not provided, no filtering is performed. If $filter=namespace eq '{value}' is provided, the
   114  // returned list only includes all data policy manifests that have a namespace matching the provided value.
   115  func (client DataPolicyManifestsClient) List(ctx context.Context, filter string) (result DataPolicyManifestListResultPage, err error) {
   116  	if tracing.IsEnabled() {
   117  		ctx = tracing.StartSpan(ctx, fqdn+"/DataPolicyManifestsClient.List")
   118  		defer func() {
   119  			sc := -1
   120  			if result.dpmlr.Response.Response != nil {
   121  				sc = result.dpmlr.Response.Response.StatusCode
   122  			}
   123  			tracing.EndSpan(ctx, sc, err)
   124  		}()
   125  	}
   126  	result.fn = client.listNextResults
   127  	req, err := client.ListPreparer(ctx, filter)
   128  	if err != nil {
   129  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "List", nil, "Failure preparing request")
   130  		return
   131  	}
   132  
   133  	resp, err := client.ListSender(req)
   134  	if err != nil {
   135  		result.dpmlr.Response = autorest.Response{Response: resp}
   136  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "List", resp, "Failure sending request")
   137  		return
   138  	}
   139  
   140  	result.dpmlr, err = client.ListResponder(resp)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "List", resp, "Failure responding to request")
   143  		return
   144  	}
   145  	if result.dpmlr.hasNextLink() && result.dpmlr.IsEmpty() {
   146  		err = result.NextWithContext(ctx)
   147  		return
   148  	}
   149  
   150  	return
   151  }
   152  
   153  // ListPreparer prepares the List request.
   154  func (client DataPolicyManifestsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) {
   155  	const APIVersion = "2020-09-01"
   156  	queryParameters := map[string]interface{}{
   157  		"api-version": APIVersion,
   158  	}
   159  	if len(filter) > 0 {
   160  		queryParameters["$filter"] = filter
   161  	}
   162  
   163  	preparer := autorest.CreatePreparer(
   164  		autorest.AsGet(),
   165  		autorest.WithBaseURL(client.BaseURI),
   166  		autorest.WithPath("/providers/Microsoft.Authorization/dataPolicyManifests"),
   167  		autorest.WithQueryParameters(queryParameters))
   168  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   169  }
   170  
   171  // ListSender sends the List request. The method will close the
   172  // http.Response Body if it receives an error.
   173  func (client DataPolicyManifestsClient) ListSender(req *http.Request) (*http.Response, error) {
   174  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   175  }
   176  
   177  // ListResponder handles the response to the List request. The method always
   178  // closes the http.Response Body.
   179  func (client DataPolicyManifestsClient) ListResponder(resp *http.Response) (result DataPolicyManifestListResult, err error) {
   180  	err = autorest.Respond(
   181  		resp,
   182  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   183  		autorest.ByUnmarshallingJSON(&result),
   184  		autorest.ByClosing())
   185  	result.Response = autorest.Response{Response: resp}
   186  	return
   187  }
   188  
   189  // listNextResults retrieves the next set of results, if any.
   190  func (client DataPolicyManifestsClient) listNextResults(ctx context.Context, lastResults DataPolicyManifestListResult) (result DataPolicyManifestListResult, err error) {
   191  	req, err := lastResults.dataPolicyManifestListResultPreparer(ctx)
   192  	if err != nil {
   193  		return result, autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "listNextResults", nil, "Failure preparing next results request")
   194  	}
   195  	if req == nil {
   196  		return
   197  	}
   198  	resp, err := client.ListSender(req)
   199  	if err != nil {
   200  		result.Response = autorest.Response{Response: resp}
   201  		return result, autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "listNextResults", resp, "Failure sending next results request")
   202  	}
   203  	result, err = client.ListResponder(resp)
   204  	if err != nil {
   205  		err = autorest.NewErrorWithError(err, "policy.DataPolicyManifestsClient", "listNextResults", resp, "Failure responding to next results request")
   206  	}
   207  	return
   208  }
   209  
   210  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   211  func (client DataPolicyManifestsClient) ListComplete(ctx context.Context, filter string) (result DataPolicyManifestListResultIterator, err error) {
   212  	if tracing.IsEnabled() {
   213  		ctx = tracing.StartSpan(ctx, fqdn+"/DataPolicyManifestsClient.List")
   214  		defer func() {
   215  			sc := -1
   216  			if result.Response().Response.Response != nil {
   217  				sc = result.page.Response().Response.Response.StatusCode
   218  			}
   219  			tracing.EndSpan(ctx, sc, err)
   220  		}()
   221  	}
   222  	result.page, err = client.List(ctx, filter)
   223  	return
   224  }
   225  

View as plain text