...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2021-06-01-preview/policy/exemptions.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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // ExemptionsClient is the client for the Exemptions methods of the Policy service.
    19  type ExemptionsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewExemptionsClient creates an instance of the ExemptionsClient client.
    24  func NewExemptionsClient(subscriptionID string) ExemptionsClient {
    25  	return NewExemptionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewExemptionsClientWithBaseURI creates an instance of the ExemptionsClient client using a custom endpoint.  Use this
    29  // when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewExemptionsClientWithBaseURI(baseURI string, subscriptionID string) ExemptionsClient {
    31  	return ExemptionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate this operation creates or updates a policy exemption with the given scope and name. Policy exemptions
    35  // apply to all resources contained within their scope. For example, when you create a policy exemption at resource
    36  // group scope for a policy assignment at the same or above level, the exemption exempts to all applicable resources in
    37  // the resource group.
    38  // Parameters:
    39  // scope - the scope of the policy exemption. Valid scopes are: management group (format:
    40  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
    41  // '/subscriptions/{subscriptionId}'), resource group (format:
    42  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
    43  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
    44  // policyExemptionName - the name of the policy exemption to delete.
    45  // parameters - parameters for the policy exemption.
    46  func (client ExemptionsClient) CreateOrUpdate(ctx context.Context, scope string, policyExemptionName string, parameters Exemption) (result Exemption, err error) {
    47  	if tracing.IsEnabled() {
    48  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.CreateOrUpdate")
    49  		defer func() {
    50  			sc := -1
    51  			if result.Response.Response != nil {
    52  				sc = result.Response.Response.StatusCode
    53  			}
    54  			tracing.EndSpan(ctx, sc, err)
    55  		}()
    56  	}
    57  	if err := validation.Validate([]validation.Validation{
    58  		{TargetValue: parameters,
    59  			Constraints: []validation.Constraint{{Target: "parameters.ExemptionProperties", Name: validation.Null, Rule: true,
    60  				Chain: []validation.Constraint{{Target: "parameters.ExemptionProperties.PolicyAssignmentID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    61  		return result, validation.NewError("policy.ExemptionsClient", "CreateOrUpdate", err.Error())
    62  	}
    63  
    64  	req, err := client.CreateOrUpdatePreparer(ctx, scope, policyExemptionName, parameters)
    65  	if err != nil {
    66  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "CreateOrUpdate", nil, "Failure preparing request")
    67  		return
    68  	}
    69  
    70  	resp, err := client.CreateOrUpdateSender(req)
    71  	if err != nil {
    72  		result.Response = autorest.Response{Response: resp}
    73  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "CreateOrUpdate", resp, "Failure sending request")
    74  		return
    75  	}
    76  
    77  	result, err = client.CreateOrUpdateResponder(resp)
    78  	if err != nil {
    79  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "CreateOrUpdate", resp, "Failure responding to request")
    80  		return
    81  	}
    82  
    83  	return
    84  }
    85  
    86  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    87  func (client ExemptionsClient) CreateOrUpdatePreparer(ctx context.Context, scope string, policyExemptionName string, parameters Exemption) (*http.Request, error) {
    88  	pathParameters := map[string]interface{}{
    89  		"policyExemptionName": autorest.Encode("path", policyExemptionName),
    90  		"scope":               scope,
    91  	}
    92  
    93  	const APIVersion = "2020-07-01-preview"
    94  	queryParameters := map[string]interface{}{
    95  		"api-version": APIVersion,
    96  	}
    97  
    98  	parameters.SystemData = nil
    99  	parameters.ID = nil
   100  	parameters.Name = nil
   101  	parameters.Type = nil
   102  	preparer := autorest.CreatePreparer(
   103  		autorest.AsContentType("application/json; charset=utf-8"),
   104  		autorest.AsPut(),
   105  		autorest.WithBaseURL(client.BaseURI),
   106  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
   107  		autorest.WithJSON(parameters),
   108  		autorest.WithQueryParameters(queryParameters))
   109  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   110  }
   111  
   112  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   113  // http.Response Body if it receives an error.
   114  func (client ExemptionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   115  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   116  }
   117  
   118  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   119  // closes the http.Response Body.
   120  func (client ExemptionsClient) CreateOrUpdateResponder(resp *http.Response) (result Exemption, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   124  		autorest.ByUnmarshallingJSON(&result),
   125  		autorest.ByClosing())
   126  	result.Response = autorest.Response{Response: resp}
   127  	return
   128  }
   129  
   130  // Delete this operation deletes a policy exemption, given its name and the scope it was created in. The scope of a
   131  // policy exemption is the part of its ID preceding
   132  // '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'.
   133  // Parameters:
   134  // scope - the scope of the policy exemption. Valid scopes are: management group (format:
   135  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   136  // '/subscriptions/{subscriptionId}'), resource group (format:
   137  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   138  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   139  // policyExemptionName - the name of the policy exemption to delete.
   140  func (client ExemptionsClient) Delete(ctx context.Context, scope string, policyExemptionName string) (result autorest.Response, err error) {
   141  	if tracing.IsEnabled() {
   142  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.Delete")
   143  		defer func() {
   144  			sc := -1
   145  			if result.Response != nil {
   146  				sc = result.Response.StatusCode
   147  			}
   148  			tracing.EndSpan(ctx, sc, err)
   149  		}()
   150  	}
   151  	req, err := client.DeletePreparer(ctx, scope, policyExemptionName)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", nil, "Failure preparing request")
   154  		return
   155  	}
   156  
   157  	resp, err := client.DeleteSender(req)
   158  	if err != nil {
   159  		result.Response = resp
   160  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", resp, "Failure sending request")
   161  		return
   162  	}
   163  
   164  	result, err = client.DeleteResponder(resp)
   165  	if err != nil {
   166  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", resp, "Failure responding to request")
   167  		return
   168  	}
   169  
   170  	return
   171  }
   172  
   173  // DeletePreparer prepares the Delete request.
   174  func (client ExemptionsClient) DeletePreparer(ctx context.Context, scope string, policyExemptionName string) (*http.Request, error) {
   175  	pathParameters := map[string]interface{}{
   176  		"policyExemptionName": autorest.Encode("path", policyExemptionName),
   177  		"scope":               scope,
   178  	}
   179  
   180  	const APIVersion = "2020-07-01-preview"
   181  	queryParameters := map[string]interface{}{
   182  		"api-version": APIVersion,
   183  	}
   184  
   185  	preparer := autorest.CreatePreparer(
   186  		autorest.AsDelete(),
   187  		autorest.WithBaseURL(client.BaseURI),
   188  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
   189  		autorest.WithQueryParameters(queryParameters))
   190  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   191  }
   192  
   193  // DeleteSender sends the Delete request. The method will close the
   194  // http.Response Body if it receives an error.
   195  func (client ExemptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   196  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   197  }
   198  
   199  // DeleteResponder handles the response to the Delete request. The method always
   200  // closes the http.Response Body.
   201  func (client ExemptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   202  	err = autorest.Respond(
   203  		resp,
   204  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   205  		autorest.ByClosing())
   206  	result.Response = resp
   207  	return
   208  }
   209  
   210  // Get this operation retrieves a single policy exemption, given its name and the scope it was created at.
   211  // Parameters:
   212  // scope - the scope of the policy exemption. Valid scopes are: management group (format:
   213  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   214  // '/subscriptions/{subscriptionId}'), resource group (format:
   215  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   216  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   217  // policyExemptionName - the name of the policy exemption to delete.
   218  func (client ExemptionsClient) Get(ctx context.Context, scope string, policyExemptionName string) (result Exemption, err error) {
   219  	if tracing.IsEnabled() {
   220  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.Get")
   221  		defer func() {
   222  			sc := -1
   223  			if result.Response.Response != nil {
   224  				sc = result.Response.Response.StatusCode
   225  			}
   226  			tracing.EndSpan(ctx, sc, err)
   227  		}()
   228  	}
   229  	req, err := client.GetPreparer(ctx, scope, policyExemptionName)
   230  	if err != nil {
   231  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", nil, "Failure preparing request")
   232  		return
   233  	}
   234  
   235  	resp, err := client.GetSender(req)
   236  	if err != nil {
   237  		result.Response = autorest.Response{Response: resp}
   238  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", resp, "Failure sending request")
   239  		return
   240  	}
   241  
   242  	result, err = client.GetResponder(resp)
   243  	if err != nil {
   244  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", resp, "Failure responding to request")
   245  		return
   246  	}
   247  
   248  	return
   249  }
   250  
   251  // GetPreparer prepares the Get request.
   252  func (client ExemptionsClient) GetPreparer(ctx context.Context, scope string, policyExemptionName string) (*http.Request, error) {
   253  	pathParameters := map[string]interface{}{
   254  		"policyExemptionName": autorest.Encode("path", policyExemptionName),
   255  		"scope":               scope,
   256  	}
   257  
   258  	const APIVersion = "2020-07-01-preview"
   259  	queryParameters := map[string]interface{}{
   260  		"api-version": APIVersion,
   261  	}
   262  
   263  	preparer := autorest.CreatePreparer(
   264  		autorest.AsGet(),
   265  		autorest.WithBaseURL(client.BaseURI),
   266  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
   267  		autorest.WithQueryParameters(queryParameters))
   268  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   269  }
   270  
   271  // GetSender sends the Get request. The method will close the
   272  // http.Response Body if it receives an error.
   273  func (client ExemptionsClient) GetSender(req *http.Request) (*http.Response, error) {
   274  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   275  }
   276  
   277  // GetResponder handles the response to the Get request. The method always
   278  // closes the http.Response Body.
   279  func (client ExemptionsClient) GetResponder(resp *http.Response) (result Exemption, err error) {
   280  	err = autorest.Respond(
   281  		resp,
   282  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   283  		autorest.ByUnmarshallingJSON(&result),
   284  		autorest.ByClosing())
   285  	result.Response = autorest.Response{Response: resp}
   286  	return
   287  }
   288  
   289  // List this operation retrieves the list of all policy exemptions associated with the given subscription that match
   290  // the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or
   291  // 'policyAssignmentId eq '{value}”. If $filter is not provided, the unfiltered list includes all policy exemptions
   292  // associated with the subscription, including those that apply directly or from management groups that contain the
   293  // given subscription, as well as any applied to objects contained within the subscription.
   294  // Parameters:
   295  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   296  // 'excludeExpired()' or 'policyAssignmentId eq '{value}”. If $filter is not provided, no filtering is
   297  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   298  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   299  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   300  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   301  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   302  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   303  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   304  // provided. the returned list only includes all policy exemptions that are associated with the give
   305  // policyAssignmentId.
   306  func (client ExemptionsClient) List(ctx context.Context, filter string) (result ExemptionListResultPage, err error) {
   307  	if tracing.IsEnabled() {
   308  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.List")
   309  		defer func() {
   310  			sc := -1
   311  			if result.elr.Response.Response != nil {
   312  				sc = result.elr.Response.Response.StatusCode
   313  			}
   314  			tracing.EndSpan(ctx, sc, err)
   315  		}()
   316  	}
   317  	result.fn = client.listNextResults
   318  	req, err := client.ListPreparer(ctx, filter)
   319  	if err != nil {
   320  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", nil, "Failure preparing request")
   321  		return
   322  	}
   323  
   324  	resp, err := client.ListSender(req)
   325  	if err != nil {
   326  		result.elr.Response = autorest.Response{Response: resp}
   327  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", resp, "Failure sending request")
   328  		return
   329  	}
   330  
   331  	result.elr, err = client.ListResponder(resp)
   332  	if err != nil {
   333  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", resp, "Failure responding to request")
   334  		return
   335  	}
   336  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   337  		err = result.NextWithContext(ctx)
   338  		return
   339  	}
   340  
   341  	return
   342  }
   343  
   344  // ListPreparer prepares the List request.
   345  func (client ExemptionsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) {
   346  	pathParameters := map[string]interface{}{
   347  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   348  	}
   349  
   350  	const APIVersion = "2020-07-01-preview"
   351  	queryParameters := map[string]interface{}{
   352  		"api-version": APIVersion,
   353  	}
   354  	if len(filter) > 0 {
   355  		queryParameters["$filter"] = filter
   356  	}
   357  
   358  	preparer := autorest.CreatePreparer(
   359  		autorest.AsGet(),
   360  		autorest.WithBaseURL(client.BaseURI),
   361  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   362  		autorest.WithQueryParameters(queryParameters))
   363  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   364  }
   365  
   366  // ListSender sends the List request. The method will close the
   367  // http.Response Body if it receives an error.
   368  func (client ExemptionsClient) ListSender(req *http.Request) (*http.Response, error) {
   369  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   370  }
   371  
   372  // ListResponder handles the response to the List request. The method always
   373  // closes the http.Response Body.
   374  func (client ExemptionsClient) ListResponder(resp *http.Response) (result ExemptionListResult, err error) {
   375  	err = autorest.Respond(
   376  		resp,
   377  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   378  		autorest.ByUnmarshallingJSON(&result),
   379  		autorest.ByClosing())
   380  	result.Response = autorest.Response{Response: resp}
   381  	return
   382  }
   383  
   384  // listNextResults retrieves the next set of results, if any.
   385  func (client ExemptionsClient) listNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   386  	req, err := lastResults.exemptionListResultPreparer(ctx)
   387  	if err != nil {
   388  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", nil, "Failure preparing next results request")
   389  	}
   390  	if req == nil {
   391  		return
   392  	}
   393  	resp, err := client.ListSender(req)
   394  	if err != nil {
   395  		result.Response = autorest.Response{Response: resp}
   396  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", resp, "Failure sending next results request")
   397  	}
   398  	result, err = client.ListResponder(resp)
   399  	if err != nil {
   400  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", resp, "Failure responding to next results request")
   401  	}
   402  	return
   403  }
   404  
   405  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   406  func (client ExemptionsClient) ListComplete(ctx context.Context, filter string) (result ExemptionListResultIterator, err error) {
   407  	if tracing.IsEnabled() {
   408  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.List")
   409  		defer func() {
   410  			sc := -1
   411  			if result.Response().Response.Response != nil {
   412  				sc = result.page.Response().Response.Response.StatusCode
   413  			}
   414  			tracing.EndSpan(ctx, sc, err)
   415  		}()
   416  	}
   417  	result.page, err = client.List(ctx, filter)
   418  	return
   419  }
   420  
   421  // ListForManagementGroup this operation retrieves the list of all policy exemptions applicable to the management group
   422  // that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or
   423  // 'policyAssignmentId eq '{value}”. If $filter=atScope() is provided, the returned list includes all policy
   424  // exemptions that are assigned to the management group or the management group's ancestors.
   425  // Parameters:
   426  // managementGroupID - the ID of the management group.
   427  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   428  // 'excludeExpired()' or 'policyAssignmentId eq '{value}”. If $filter is not provided, no filtering is
   429  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   430  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   431  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   432  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   433  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   434  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   435  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   436  // provided. the returned list only includes all policy exemptions that are associated with the give
   437  // policyAssignmentId.
   438  func (client ExemptionsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, filter string) (result ExemptionListResultPage, err error) {
   439  	if tracing.IsEnabled() {
   440  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForManagementGroup")
   441  		defer func() {
   442  			sc := -1
   443  			if result.elr.Response.Response != nil {
   444  				sc = result.elr.Response.Response.StatusCode
   445  			}
   446  			tracing.EndSpan(ctx, sc, err)
   447  		}()
   448  	}
   449  	result.fn = client.listForManagementGroupNextResults
   450  	req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, filter)
   451  	if err != nil {
   452  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", nil, "Failure preparing request")
   453  		return
   454  	}
   455  
   456  	resp, err := client.ListForManagementGroupSender(req)
   457  	if err != nil {
   458  		result.elr.Response = autorest.Response{Response: resp}
   459  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", resp, "Failure sending request")
   460  		return
   461  	}
   462  
   463  	result.elr, err = client.ListForManagementGroupResponder(resp)
   464  	if err != nil {
   465  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", resp, "Failure responding to request")
   466  		return
   467  	}
   468  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   469  		err = result.NextWithContext(ctx)
   470  		return
   471  	}
   472  
   473  	return
   474  }
   475  
   476  // ListForManagementGroupPreparer prepares the ListForManagementGroup request.
   477  func (client ExemptionsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, filter string) (*http.Request, error) {
   478  	pathParameters := map[string]interface{}{
   479  		"managementGroupId": autorest.Encode("path", managementGroupID),
   480  	}
   481  
   482  	const APIVersion = "2020-07-01-preview"
   483  	queryParameters := map[string]interface{}{
   484  		"api-version": APIVersion,
   485  	}
   486  	if len(filter) > 0 {
   487  		queryParameters["$filter"] = filter
   488  	}
   489  
   490  	preparer := autorest.CreatePreparer(
   491  		autorest.AsGet(),
   492  		autorest.WithBaseURL(client.BaseURI),
   493  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   494  		autorest.WithQueryParameters(queryParameters))
   495  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   496  }
   497  
   498  // ListForManagementGroupSender sends the ListForManagementGroup request. The method will close the
   499  // http.Response Body if it receives an error.
   500  func (client ExemptionsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
   501  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   502  }
   503  
   504  // ListForManagementGroupResponder handles the response to the ListForManagementGroup request. The method always
   505  // closes the http.Response Body.
   506  func (client ExemptionsClient) ListForManagementGroupResponder(resp *http.Response) (result ExemptionListResult, err error) {
   507  	err = autorest.Respond(
   508  		resp,
   509  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   510  		autorest.ByUnmarshallingJSON(&result),
   511  		autorest.ByClosing())
   512  	result.Response = autorest.Response{Response: resp}
   513  	return
   514  }
   515  
   516  // listForManagementGroupNextResults retrieves the next set of results, if any.
   517  func (client ExemptionsClient) listForManagementGroupNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   518  	req, err := lastResults.exemptionListResultPreparer(ctx)
   519  	if err != nil {
   520  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
   521  	}
   522  	if req == nil {
   523  		return
   524  	}
   525  	resp, err := client.ListForManagementGroupSender(req)
   526  	if err != nil {
   527  		result.Response = autorest.Response{Response: resp}
   528  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
   529  	}
   530  	result, err = client.ListForManagementGroupResponder(resp)
   531  	if err != nil {
   532  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
   533  	}
   534  	return
   535  }
   536  
   537  // ListForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required.
   538  func (client ExemptionsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, filter string) (result ExemptionListResultIterator, err error) {
   539  	if tracing.IsEnabled() {
   540  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForManagementGroup")
   541  		defer func() {
   542  			sc := -1
   543  			if result.Response().Response.Response != nil {
   544  				sc = result.page.Response().Response.Response.StatusCode
   545  			}
   546  			tracing.EndSpan(ctx, sc, err)
   547  		}()
   548  	}
   549  	result.page, err = client.ListForManagementGroup(ctx, managementGroupID, filter)
   550  	return
   551  }
   552  
   553  // ListForResource this operation retrieves the list of all policy exemptions associated with the specified resource in
   554  // the given resource group and subscription that match the optional given $filter. Valid values for $filter are:
   555  // 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}”. If $filter is not provided,
   556  // the unfiltered list includes all policy exemptions associated with the resource, including those that apply directly
   557  // or from all containing scopes, as well as any applied to resources contained within the resource. Three parameters
   558  // plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource
   559  // (the more common case), the parent resource path should not be provided (or provided as ”). For example a web app
   560  // could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == ”, {resourceType} ==
   561  // 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be
   562  // provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} ==
   563  // 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames',
   564  // {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is
   565  // to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == ”, {parentResourcePath} ==
   566  // ”, {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   567  // Parameters:
   568  // resourceGroupName - the name of the resource group containing the resource.
   569  // resourceProviderNamespace - the namespace of the resource provider. For example, the namespace of a virtual
   570  // machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines)
   571  // parentResourcePath - the parent resource path. Use empty string if there is none.
   572  // resourceType - the resource type name. For example the type name of a web app is 'sites' (from
   573  // Microsoft.Web/sites).
   574  // resourceName - the name of the resource.
   575  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   576  // 'excludeExpired()' or 'policyAssignmentId eq '{value}”. If $filter is not provided, no filtering is
   577  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   578  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   579  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   580  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   581  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   582  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   583  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   584  // provided. the returned list only includes all policy exemptions that are associated with the give
   585  // policyAssignmentId.
   586  func (client ExemptionsClient) ListForResource(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result ExemptionListResultPage, err error) {
   587  	if tracing.IsEnabled() {
   588  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResource")
   589  		defer func() {
   590  			sc := -1
   591  			if result.elr.Response.Response != nil {
   592  				sc = result.elr.Response.Response.StatusCode
   593  			}
   594  			tracing.EndSpan(ctx, sc, err)
   595  		}()
   596  	}
   597  	if err := validation.Validate([]validation.Validation{
   598  		{TargetValue: resourceGroupName,
   599  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   600  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   601  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   602  		return result, validation.NewError("policy.ExemptionsClient", "ListForResource", err.Error())
   603  	}
   604  
   605  	result.fn = client.listForResourceNextResults
   606  	req, err := client.ListForResourcePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
   607  	if err != nil {
   608  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", nil, "Failure preparing request")
   609  		return
   610  	}
   611  
   612  	resp, err := client.ListForResourceSender(req)
   613  	if err != nil {
   614  		result.elr.Response = autorest.Response{Response: resp}
   615  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", resp, "Failure sending request")
   616  		return
   617  	}
   618  
   619  	result.elr, err = client.ListForResourceResponder(resp)
   620  	if err != nil {
   621  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", resp, "Failure responding to request")
   622  		return
   623  	}
   624  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   625  		err = result.NextWithContext(ctx)
   626  		return
   627  	}
   628  
   629  	return
   630  }
   631  
   632  // ListForResourcePreparer prepares the ListForResource request.
   633  func (client ExemptionsClient) ListForResourcePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (*http.Request, error) {
   634  	pathParameters := map[string]interface{}{
   635  		"parentResourcePath":        parentResourcePath,
   636  		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
   637  		"resourceName":              autorest.Encode("path", resourceName),
   638  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
   639  		"resourceType":              resourceType,
   640  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
   641  	}
   642  
   643  	const APIVersion = "2020-07-01-preview"
   644  	queryParameters := map[string]interface{}{
   645  		"api-version": APIVersion,
   646  	}
   647  	if len(filter) > 0 {
   648  		queryParameters["$filter"] = filter
   649  	}
   650  
   651  	preparer := autorest.CreatePreparer(
   652  		autorest.AsGet(),
   653  		autorest.WithBaseURL(client.BaseURI),
   654  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   655  		autorest.WithQueryParameters(queryParameters))
   656  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   657  }
   658  
   659  // ListForResourceSender sends the ListForResource request. The method will close the
   660  // http.Response Body if it receives an error.
   661  func (client ExemptionsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
   662  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   663  }
   664  
   665  // ListForResourceResponder handles the response to the ListForResource request. The method always
   666  // closes the http.Response Body.
   667  func (client ExemptionsClient) ListForResourceResponder(resp *http.Response) (result ExemptionListResult, err error) {
   668  	err = autorest.Respond(
   669  		resp,
   670  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   671  		autorest.ByUnmarshallingJSON(&result),
   672  		autorest.ByClosing())
   673  	result.Response = autorest.Response{Response: resp}
   674  	return
   675  }
   676  
   677  // listForResourceNextResults retrieves the next set of results, if any.
   678  func (client ExemptionsClient) listForResourceNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   679  	req, err := lastResults.exemptionListResultPreparer(ctx)
   680  	if err != nil {
   681  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
   682  	}
   683  	if req == nil {
   684  		return
   685  	}
   686  	resp, err := client.ListForResourceSender(req)
   687  	if err != nil {
   688  		result.Response = autorest.Response{Response: resp}
   689  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", resp, "Failure sending next results request")
   690  	}
   691  	result, err = client.ListForResourceResponder(resp)
   692  	if err != nil {
   693  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
   694  	}
   695  	return
   696  }
   697  
   698  // ListForResourceComplete enumerates all values, automatically crossing page boundaries as required.
   699  func (client ExemptionsClient) ListForResourceComplete(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result ExemptionListResultIterator, err error) {
   700  	if tracing.IsEnabled() {
   701  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResource")
   702  		defer func() {
   703  			sc := -1
   704  			if result.Response().Response.Response != nil {
   705  				sc = result.page.Response().Response.Response.StatusCode
   706  			}
   707  			tracing.EndSpan(ctx, sc, err)
   708  		}()
   709  	}
   710  	result.page, err = client.ListForResource(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
   711  	return
   712  }
   713  
   714  // ListForResourceGroup this operation retrieves the list of all policy exemptions associated with the given resource
   715  // group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()',
   716  // 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}”. If $filter is not provided, the
   717  // unfiltered list includes all policy exemptions associated with the resource group, including those that apply
   718  // directly or apply from containing scopes, as well as any applied to resources contained within the resource group.
   719  // Parameters:
   720  // resourceGroupName - the name of the resource group containing the resource.
   721  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   722  // 'excludeExpired()' or 'policyAssignmentId eq '{value}”. If $filter is not provided, no filtering is
   723  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   724  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   725  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   726  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   727  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   728  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   729  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   730  // provided. the returned list only includes all policy exemptions that are associated with the give
   731  // policyAssignmentId.
   732  func (client ExemptionsClient) ListForResourceGroup(ctx context.Context, resourceGroupName string, filter string) (result ExemptionListResultPage, err error) {
   733  	if tracing.IsEnabled() {
   734  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResourceGroup")
   735  		defer func() {
   736  			sc := -1
   737  			if result.elr.Response.Response != nil {
   738  				sc = result.elr.Response.Response.StatusCode
   739  			}
   740  			tracing.EndSpan(ctx, sc, err)
   741  		}()
   742  	}
   743  	if err := validation.Validate([]validation.Validation{
   744  		{TargetValue: resourceGroupName,
   745  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   746  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   747  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   748  		return result, validation.NewError("policy.ExemptionsClient", "ListForResourceGroup", err.Error())
   749  	}
   750  
   751  	result.fn = client.listForResourceGroupNextResults
   752  	req, err := client.ListForResourceGroupPreparer(ctx, resourceGroupName, filter)
   753  	if err != nil {
   754  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResourceGroup", nil, "Failure preparing request")
   755  		return
   756  	}
   757  
   758  	resp, err := client.ListForResourceGroupSender(req)
   759  	if err != nil {
   760  		result.elr.Response = autorest.Response{Response: resp}
   761  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResourceGroup", resp, "Failure sending request")
   762  		return
   763  	}
   764  
   765  	result.elr, err = client.ListForResourceGroupResponder(resp)
   766  	if err != nil {
   767  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResourceGroup", resp, "Failure responding to request")
   768  		return
   769  	}
   770  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   771  		err = result.NextWithContext(ctx)
   772  		return
   773  	}
   774  
   775  	return
   776  }
   777  
   778  // ListForResourceGroupPreparer prepares the ListForResourceGroup request.
   779  func (client ExemptionsClient) ListForResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string) (*http.Request, error) {
   780  	pathParameters := map[string]interface{}{
   781  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   782  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   783  	}
   784  
   785  	const APIVersion = "2020-07-01-preview"
   786  	queryParameters := map[string]interface{}{
   787  		"api-version": APIVersion,
   788  	}
   789  	if len(filter) > 0 {
   790  		queryParameters["$filter"] = filter
   791  	}
   792  
   793  	preparer := autorest.CreatePreparer(
   794  		autorest.AsGet(),
   795  		autorest.WithBaseURL(client.BaseURI),
   796  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   797  		autorest.WithQueryParameters(queryParameters))
   798  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   799  }
   800  
   801  // ListForResourceGroupSender sends the ListForResourceGroup request. The method will close the
   802  // http.Response Body if it receives an error.
   803  func (client ExemptionsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) {
   804  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   805  }
   806  
   807  // ListForResourceGroupResponder handles the response to the ListForResourceGroup request. The method always
   808  // closes the http.Response Body.
   809  func (client ExemptionsClient) ListForResourceGroupResponder(resp *http.Response) (result ExemptionListResult, err error) {
   810  	err = autorest.Respond(
   811  		resp,
   812  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   813  		autorest.ByUnmarshallingJSON(&result),
   814  		autorest.ByClosing())
   815  	result.Response = autorest.Response{Response: resp}
   816  	return
   817  }
   818  
   819  // listForResourceGroupNextResults retrieves the next set of results, if any.
   820  func (client ExemptionsClient) listForResourceGroupNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   821  	req, err := lastResults.exemptionListResultPreparer(ctx)
   822  	if err != nil {
   823  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request")
   824  	}
   825  	if req == nil {
   826  		return
   827  	}
   828  	resp, err := client.ListForResourceGroupSender(req)
   829  	if err != nil {
   830  		result.Response = autorest.Response{Response: resp}
   831  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request")
   832  	}
   833  	result, err = client.ListForResourceGroupResponder(resp)
   834  	if err != nil {
   835  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request")
   836  	}
   837  	return
   838  }
   839  
   840  // ListForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   841  func (client ExemptionsClient) ListForResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string) (result ExemptionListResultIterator, err error) {
   842  	if tracing.IsEnabled() {
   843  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResourceGroup")
   844  		defer func() {
   845  			sc := -1
   846  			if result.Response().Response.Response != nil {
   847  				sc = result.page.Response().Response.Response.StatusCode
   848  			}
   849  			tracing.EndSpan(ctx, sc, err)
   850  		}()
   851  	}
   852  	result.page, err = client.ListForResourceGroup(ctx, resourceGroupName, filter)
   853  	return
   854  }
   855  

View as plain text