...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2020-03-01-preview/policy/exemptions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2020-03-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() ExemptionsClient {
    25  	return NewExemptionsClientWithBaseURI(DefaultBaseURI)
    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) ExemptionsClient {
    31  	return ExemptionsClient{NewWithBaseURI(baseURI)}
    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  // parameters - parameters for the policy exemption.
    40  // scope - the scope of the policy exemption. Valid scopes are: management group (format:
    41  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
    42  // '/subscriptions/{subscriptionId}'), resource group (format:
    43  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
    44  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
    45  // policyExemptionName - the name of the policy exemption to delete.
    46  func (client ExemptionsClient) CreateOrUpdate(ctx context.Context, parameters Exemption, scope string, policyExemptionName string) (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, parameters, scope, policyExemptionName)
    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, parameters Exemption, scope string, policyExemptionName string) (*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  	preparer := autorest.CreatePreparer(
   100  		autorest.AsContentType("application/json; charset=utf-8"),
   101  		autorest.AsPut(),
   102  		autorest.WithBaseURL(client.BaseURI),
   103  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
   104  		autorest.WithJSON(parameters),
   105  		autorest.WithQueryParameters(queryParameters))
   106  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   107  }
   108  
   109  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   110  // http.Response Body if it receives an error.
   111  func (client ExemptionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   112  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   113  }
   114  
   115  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   116  // closes the http.Response Body.
   117  func (client ExemptionsClient) CreateOrUpdateResponder(resp *http.Response) (result Exemption, err error) {
   118  	err = autorest.Respond(
   119  		resp,
   120  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   121  		autorest.ByUnmarshallingJSON(&result),
   122  		autorest.ByClosing())
   123  	result.Response = autorest.Response{Response: resp}
   124  	return
   125  }
   126  
   127  // Delete this operation deletes a policy exemption, given its name and the scope it was created in. The scope of a
   128  // policy exemption is the part of its ID preceding
   129  // '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'.
   130  // Parameters:
   131  // scope - the scope of the policy exemption. Valid scopes are: management group (format:
   132  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   133  // '/subscriptions/{subscriptionId}'), resource group (format:
   134  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   135  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   136  // policyExemptionName - the name of the policy exemption to delete.
   137  func (client ExemptionsClient) Delete(ctx context.Context, scope string, policyExemptionName string) (result autorest.Response, err error) {
   138  	if tracing.IsEnabled() {
   139  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.Delete")
   140  		defer func() {
   141  			sc := -1
   142  			if result.Response != nil {
   143  				sc = result.Response.StatusCode
   144  			}
   145  			tracing.EndSpan(ctx, sc, err)
   146  		}()
   147  	}
   148  	req, err := client.DeletePreparer(ctx, scope, policyExemptionName)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", nil, "Failure preparing request")
   151  		return
   152  	}
   153  
   154  	resp, err := client.DeleteSender(req)
   155  	if err != nil {
   156  		result.Response = resp
   157  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", resp, "Failure sending request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteResponder(resp)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", resp, "Failure responding to request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client ExemptionsClient) DeletePreparer(ctx context.Context, scope string, policyExemptionName string) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"policyExemptionName": autorest.Encode("path", policyExemptionName),
   174  		"scope":               scope,
   175  	}
   176  
   177  	const APIVersion = "2020-07-01-preview"
   178  	queryParameters := map[string]interface{}{
   179  		"api-version": APIVersion,
   180  	}
   181  
   182  	preparer := autorest.CreatePreparer(
   183  		autorest.AsDelete(),
   184  		autorest.WithBaseURL(client.BaseURI),
   185  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
   186  		autorest.WithQueryParameters(queryParameters))
   187  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   188  }
   189  
   190  // DeleteSender sends the Delete request. The method will close the
   191  // http.Response Body if it receives an error.
   192  func (client ExemptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   193  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   194  }
   195  
   196  // DeleteResponder handles the response to the Delete request. The method always
   197  // closes the http.Response Body.
   198  func (client ExemptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   199  	err = autorest.Respond(
   200  		resp,
   201  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   202  		autorest.ByClosing())
   203  	result.Response = resp
   204  	return
   205  }
   206  
   207  // Get this operation retrieves a single policy exemption, given its name and the scope it was created at.
   208  // Parameters:
   209  // scope - the scope of the policy exemption. Valid scopes are: management group (format:
   210  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   211  // '/subscriptions/{subscriptionId}'), resource group (format:
   212  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   213  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   214  // policyExemptionName - the name of the policy exemption to delete.
   215  func (client ExemptionsClient) Get(ctx context.Context, scope string, policyExemptionName string) (result Exemption, err error) {
   216  	if tracing.IsEnabled() {
   217  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.Get")
   218  		defer func() {
   219  			sc := -1
   220  			if result.Response.Response != nil {
   221  				sc = result.Response.Response.StatusCode
   222  			}
   223  			tracing.EndSpan(ctx, sc, err)
   224  		}()
   225  	}
   226  	req, err := client.GetPreparer(ctx, scope, policyExemptionName)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", nil, "Failure preparing request")
   229  		return
   230  	}
   231  
   232  	resp, err := client.GetSender(req)
   233  	if err != nil {
   234  		result.Response = autorest.Response{Response: resp}
   235  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", resp, "Failure sending request")
   236  		return
   237  	}
   238  
   239  	result, err = client.GetResponder(resp)
   240  	if err != nil {
   241  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", resp, "Failure responding to request")
   242  		return
   243  	}
   244  
   245  	return
   246  }
   247  
   248  // GetPreparer prepares the Get request.
   249  func (client ExemptionsClient) GetPreparer(ctx context.Context, scope string, policyExemptionName string) (*http.Request, error) {
   250  	pathParameters := map[string]interface{}{
   251  		"policyExemptionName": autorest.Encode("path", policyExemptionName),
   252  		"scope":               scope,
   253  	}
   254  
   255  	const APIVersion = "2020-07-01-preview"
   256  	queryParameters := map[string]interface{}{
   257  		"api-version": APIVersion,
   258  	}
   259  
   260  	preparer := autorest.CreatePreparer(
   261  		autorest.AsGet(),
   262  		autorest.WithBaseURL(client.BaseURI),
   263  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
   264  		autorest.WithQueryParameters(queryParameters))
   265  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   266  }
   267  
   268  // GetSender sends the Get request. The method will close the
   269  // http.Response Body if it receives an error.
   270  func (client ExemptionsClient) GetSender(req *http.Request) (*http.Response, error) {
   271  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   272  }
   273  
   274  // GetResponder handles the response to the Get request. The method always
   275  // closes the http.Response Body.
   276  func (client ExemptionsClient) GetResponder(resp *http.Response) (result Exemption, err error) {
   277  	err = autorest.Respond(
   278  		resp,
   279  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   280  		autorest.ByUnmarshallingJSON(&result),
   281  		autorest.ByClosing())
   282  	result.Response = autorest.Response{Response: resp}
   283  	return
   284  }
   285  
   286  // List this operation retrieves the list of all policy exemptions associated with the given subscription that match
   287  // the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or
   288  // 'policyAssignmentId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy exemptions
   289  // associated with the subscription, including those that apply directly or from management groups that contain the
   290  // given subscription, as well as any applied to objects contained within the subscription.
   291  // Parameters:
   292  // subscriptionID - the ID of the target subscription.
   293  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   294  // 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is
   295  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   296  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   297  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   298  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   299  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   300  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   301  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   302  // provided. the returned list only includes all policy exemptions that are associated with the give
   303  // policyAssignmentId.
   304  func (client ExemptionsClient) List(ctx context.Context, subscriptionID string, filter string) (result ExemptionListResultPage, err error) {
   305  	if tracing.IsEnabled() {
   306  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.List")
   307  		defer func() {
   308  			sc := -1
   309  			if result.elr.Response.Response != nil {
   310  				sc = result.elr.Response.Response.StatusCode
   311  			}
   312  			tracing.EndSpan(ctx, sc, err)
   313  		}()
   314  	}
   315  	result.fn = client.listNextResults
   316  	req, err := client.ListPreparer(ctx, subscriptionID, filter)
   317  	if err != nil {
   318  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", nil, "Failure preparing request")
   319  		return
   320  	}
   321  
   322  	resp, err := client.ListSender(req)
   323  	if err != nil {
   324  		result.elr.Response = autorest.Response{Response: resp}
   325  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", resp, "Failure sending request")
   326  		return
   327  	}
   328  
   329  	result.elr, err = client.ListResponder(resp)
   330  	if err != nil {
   331  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", resp, "Failure responding to request")
   332  		return
   333  	}
   334  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   335  		err = result.NextWithContext(ctx)
   336  		return
   337  	}
   338  
   339  	return
   340  }
   341  
   342  // ListPreparer prepares the List request.
   343  func (client ExemptionsClient) ListPreparer(ctx context.Context, subscriptionID string, filter string) (*http.Request, error) {
   344  	pathParameters := map[string]interface{}{
   345  		"subscriptionId": autorest.Encode("path", subscriptionID),
   346  	}
   347  
   348  	const APIVersion = "2020-07-01-preview"
   349  	queryParameters := map[string]interface{}{
   350  		"api-version": APIVersion,
   351  	}
   352  	if len(filter) > 0 {
   353  		queryParameters["$filter"] = filter
   354  	}
   355  
   356  	preparer := autorest.CreatePreparer(
   357  		autorest.AsGet(),
   358  		autorest.WithBaseURL(client.BaseURI),
   359  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   360  		autorest.WithQueryParameters(queryParameters))
   361  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   362  }
   363  
   364  // ListSender sends the List request. The method will close the
   365  // http.Response Body if it receives an error.
   366  func (client ExemptionsClient) ListSender(req *http.Request) (*http.Response, error) {
   367  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   368  }
   369  
   370  // ListResponder handles the response to the List request. The method always
   371  // closes the http.Response Body.
   372  func (client ExemptionsClient) ListResponder(resp *http.Response) (result ExemptionListResult, err error) {
   373  	err = autorest.Respond(
   374  		resp,
   375  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   376  		autorest.ByUnmarshallingJSON(&result),
   377  		autorest.ByClosing())
   378  	result.Response = autorest.Response{Response: resp}
   379  	return
   380  }
   381  
   382  // listNextResults retrieves the next set of results, if any.
   383  func (client ExemptionsClient) listNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   384  	req, err := lastResults.exemptionListResultPreparer(ctx)
   385  	if err != nil {
   386  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", nil, "Failure preparing next results request")
   387  	}
   388  	if req == nil {
   389  		return
   390  	}
   391  	resp, err := client.ListSender(req)
   392  	if err != nil {
   393  		result.Response = autorest.Response{Response: resp}
   394  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", resp, "Failure sending next results request")
   395  	}
   396  	result, err = client.ListResponder(resp)
   397  	if err != nil {
   398  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", resp, "Failure responding to next results request")
   399  	}
   400  	return
   401  }
   402  
   403  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   404  func (client ExemptionsClient) ListComplete(ctx context.Context, subscriptionID string, filter string) (result ExemptionListResultIterator, err error) {
   405  	if tracing.IsEnabled() {
   406  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.List")
   407  		defer func() {
   408  			sc := -1
   409  			if result.Response().Response.Response != nil {
   410  				sc = result.page.Response().Response.Response.StatusCode
   411  			}
   412  			tracing.EndSpan(ctx, sc, err)
   413  		}()
   414  	}
   415  	result.page, err = client.List(ctx, subscriptionID, filter)
   416  	return
   417  }
   418  
   419  // ListForManagementGroup this operation retrieves the list of all policy exemptions applicable to the management group
   420  // that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()', 'excludeExpired()' or
   421  // 'policyAssignmentId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy
   422  // exemptions that are assigned to the management group or the management group's ancestors.
   423  // Parameters:
   424  // managementGroupID - the ID of the management group.
   425  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   426  // 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is
   427  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   428  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   429  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   430  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   431  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   432  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   433  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   434  // provided. the returned list only includes all policy exemptions that are associated with the give
   435  // policyAssignmentId.
   436  func (client ExemptionsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, filter string) (result ExemptionListResultPage, err error) {
   437  	if tracing.IsEnabled() {
   438  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForManagementGroup")
   439  		defer func() {
   440  			sc := -1
   441  			if result.elr.Response.Response != nil {
   442  				sc = result.elr.Response.Response.StatusCode
   443  			}
   444  			tracing.EndSpan(ctx, sc, err)
   445  		}()
   446  	}
   447  	result.fn = client.listForManagementGroupNextResults
   448  	req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, filter)
   449  	if err != nil {
   450  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", nil, "Failure preparing request")
   451  		return
   452  	}
   453  
   454  	resp, err := client.ListForManagementGroupSender(req)
   455  	if err != nil {
   456  		result.elr.Response = autorest.Response{Response: resp}
   457  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", resp, "Failure sending request")
   458  		return
   459  	}
   460  
   461  	result.elr, err = client.ListForManagementGroupResponder(resp)
   462  	if err != nil {
   463  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", resp, "Failure responding to request")
   464  		return
   465  	}
   466  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   467  		err = result.NextWithContext(ctx)
   468  		return
   469  	}
   470  
   471  	return
   472  }
   473  
   474  // ListForManagementGroupPreparer prepares the ListForManagementGroup request.
   475  func (client ExemptionsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, filter string) (*http.Request, error) {
   476  	pathParameters := map[string]interface{}{
   477  		"managementGroupId": autorest.Encode("path", managementGroupID),
   478  	}
   479  
   480  	const APIVersion = "2020-07-01-preview"
   481  	queryParameters := map[string]interface{}{
   482  		"api-version": APIVersion,
   483  	}
   484  	if len(filter) > 0 {
   485  		queryParameters["$filter"] = filter
   486  	}
   487  
   488  	preparer := autorest.CreatePreparer(
   489  		autorest.AsGet(),
   490  		autorest.WithBaseURL(client.BaseURI),
   491  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   492  		autorest.WithQueryParameters(queryParameters))
   493  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   494  }
   495  
   496  // ListForManagementGroupSender sends the ListForManagementGroup request. The method will close the
   497  // http.Response Body if it receives an error.
   498  func (client ExemptionsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
   499  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   500  }
   501  
   502  // ListForManagementGroupResponder handles the response to the ListForManagementGroup request. The method always
   503  // closes the http.Response Body.
   504  func (client ExemptionsClient) ListForManagementGroupResponder(resp *http.Response) (result ExemptionListResult, err error) {
   505  	err = autorest.Respond(
   506  		resp,
   507  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   508  		autorest.ByUnmarshallingJSON(&result),
   509  		autorest.ByClosing())
   510  	result.Response = autorest.Response{Response: resp}
   511  	return
   512  }
   513  
   514  // listForManagementGroupNextResults retrieves the next set of results, if any.
   515  func (client ExemptionsClient) listForManagementGroupNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   516  	req, err := lastResults.exemptionListResultPreparer(ctx)
   517  	if err != nil {
   518  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
   519  	}
   520  	if req == nil {
   521  		return
   522  	}
   523  	resp, err := client.ListForManagementGroupSender(req)
   524  	if err != nil {
   525  		result.Response = autorest.Response{Response: resp}
   526  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
   527  	}
   528  	result, err = client.ListForManagementGroupResponder(resp)
   529  	if err != nil {
   530  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
   531  	}
   532  	return
   533  }
   534  
   535  // ListForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required.
   536  func (client ExemptionsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, filter string) (result ExemptionListResultIterator, err error) {
   537  	if tracing.IsEnabled() {
   538  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForManagementGroup")
   539  		defer func() {
   540  			sc := -1
   541  			if result.Response().Response.Response != nil {
   542  				sc = result.page.Response().Response.Response.StatusCode
   543  			}
   544  			tracing.EndSpan(ctx, sc, err)
   545  		}()
   546  	}
   547  	result.page, err = client.ListForManagementGroup(ctx, managementGroupID, filter)
   548  	return
   549  }
   550  
   551  // ListForResource this operation retrieves the list of all policy exemptions associated with the specified resource in
   552  // the given resource group and subscription that match the optional given $filter. Valid values for $filter are:
   553  // 'atScope()', 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided,
   554  // the unfiltered list includes all policy exemptions associated with the resource, including those that apply directly
   555  // or from all containing scopes, as well as any applied to resources contained within the resource. Three parameters
   556  // plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource
   557  // (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app
   558  // could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} ==
   559  // 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be
   560  // provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} ==
   561  // 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames',
   562  // {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is
   563  // to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} ==
   564  // '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   565  // Parameters:
   566  // subscriptionID - the ID of the target subscription.
   567  // resourceGroupName - the name of the resource group containing the resource.
   568  // resourceProviderNamespace - the namespace of the resource provider. For example, the namespace of a virtual
   569  // machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines)
   570  // parentResourcePath - the parent resource path. Use empty string if there is none.
   571  // resourceType - the resource type name. For example the type name of a web app is 'sites' (from
   572  // Microsoft.Web/sites).
   573  // resourceName - the name of the resource.
   574  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()',
   575  // 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, no filtering is
   576  // performed. If $filter is not provided, the unfiltered list includes all policy exemptions associated with
   577  // the scope, including those that apply directly or apply from containing scopes. If $filter=atScope() is
   578  // provided, the returned list only includes all policy exemptions that apply to the scope, which is everything
   579  // in the unfiltered list except those applied to sub scopes contained within the given scope. If
   580  // $filter=atExactScope() is provided, the returned list only includes all policy exemptions that at the given
   581  // scope. If $filter=excludeExpired() is provided, the returned list only includes all policy exemptions that
   582  // either haven't expired or didn't set expiration date. If $filter=policyAssignmentId eq '{value}' is
   583  // provided. the returned list only includes all policy exemptions that are associated with the give
   584  // policyAssignmentId.
   585  func (client ExemptionsClient) ListForResource(ctx context.Context, subscriptionID string, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result ExemptionListResultPage, err error) {
   586  	if tracing.IsEnabled() {
   587  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResource")
   588  		defer func() {
   589  			sc := -1
   590  			if result.elr.Response.Response != nil {
   591  				sc = result.elr.Response.Response.StatusCode
   592  			}
   593  			tracing.EndSpan(ctx, sc, err)
   594  		}()
   595  	}
   596  	if err := validation.Validate([]validation.Validation{
   597  		{TargetValue: resourceGroupName,
   598  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   599  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   600  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   601  		return result, validation.NewError("policy.ExemptionsClient", "ListForResource", err.Error())
   602  	}
   603  
   604  	result.fn = client.listForResourceNextResults
   605  	req, err := client.ListForResourcePreparer(ctx, subscriptionID, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
   606  	if err != nil {
   607  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", nil, "Failure preparing request")
   608  		return
   609  	}
   610  
   611  	resp, err := client.ListForResourceSender(req)
   612  	if err != nil {
   613  		result.elr.Response = autorest.Response{Response: resp}
   614  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", resp, "Failure sending request")
   615  		return
   616  	}
   617  
   618  	result.elr, err = client.ListForResourceResponder(resp)
   619  	if err != nil {
   620  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", resp, "Failure responding to request")
   621  		return
   622  	}
   623  	if result.elr.hasNextLink() && result.elr.IsEmpty() {
   624  		err = result.NextWithContext(ctx)
   625  		return
   626  	}
   627  
   628  	return
   629  }
   630  
   631  // ListForResourcePreparer prepares the ListForResource request.
   632  func (client ExemptionsClient) ListForResourcePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (*http.Request, error) {
   633  	pathParameters := map[string]interface{}{
   634  		"parentResourcePath":        parentResourcePath,
   635  		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
   636  		"resourceName":              autorest.Encode("path", resourceName),
   637  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
   638  		"resourceType":              resourceType,
   639  		"subscriptionId":            autorest.Encode("path", subscriptionID),
   640  	}
   641  
   642  	const APIVersion = "2020-07-01-preview"
   643  	queryParameters := map[string]interface{}{
   644  		"api-version": APIVersion,
   645  	}
   646  	if len(filter) > 0 {
   647  		queryParameters["$filter"] = filter
   648  	}
   649  
   650  	preparer := autorest.CreatePreparer(
   651  		autorest.AsGet(),
   652  		autorest.WithBaseURL(client.BaseURI),
   653  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
   654  		autorest.WithQueryParameters(queryParameters))
   655  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   656  }
   657  
   658  // ListForResourceSender sends the ListForResource request. The method will close the
   659  // http.Response Body if it receives an error.
   660  func (client ExemptionsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
   661  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   662  }
   663  
   664  // ListForResourceResponder handles the response to the ListForResource request. The method always
   665  // closes the http.Response Body.
   666  func (client ExemptionsClient) ListForResourceResponder(resp *http.Response) (result ExemptionListResult, err error) {
   667  	err = autorest.Respond(
   668  		resp,
   669  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   670  		autorest.ByUnmarshallingJSON(&result),
   671  		autorest.ByClosing())
   672  	result.Response = autorest.Response{Response: resp}
   673  	return
   674  }
   675  
   676  // listForResourceNextResults retrieves the next set of results, if any.
   677  func (client ExemptionsClient) listForResourceNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
   678  	req, err := lastResults.exemptionListResultPreparer(ctx)
   679  	if err != nil {
   680  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
   681  	}
   682  	if req == nil {
   683  		return
   684  	}
   685  	resp, err := client.ListForResourceSender(req)
   686  	if err != nil {
   687  		result.Response = autorest.Response{Response: resp}
   688  		return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", resp, "Failure sending next results request")
   689  	}
   690  	result, err = client.ListForResourceResponder(resp)
   691  	if err != nil {
   692  		err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
   693  	}
   694  	return
   695  }
   696  
   697  // ListForResourceComplete enumerates all values, automatically crossing page boundaries as required.
   698  func (client ExemptionsClient) ListForResourceComplete(ctx context.Context, subscriptionID string, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result ExemptionListResultIterator, err error) {
   699  	if tracing.IsEnabled() {
   700  		ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResource")
   701  		defer func() {
   702  			sc := -1
   703  			if result.Response().Response.Response != nil {
   704  				sc = result.page.Response().Response.Response.StatusCode
   705  			}
   706  			tracing.EndSpan(ctx, sc, err)
   707  		}()
   708  	}
   709  	result.page, err = client.ListForResource(ctx, subscriptionID, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
   710  	return
   711  }
   712  
   713  // ListForResourceGroup this operation retrieves the list of all policy exemptions associated with the given resource
   714  // group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()',
   715  // 'atExactScope()', 'excludeExpired()' or 'policyAssignmentId eq '{value}''. If $filter is not provided, the
   716  // unfiltered list includes all policy exemptions associated with the resource group, including those that apply
   717  // directly or apply from containing scopes, as well as any applied to resources contained within the resource group.
   718  // Parameters:
   719  // subscriptionID - the ID of the target subscription.
   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, subscriptionID string, 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, subscriptionID, 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, subscriptionID string, resourceGroupName string, filter string) (*http.Request, error) {
   780  	pathParameters := map[string]interface{}{
   781  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   782  		"subscriptionId":    autorest.Encode("path", 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, subscriptionID string, 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, subscriptionID, resourceGroupName, filter)
   853  	return
   854  }
   855  

View as plain text