...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2021-06-01-preview/policy/assignments.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  // AssignmentsClient is the client for the Assignments methods of the Policy service.
    19  type AssignmentsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAssignmentsClient creates an instance of the AssignmentsClient client.
    24  func NewAssignmentsClient(subscriptionID string) AssignmentsClient {
    25  	return NewAssignmentsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewAssignmentsClientWithBaseURI creates an instance of the AssignmentsClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewAssignmentsClientWithBaseURI(baseURI string, subscriptionID string) AssignmentsClient {
    31  	return AssignmentsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Create this operation creates or updates a policy assignment with the given scope and name. Policy assignments apply
    35  // to all resources contained within their scope. For example, when you assign a policy at resource group scope, that
    36  // policy applies to all resources in the group.
    37  // Parameters:
    38  // scope - the scope of the policy assignment. Valid scopes are: management group (format:
    39  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
    40  // '/subscriptions/{subscriptionId}'), resource group (format:
    41  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
    42  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
    43  // policyAssignmentName - the name of the policy assignment.
    44  // parameters - parameters for the policy assignment.
    45  func (client AssignmentsClient) Create(ctx context.Context, scope string, policyAssignmentName string, parameters Assignment) (result Assignment, err error) {
    46  	if tracing.IsEnabled() {
    47  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Create")
    48  		defer func() {
    49  			sc := -1
    50  			if result.Response.Response != nil {
    51  				sc = result.Response.Response.StatusCode
    52  			}
    53  			tracing.EndSpan(ctx, sc, err)
    54  		}()
    55  	}
    56  	req, err := client.CreatePreparer(ctx, scope, policyAssignmentName, parameters)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Create", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.CreateSender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Create", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.CreateResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Create", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // CreatePreparer prepares the Create request.
    79  func (client AssignmentsClient) CreatePreparer(ctx context.Context, scope string, policyAssignmentName string, parameters Assignment) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"policyAssignmentName": autorest.Encode("path", policyAssignmentName),
    82  		"scope":                scope,
    83  	}
    84  
    85  	const APIVersion = "2021-06-01"
    86  	queryParameters := map[string]interface{}{
    87  		"api-version": APIVersion,
    88  	}
    89  
    90  	parameters.ID = nil
    91  	parameters.Type = nil
    92  	parameters.Name = nil
    93  	parameters.SystemData = nil
    94  	preparer := autorest.CreatePreparer(
    95  		autorest.AsContentType("application/json; charset=utf-8"),
    96  		autorest.AsPut(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
    99  		autorest.WithJSON(parameters),
   100  		autorest.WithQueryParameters(queryParameters))
   101  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   102  }
   103  
   104  // CreateSender sends the Create request. The method will close the
   105  // http.Response Body if it receives an error.
   106  func (client AssignmentsClient) CreateSender(req *http.Request) (*http.Response, error) {
   107  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   108  }
   109  
   110  // CreateResponder handles the response to the Create request. The method always
   111  // closes the http.Response Body.
   112  func (client AssignmentsClient) CreateResponder(resp *http.Response) (result Assignment, err error) {
   113  	err = autorest.Respond(
   114  		resp,
   115  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   116  		autorest.ByUnmarshallingJSON(&result),
   117  		autorest.ByClosing())
   118  	result.Response = autorest.Response{Response: resp}
   119  	return
   120  }
   121  
   122  // CreateByID this operation creates or updates the policy assignment with the given ID. Policy assignments made on a
   123  // scope apply to all resources contained in that scope. For example, when you assign a policy to a resource group that
   124  // policy applies to all resources in the group. Policy assignment IDs have this format:
   125  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management
   126  // group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   127  // '/subscriptions/{subscriptionId}'), resource group (format:
   128  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   129  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
   130  // Parameters:
   131  // policyAssignmentID - the ID of the policy assignment to create. Use the format
   132  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   133  // parameters - parameters for policy assignment.
   134  func (client AssignmentsClient) CreateByID(ctx context.Context, policyAssignmentID string, parameters Assignment) (result Assignment, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.CreateByID")
   137  		defer func() {
   138  			sc := -1
   139  			if result.Response.Response != nil {
   140  				sc = result.Response.Response.StatusCode
   141  			}
   142  			tracing.EndSpan(ctx, sc, err)
   143  		}()
   144  	}
   145  	req, err := client.CreateByIDPreparer(ctx, policyAssignmentID, parameters)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", nil, "Failure preparing request")
   148  		return
   149  	}
   150  
   151  	resp, err := client.CreateByIDSender(req)
   152  	if err != nil {
   153  		result.Response = autorest.Response{Response: resp}
   154  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", resp, "Failure sending request")
   155  		return
   156  	}
   157  
   158  	result, err = client.CreateByIDResponder(resp)
   159  	if err != nil {
   160  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", resp, "Failure responding to request")
   161  		return
   162  	}
   163  
   164  	return
   165  }
   166  
   167  // CreateByIDPreparer prepares the CreateByID request.
   168  func (client AssignmentsClient) CreateByIDPreparer(ctx context.Context, policyAssignmentID string, parameters Assignment) (*http.Request, error) {
   169  	pathParameters := map[string]interface{}{
   170  		"policyAssignmentId": policyAssignmentID,
   171  	}
   172  
   173  	const APIVersion = "2021-06-01"
   174  	queryParameters := map[string]interface{}{
   175  		"api-version": APIVersion,
   176  	}
   177  
   178  	parameters.ID = nil
   179  	parameters.Type = nil
   180  	parameters.Name = nil
   181  	parameters.SystemData = nil
   182  	preparer := autorest.CreatePreparer(
   183  		autorest.AsContentType("application/json; charset=utf-8"),
   184  		autorest.AsPut(),
   185  		autorest.WithBaseURL(client.BaseURI),
   186  		autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
   187  		autorest.WithJSON(parameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // CreateByIDSender sends the CreateByID request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client AssignmentsClient) CreateByIDSender(req *http.Request) (*http.Response, error) {
   195  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   196  }
   197  
   198  // CreateByIDResponder handles the response to the CreateByID request. The method always
   199  // closes the http.Response Body.
   200  func (client AssignmentsClient) CreateByIDResponder(resp *http.Response) (result Assignment, err error) {
   201  	err = autorest.Respond(
   202  		resp,
   203  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   204  		autorest.ByUnmarshallingJSON(&result),
   205  		autorest.ByClosing())
   206  	result.Response = autorest.Response{Response: resp}
   207  	return
   208  }
   209  
   210  // Delete this operation deletes a policy assignment, given its name and the scope it was created in. The scope of a
   211  // policy assignment is the part of its ID preceding
   212  // '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   213  // Parameters:
   214  // scope - the scope of the policy assignment. Valid scopes are: management group (format:
   215  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   216  // '/subscriptions/{subscriptionId}'), resource group (format:
   217  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   218  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   219  // policyAssignmentName - the name of the policy assignment to delete.
   220  func (client AssignmentsClient) Delete(ctx context.Context, scope string, policyAssignmentName string) (result Assignment, err error) {
   221  	if tracing.IsEnabled() {
   222  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Delete")
   223  		defer func() {
   224  			sc := -1
   225  			if result.Response.Response != nil {
   226  				sc = result.Response.Response.StatusCode
   227  			}
   228  			tracing.EndSpan(ctx, sc, err)
   229  		}()
   230  	}
   231  	req, err := client.DeletePreparer(ctx, scope, policyAssignmentName)
   232  	if err != nil {
   233  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", nil, "Failure preparing request")
   234  		return
   235  	}
   236  
   237  	resp, err := client.DeleteSender(req)
   238  	if err != nil {
   239  		result.Response = autorest.Response{Response: resp}
   240  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", resp, "Failure sending request")
   241  		return
   242  	}
   243  
   244  	result, err = client.DeleteResponder(resp)
   245  	if err != nil {
   246  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", resp, "Failure responding to request")
   247  		return
   248  	}
   249  
   250  	return
   251  }
   252  
   253  // DeletePreparer prepares the Delete request.
   254  func (client AssignmentsClient) DeletePreparer(ctx context.Context, scope string, policyAssignmentName string) (*http.Request, error) {
   255  	pathParameters := map[string]interface{}{
   256  		"policyAssignmentName": autorest.Encode("path", policyAssignmentName),
   257  		"scope":                scope,
   258  	}
   259  
   260  	const APIVersion = "2021-06-01"
   261  	queryParameters := map[string]interface{}{
   262  		"api-version": APIVersion,
   263  	}
   264  
   265  	preparer := autorest.CreatePreparer(
   266  		autorest.AsDelete(),
   267  		autorest.WithBaseURL(client.BaseURI),
   268  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
   269  		autorest.WithQueryParameters(queryParameters))
   270  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   271  }
   272  
   273  // DeleteSender sends the Delete request. The method will close the
   274  // http.Response Body if it receives an error.
   275  func (client AssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   276  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   277  }
   278  
   279  // DeleteResponder handles the response to the Delete request. The method always
   280  // closes the http.Response Body.
   281  func (client AssignmentsClient) DeleteResponder(resp *http.Response) (result Assignment, err error) {
   282  	err = autorest.Respond(
   283  		resp,
   284  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   285  		autorest.ByUnmarshallingJSON(&result),
   286  		autorest.ByClosing())
   287  	result.Response = autorest.Response{Response: resp}
   288  	return
   289  }
   290  
   291  // DeleteByID this operation deletes the policy with the given ID. Policy assignment IDs have this format:
   292  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid formats for {scope} are:
   293  // '/providers/Microsoft.Management/managementGroups/{managementGroup}' (management group),
   294  // '/subscriptions/{subscriptionId}' (subscription),
   295  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' (resource group), or
   296  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   297  // (resource).
   298  // Parameters:
   299  // policyAssignmentID - the ID of the policy assignment to delete. Use the format
   300  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   301  func (client AssignmentsClient) DeleteByID(ctx context.Context, policyAssignmentID string) (result Assignment, err error) {
   302  	if tracing.IsEnabled() {
   303  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.DeleteByID")
   304  		defer func() {
   305  			sc := -1
   306  			if result.Response.Response != nil {
   307  				sc = result.Response.Response.StatusCode
   308  			}
   309  			tracing.EndSpan(ctx, sc, err)
   310  		}()
   311  	}
   312  	req, err := client.DeleteByIDPreparer(ctx, policyAssignmentID)
   313  	if err != nil {
   314  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", nil, "Failure preparing request")
   315  		return
   316  	}
   317  
   318  	resp, err := client.DeleteByIDSender(req)
   319  	if err != nil {
   320  		result.Response = autorest.Response{Response: resp}
   321  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", resp, "Failure sending request")
   322  		return
   323  	}
   324  
   325  	result, err = client.DeleteByIDResponder(resp)
   326  	if err != nil {
   327  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", resp, "Failure responding to request")
   328  		return
   329  	}
   330  
   331  	return
   332  }
   333  
   334  // DeleteByIDPreparer prepares the DeleteByID request.
   335  func (client AssignmentsClient) DeleteByIDPreparer(ctx context.Context, policyAssignmentID string) (*http.Request, error) {
   336  	pathParameters := map[string]interface{}{
   337  		"policyAssignmentId": policyAssignmentID,
   338  	}
   339  
   340  	const APIVersion = "2021-06-01"
   341  	queryParameters := map[string]interface{}{
   342  		"api-version": APIVersion,
   343  	}
   344  
   345  	preparer := autorest.CreatePreparer(
   346  		autorest.AsDelete(),
   347  		autorest.WithBaseURL(client.BaseURI),
   348  		autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
   349  		autorest.WithQueryParameters(queryParameters))
   350  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   351  }
   352  
   353  // DeleteByIDSender sends the DeleteByID request. The method will close the
   354  // http.Response Body if it receives an error.
   355  func (client AssignmentsClient) DeleteByIDSender(req *http.Request) (*http.Response, error) {
   356  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   357  }
   358  
   359  // DeleteByIDResponder handles the response to the DeleteByID request. The method always
   360  // closes the http.Response Body.
   361  func (client AssignmentsClient) DeleteByIDResponder(resp *http.Response) (result Assignment, err error) {
   362  	err = autorest.Respond(
   363  		resp,
   364  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   365  		autorest.ByUnmarshallingJSON(&result),
   366  		autorest.ByClosing())
   367  	result.Response = autorest.Response{Response: resp}
   368  	return
   369  }
   370  
   371  // Get this operation retrieves a single policy assignment, given its name and the scope it was created at.
   372  // Parameters:
   373  // scope - the scope of the policy assignment. Valid scopes are: management group (format:
   374  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   375  // '/subscriptions/{subscriptionId}'), resource group (format:
   376  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   377  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   378  // policyAssignmentName - the name of the policy assignment to get.
   379  func (client AssignmentsClient) Get(ctx context.Context, scope string, policyAssignmentName string) (result Assignment, err error) {
   380  	if tracing.IsEnabled() {
   381  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Get")
   382  		defer func() {
   383  			sc := -1
   384  			if result.Response.Response != nil {
   385  				sc = result.Response.Response.StatusCode
   386  			}
   387  			tracing.EndSpan(ctx, sc, err)
   388  		}()
   389  	}
   390  	req, err := client.GetPreparer(ctx, scope, policyAssignmentName)
   391  	if err != nil {
   392  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", nil, "Failure preparing request")
   393  		return
   394  	}
   395  
   396  	resp, err := client.GetSender(req)
   397  	if err != nil {
   398  		result.Response = autorest.Response{Response: resp}
   399  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", resp, "Failure sending request")
   400  		return
   401  	}
   402  
   403  	result, err = client.GetResponder(resp)
   404  	if err != nil {
   405  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", resp, "Failure responding to request")
   406  		return
   407  	}
   408  
   409  	return
   410  }
   411  
   412  // GetPreparer prepares the Get request.
   413  func (client AssignmentsClient) GetPreparer(ctx context.Context, scope string, policyAssignmentName string) (*http.Request, error) {
   414  	pathParameters := map[string]interface{}{
   415  		"policyAssignmentName": autorest.Encode("path", policyAssignmentName),
   416  		"scope":                scope,
   417  	}
   418  
   419  	const APIVersion = "2021-06-01"
   420  	queryParameters := map[string]interface{}{
   421  		"api-version": APIVersion,
   422  	}
   423  
   424  	preparer := autorest.CreatePreparer(
   425  		autorest.AsGet(),
   426  		autorest.WithBaseURL(client.BaseURI),
   427  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
   428  		autorest.WithQueryParameters(queryParameters))
   429  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   430  }
   431  
   432  // GetSender sends the Get request. The method will close the
   433  // http.Response Body if it receives an error.
   434  func (client AssignmentsClient) GetSender(req *http.Request) (*http.Response, error) {
   435  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   436  }
   437  
   438  // GetResponder handles the response to the Get request. The method always
   439  // closes the http.Response Body.
   440  func (client AssignmentsClient) GetResponder(resp *http.Response) (result Assignment, err error) {
   441  	err = autorest.Respond(
   442  		resp,
   443  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   444  		autorest.ByUnmarshallingJSON(&result),
   445  		autorest.ByClosing())
   446  	result.Response = autorest.Response{Response: resp}
   447  	return
   448  }
   449  
   450  // GetByID the operation retrieves the policy assignment with the given ID. Policy assignment IDs have this format:
   451  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management
   452  // group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
   453  // '/subscriptions/{subscriptionId}'), resource group (format:
   454  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
   455  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
   456  // Parameters:
   457  // policyAssignmentID - the ID of the policy assignment to get. Use the format
   458  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   459  func (client AssignmentsClient) GetByID(ctx context.Context, policyAssignmentID string) (result Assignment, err error) {
   460  	if tracing.IsEnabled() {
   461  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.GetByID")
   462  		defer func() {
   463  			sc := -1
   464  			if result.Response.Response != nil {
   465  				sc = result.Response.Response.StatusCode
   466  			}
   467  			tracing.EndSpan(ctx, sc, err)
   468  		}()
   469  	}
   470  	req, err := client.GetByIDPreparer(ctx, policyAssignmentID)
   471  	if err != nil {
   472  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", nil, "Failure preparing request")
   473  		return
   474  	}
   475  
   476  	resp, err := client.GetByIDSender(req)
   477  	if err != nil {
   478  		result.Response = autorest.Response{Response: resp}
   479  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", resp, "Failure sending request")
   480  		return
   481  	}
   482  
   483  	result, err = client.GetByIDResponder(resp)
   484  	if err != nil {
   485  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", resp, "Failure responding to request")
   486  		return
   487  	}
   488  
   489  	return
   490  }
   491  
   492  // GetByIDPreparer prepares the GetByID request.
   493  func (client AssignmentsClient) GetByIDPreparer(ctx context.Context, policyAssignmentID string) (*http.Request, error) {
   494  	pathParameters := map[string]interface{}{
   495  		"policyAssignmentId": policyAssignmentID,
   496  	}
   497  
   498  	const APIVersion = "2021-06-01"
   499  	queryParameters := map[string]interface{}{
   500  		"api-version": APIVersion,
   501  	}
   502  
   503  	preparer := autorest.CreatePreparer(
   504  		autorest.AsGet(),
   505  		autorest.WithBaseURL(client.BaseURI),
   506  		autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
   507  		autorest.WithQueryParameters(queryParameters))
   508  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   509  }
   510  
   511  // GetByIDSender sends the GetByID request. The method will close the
   512  // http.Response Body if it receives an error.
   513  func (client AssignmentsClient) GetByIDSender(req *http.Request) (*http.Response, error) {
   514  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   515  }
   516  
   517  // GetByIDResponder handles the response to the GetByID request. The method always
   518  // closes the http.Response Body.
   519  func (client AssignmentsClient) GetByIDResponder(resp *http.Response) (result Assignment, err error) {
   520  	err = autorest.Respond(
   521  		resp,
   522  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   523  		autorest.ByUnmarshallingJSON(&result),
   524  		autorest.ByClosing())
   525  	result.Response = autorest.Response{Response: resp}
   526  	return
   527  }
   528  
   529  // List this operation retrieves the list of all policy assignments associated with the given subscription that match
   530  // the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq
   531  // '{value}”. If $filter is not provided, the unfiltered list includes all policy assignments associated with the
   532  // subscription, including those that apply directly or from management groups that contain the given subscription, as
   533  // well as any applied to objects contained within the subscription. If $filter=atScope() is provided, the returned
   534  // list includes all policy assignments that apply to the subscription, which is everything in the unfiltered list
   535  // except those applied to objects contained within the subscription. If $filter=atExactScope() is provided, the
   536  // returned list only includes all policy assignments that at the subscription. If $filter=policyDefinitionId eq
   537  // '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is
   538  // {value}.
   539  // Parameters:
   540  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()'
   541  // or 'policyDefinitionId eq '{value}”. If $filter is not provided, no filtering is performed. If
   542  // $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the
   543  // scope, which is everything in the unfiltered list except those applied to sub scopes contained within the
   544  // given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments
   545  // that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes
   546  // all policy assignments of the policy definition whose id is {value}.
   547  // top - maximum number of records to return. When the $top filter is not provided, it will return 500 records.
   548  func (client AssignmentsClient) List(ctx context.Context, filter string, top *int32) (result AssignmentListResultPage, err error) {
   549  	if tracing.IsEnabled() {
   550  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List")
   551  		defer func() {
   552  			sc := -1
   553  			if result.alr.Response.Response != nil {
   554  				sc = result.alr.Response.Response.StatusCode
   555  			}
   556  			tracing.EndSpan(ctx, sc, err)
   557  		}()
   558  	}
   559  	if err := validation.Validate([]validation.Validation{
   560  		{TargetValue: top,
   561  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   562  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
   563  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   564  				}}}}}); err != nil {
   565  		return result, validation.NewError("policy.AssignmentsClient", "List", err.Error())
   566  	}
   567  
   568  	result.fn = client.listNextResults
   569  	req, err := client.ListPreparer(ctx, filter, top)
   570  	if err != nil {
   571  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", nil, "Failure preparing request")
   572  		return
   573  	}
   574  
   575  	resp, err := client.ListSender(req)
   576  	if err != nil {
   577  		result.alr.Response = autorest.Response{Response: resp}
   578  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", resp, "Failure sending request")
   579  		return
   580  	}
   581  
   582  	result.alr, err = client.ListResponder(resp)
   583  	if err != nil {
   584  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", resp, "Failure responding to request")
   585  		return
   586  	}
   587  	if result.alr.hasNextLink() && result.alr.IsEmpty() {
   588  		err = result.NextWithContext(ctx)
   589  		return
   590  	}
   591  
   592  	return
   593  }
   594  
   595  // ListPreparer prepares the List request.
   596  func (client AssignmentsClient) ListPreparer(ctx context.Context, filter string, top *int32) (*http.Request, error) {
   597  	pathParameters := map[string]interface{}{
   598  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   599  	}
   600  
   601  	const APIVersion = "2021-06-01"
   602  	queryParameters := map[string]interface{}{
   603  		"api-version": APIVersion,
   604  	}
   605  	if len(filter) > 0 {
   606  		queryParameters["$filter"] = filter
   607  	}
   608  	if top != nil {
   609  		queryParameters["$top"] = autorest.Encode("query", *top)
   610  	}
   611  
   612  	preparer := autorest.CreatePreparer(
   613  		autorest.AsGet(),
   614  		autorest.WithBaseURL(client.BaseURI),
   615  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
   616  		autorest.WithQueryParameters(queryParameters))
   617  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   618  }
   619  
   620  // ListSender sends the List request. The method will close the
   621  // http.Response Body if it receives an error.
   622  func (client AssignmentsClient) ListSender(req *http.Request) (*http.Response, error) {
   623  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   624  }
   625  
   626  // ListResponder handles the response to the List request. The method always
   627  // closes the http.Response Body.
   628  func (client AssignmentsClient) ListResponder(resp *http.Response) (result AssignmentListResult, err error) {
   629  	err = autorest.Respond(
   630  		resp,
   631  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   632  		autorest.ByUnmarshallingJSON(&result),
   633  		autorest.ByClosing())
   634  	result.Response = autorest.Response{Response: resp}
   635  	return
   636  }
   637  
   638  // listNextResults retrieves the next set of results, if any.
   639  func (client AssignmentsClient) listNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
   640  	req, err := lastResults.assignmentListResultPreparer(ctx)
   641  	if err != nil {
   642  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", nil, "Failure preparing next results request")
   643  	}
   644  	if req == nil {
   645  		return
   646  	}
   647  	resp, err := client.ListSender(req)
   648  	if err != nil {
   649  		result.Response = autorest.Response{Response: resp}
   650  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", resp, "Failure sending next results request")
   651  	}
   652  	result, err = client.ListResponder(resp)
   653  	if err != nil {
   654  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", resp, "Failure responding to next results request")
   655  	}
   656  	return
   657  }
   658  
   659  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   660  func (client AssignmentsClient) ListComplete(ctx context.Context, filter string, top *int32) (result AssignmentListResultIterator, err error) {
   661  	if tracing.IsEnabled() {
   662  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List")
   663  		defer func() {
   664  			sc := -1
   665  			if result.Response().Response.Response != nil {
   666  				sc = result.page.Response().Response.Response.StatusCode
   667  			}
   668  			tracing.EndSpan(ctx, sc, err)
   669  		}()
   670  	}
   671  	result.page, err = client.List(ctx, filter, top)
   672  	return
   673  }
   674  
   675  // ListForManagementGroup this operation retrieves the list of all policy assignments applicable to the management
   676  // group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or
   677  // 'policyDefinitionId eq '{value}”. If $filter=atScope() is provided, the returned list includes all policy
   678  // assignments that are assigned to the management group or the management group's ancestors. If $filter=atExactScope()
   679  // is provided, the returned list only includes all policy assignments that at the management group. If
   680  // $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy
   681  // definition whose id is {value} that apply to the management group.
   682  // Parameters:
   683  // managementGroupID - the ID of the management group.
   684  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()'
   685  // or 'policyDefinitionId eq '{value}”. If $filter is not provided, no filtering is performed. If
   686  // $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the
   687  // scope, which is everything in the unfiltered list except those applied to sub scopes contained within the
   688  // given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments
   689  // that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes
   690  // all policy assignments of the policy definition whose id is {value}.
   691  // top - maximum number of records to return. When the $top filter is not provided, it will return 500 records.
   692  func (client AssignmentsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, filter string, top *int32) (result AssignmentListResultPage, err error) {
   693  	if tracing.IsEnabled() {
   694  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForManagementGroup")
   695  		defer func() {
   696  			sc := -1
   697  			if result.alr.Response.Response != nil {
   698  				sc = result.alr.Response.Response.StatusCode
   699  			}
   700  			tracing.EndSpan(ctx, sc, err)
   701  		}()
   702  	}
   703  	if err := validation.Validate([]validation.Validation{
   704  		{TargetValue: top,
   705  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   706  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
   707  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   708  				}}}}}); err != nil {
   709  		return result, validation.NewError("policy.AssignmentsClient", "ListForManagementGroup", err.Error())
   710  	}
   711  
   712  	result.fn = client.listForManagementGroupNextResults
   713  	req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, filter, top)
   714  	if err != nil {
   715  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", nil, "Failure preparing request")
   716  		return
   717  	}
   718  
   719  	resp, err := client.ListForManagementGroupSender(req)
   720  	if err != nil {
   721  		result.alr.Response = autorest.Response{Response: resp}
   722  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", resp, "Failure sending request")
   723  		return
   724  	}
   725  
   726  	result.alr, err = client.ListForManagementGroupResponder(resp)
   727  	if err != nil {
   728  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", resp, "Failure responding to request")
   729  		return
   730  	}
   731  	if result.alr.hasNextLink() && result.alr.IsEmpty() {
   732  		err = result.NextWithContext(ctx)
   733  		return
   734  	}
   735  
   736  	return
   737  }
   738  
   739  // ListForManagementGroupPreparer prepares the ListForManagementGroup request.
   740  func (client AssignmentsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, filter string, top *int32) (*http.Request, error) {
   741  	pathParameters := map[string]interface{}{
   742  		"managementGroupId": autorest.Encode("path", managementGroupID),
   743  	}
   744  
   745  	const APIVersion = "2021-06-01"
   746  	queryParameters := map[string]interface{}{
   747  		"api-version": APIVersion,
   748  	}
   749  	if len(filter) > 0 {
   750  		queryParameters["$filter"] = filter
   751  	}
   752  	if top != nil {
   753  		queryParameters["$top"] = autorest.Encode("query", *top)
   754  	}
   755  
   756  	preparer := autorest.CreatePreparer(
   757  		autorest.AsGet(),
   758  		autorest.WithBaseURL(client.BaseURI),
   759  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
   760  		autorest.WithQueryParameters(queryParameters))
   761  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   762  }
   763  
   764  // ListForManagementGroupSender sends the ListForManagementGroup request. The method will close the
   765  // http.Response Body if it receives an error.
   766  func (client AssignmentsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
   767  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   768  }
   769  
   770  // ListForManagementGroupResponder handles the response to the ListForManagementGroup request. The method always
   771  // closes the http.Response Body.
   772  func (client AssignmentsClient) ListForManagementGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
   773  	err = autorest.Respond(
   774  		resp,
   775  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   776  		autorest.ByUnmarshallingJSON(&result),
   777  		autorest.ByClosing())
   778  	result.Response = autorest.Response{Response: resp}
   779  	return
   780  }
   781  
   782  // listForManagementGroupNextResults retrieves the next set of results, if any.
   783  func (client AssignmentsClient) listForManagementGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
   784  	req, err := lastResults.assignmentListResultPreparer(ctx)
   785  	if err != nil {
   786  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
   787  	}
   788  	if req == nil {
   789  		return
   790  	}
   791  	resp, err := client.ListForManagementGroupSender(req)
   792  	if err != nil {
   793  		result.Response = autorest.Response{Response: resp}
   794  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
   795  	}
   796  	result, err = client.ListForManagementGroupResponder(resp)
   797  	if err != nil {
   798  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
   799  	}
   800  	return
   801  }
   802  
   803  // ListForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required.
   804  func (client AssignmentsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
   805  	if tracing.IsEnabled() {
   806  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForManagementGroup")
   807  		defer func() {
   808  			sc := -1
   809  			if result.Response().Response.Response != nil {
   810  				sc = result.page.Response().Response.Response.StatusCode
   811  			}
   812  			tracing.EndSpan(ctx, sc, err)
   813  		}()
   814  	}
   815  	result.page, err = client.ListForManagementGroup(ctx, managementGroupID, filter, top)
   816  	return
   817  }
   818  
   819  // ListForResource this operation retrieves the list of all policy assignments associated with the specified resource
   820  // in the given resource group and subscription that match the optional given $filter. Valid values for $filter are:
   821  // 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}”. If $filter is not provided, the unfiltered list
   822  // includes all policy assignments associated with the resource, including those that apply directly or from all
   823  // containing scopes, as well as any applied to resources contained within the resource. If $filter=atScope() is
   824  // provided, the returned list includes all policy assignments that apply to the resource, which is everything in the
   825  // unfiltered list except those applied to resources contained within the resource. If $filter=atExactScope() is
   826  // provided, the returned list only includes all policy assignments that at the resource level. If
   827  // $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy
   828  // definition whose id is {value} that apply to the resource. Three parameters plus the resource name are used to
   829  // identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent
   830  // resource path should not be provided (or provided as ”). For example a web app could be specified as
   831  // ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == ”, {resourceType} == 'sites',
   832  // {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided.
   833  // For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
   834  // {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} ==
   835  // 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both
   836  // in the {resourceType} parameter, format: ({resourceProviderNamespace} == ”, {parentResourcePath} == ”,
   837  // {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   838  // Parameters:
   839  // resourceGroupName - the name of the resource group containing the resource.
   840  // resourceProviderNamespace - the namespace of the resource provider. For example, the namespace of a virtual
   841  // machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines)
   842  // parentResourcePath - the parent resource path. Use empty string if there is none.
   843  // resourceType - the resource type name. For example the type name of a web app is 'sites' (from
   844  // Microsoft.Web/sites).
   845  // resourceName - the name of the resource.
   846  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()'
   847  // or 'policyDefinitionId eq '{value}”. If $filter is not provided, no filtering is performed. If
   848  // $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the
   849  // scope, which is everything in the unfiltered list except those applied to sub scopes contained within the
   850  // given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments
   851  // that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes
   852  // all policy assignments of the policy definition whose id is {value}.
   853  // top - maximum number of records to return. When the $top filter is not provided, it will return 500 records.
   854  func (client AssignmentsClient) ListForResource(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (result AssignmentListResultPage, err error) {
   855  	if tracing.IsEnabled() {
   856  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
   857  		defer func() {
   858  			sc := -1
   859  			if result.alr.Response.Response != nil {
   860  				sc = result.alr.Response.Response.StatusCode
   861  			}
   862  			tracing.EndSpan(ctx, sc, err)
   863  		}()
   864  	}
   865  	if err := validation.Validate([]validation.Validation{
   866  		{TargetValue: resourceGroupName,
   867  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   868  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   869  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}},
   870  		{TargetValue: top,
   871  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
   872  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
   873  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
   874  				}}}}}); err != nil {
   875  		return result, validation.NewError("policy.AssignmentsClient", "ListForResource", err.Error())
   876  	}
   877  
   878  	result.fn = client.listForResourceNextResults
   879  	req, err := client.ListForResourcePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter, top)
   880  	if err != nil {
   881  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", nil, "Failure preparing request")
   882  		return
   883  	}
   884  
   885  	resp, err := client.ListForResourceSender(req)
   886  	if err != nil {
   887  		result.alr.Response = autorest.Response{Response: resp}
   888  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure sending request")
   889  		return
   890  	}
   891  
   892  	result.alr, err = client.ListForResourceResponder(resp)
   893  	if err != nil {
   894  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure responding to request")
   895  		return
   896  	}
   897  	if result.alr.hasNextLink() && result.alr.IsEmpty() {
   898  		err = result.NextWithContext(ctx)
   899  		return
   900  	}
   901  
   902  	return
   903  }
   904  
   905  // ListForResourcePreparer prepares the ListForResource request.
   906  func (client AssignmentsClient) ListForResourcePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (*http.Request, error) {
   907  	pathParameters := map[string]interface{}{
   908  		"parentResourcePath":        parentResourcePath,
   909  		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
   910  		"resourceName":              autorest.Encode("path", resourceName),
   911  		"resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
   912  		"resourceType":              resourceType,
   913  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
   914  	}
   915  
   916  	const APIVersion = "2021-06-01"
   917  	queryParameters := map[string]interface{}{
   918  		"api-version": APIVersion,
   919  	}
   920  	if len(filter) > 0 {
   921  		queryParameters["$filter"] = filter
   922  	}
   923  	if top != nil {
   924  		queryParameters["$top"] = autorest.Encode("query", *top)
   925  	}
   926  
   927  	preparer := autorest.CreatePreparer(
   928  		autorest.AsGet(),
   929  		autorest.WithBaseURL(client.BaseURI),
   930  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
   931  		autorest.WithQueryParameters(queryParameters))
   932  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   933  }
   934  
   935  // ListForResourceSender sends the ListForResource request. The method will close the
   936  // http.Response Body if it receives an error.
   937  func (client AssignmentsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
   938  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   939  }
   940  
   941  // ListForResourceResponder handles the response to the ListForResource request. The method always
   942  // closes the http.Response Body.
   943  func (client AssignmentsClient) ListForResourceResponder(resp *http.Response) (result AssignmentListResult, err error) {
   944  	err = autorest.Respond(
   945  		resp,
   946  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   947  		autorest.ByUnmarshallingJSON(&result),
   948  		autorest.ByClosing())
   949  	result.Response = autorest.Response{Response: resp}
   950  	return
   951  }
   952  
   953  // listForResourceNextResults retrieves the next set of results, if any.
   954  func (client AssignmentsClient) listForResourceNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
   955  	req, err := lastResults.assignmentListResultPreparer(ctx)
   956  	if err != nil {
   957  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
   958  	}
   959  	if req == nil {
   960  		return
   961  	}
   962  	resp, err := client.ListForResourceSender(req)
   963  	if err != nil {
   964  		result.Response = autorest.Response{Response: resp}
   965  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure sending next results request")
   966  	}
   967  	result, err = client.ListForResourceResponder(resp)
   968  	if err != nil {
   969  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
   970  	}
   971  	return
   972  }
   973  
   974  // ListForResourceComplete enumerates all values, automatically crossing page boundaries as required.
   975  func (client AssignmentsClient) ListForResourceComplete(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
   976  	if tracing.IsEnabled() {
   977  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
   978  		defer func() {
   979  			sc := -1
   980  			if result.Response().Response.Response != nil {
   981  				sc = result.page.Response().Response.Response.StatusCode
   982  			}
   983  			tracing.EndSpan(ctx, sc, err)
   984  		}()
   985  	}
   986  	result.page, err = client.ListForResource(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter, top)
   987  	return
   988  }
   989  
   990  // ListForResourceGroup this operation retrieves the list of all policy assignments associated with the given resource
   991  // group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()',
   992  // 'atExactScope()' or 'policyDefinitionId eq '{value}”. If $filter is not provided, the unfiltered list includes all
   993  // policy assignments associated with the resource group, including those that apply directly or apply from containing
   994  // scopes, as well as any applied to resources contained within the resource group. If $filter=atScope() is provided,
   995  // the returned list includes all policy assignments that apply to the resource group, which is everything in the
   996  // unfiltered list except those applied to resources contained within the resource group. If $filter=atExactScope() is
   997  // provided, the returned list only includes all policy assignments that at the resource group. If
   998  // $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy
   999  // definition whose id is {value} that apply to the resource group.
  1000  // Parameters:
  1001  // resourceGroupName - the name of the resource group that contains policy assignments.
  1002  // filter - the filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()'
  1003  // or 'policyDefinitionId eq '{value}”. If $filter is not provided, no filtering is performed. If
  1004  // $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the
  1005  // scope, which is everything in the unfiltered list except those applied to sub scopes contained within the
  1006  // given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments
  1007  // that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes
  1008  // all policy assignments of the policy definition whose id is {value}.
  1009  // top - maximum number of records to return. When the $top filter is not provided, it will return 500 records.
  1010  func (client AssignmentsClient) ListForResourceGroup(ctx context.Context, resourceGroupName string, filter string, top *int32) (result AssignmentListResultPage, err error) {
  1011  	if tracing.IsEnabled() {
  1012  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
  1013  		defer func() {
  1014  			sc := -1
  1015  			if result.alr.Response.Response != nil {
  1016  				sc = result.alr.Response.Response.StatusCode
  1017  			}
  1018  			tracing.EndSpan(ctx, sc, err)
  1019  		}()
  1020  	}
  1021  	if err := validation.Validate([]validation.Validation{
  1022  		{TargetValue: resourceGroupName,
  1023  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
  1024  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
  1025  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}},
  1026  		{TargetValue: top,
  1027  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
  1028  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
  1029  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
  1030  				}}}}}); err != nil {
  1031  		return result, validation.NewError("policy.AssignmentsClient", "ListForResourceGroup", err.Error())
  1032  	}
  1033  
  1034  	result.fn = client.listForResourceGroupNextResults
  1035  	req, err := client.ListForResourceGroupPreparer(ctx, resourceGroupName, filter, top)
  1036  	if err != nil {
  1037  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", nil, "Failure preparing request")
  1038  		return
  1039  	}
  1040  
  1041  	resp, err := client.ListForResourceGroupSender(req)
  1042  	if err != nil {
  1043  		result.alr.Response = autorest.Response{Response: resp}
  1044  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure sending request")
  1045  		return
  1046  	}
  1047  
  1048  	result.alr, err = client.ListForResourceGroupResponder(resp)
  1049  	if err != nil {
  1050  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure responding to request")
  1051  		return
  1052  	}
  1053  	if result.alr.hasNextLink() && result.alr.IsEmpty() {
  1054  		err = result.NextWithContext(ctx)
  1055  		return
  1056  	}
  1057  
  1058  	return
  1059  }
  1060  
  1061  // ListForResourceGroupPreparer prepares the ListForResourceGroup request.
  1062  func (client AssignmentsClient) ListForResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string, top *int32) (*http.Request, error) {
  1063  	pathParameters := map[string]interface{}{
  1064  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
  1065  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
  1066  	}
  1067  
  1068  	const APIVersion = "2021-06-01"
  1069  	queryParameters := map[string]interface{}{
  1070  		"api-version": APIVersion,
  1071  	}
  1072  	if len(filter) > 0 {
  1073  		queryParameters["$filter"] = filter
  1074  	}
  1075  	if top != nil {
  1076  		queryParameters["$top"] = autorest.Encode("query", *top)
  1077  	}
  1078  
  1079  	preparer := autorest.CreatePreparer(
  1080  		autorest.AsGet(),
  1081  		autorest.WithBaseURL(client.BaseURI),
  1082  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
  1083  		autorest.WithQueryParameters(queryParameters))
  1084  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1085  }
  1086  
  1087  // ListForResourceGroupSender sends the ListForResourceGroup request. The method will close the
  1088  // http.Response Body if it receives an error.
  1089  func (client AssignmentsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) {
  1090  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
  1091  }
  1092  
  1093  // ListForResourceGroupResponder handles the response to the ListForResourceGroup request. The method always
  1094  // closes the http.Response Body.
  1095  func (client AssignmentsClient) ListForResourceGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
  1096  	err = autorest.Respond(
  1097  		resp,
  1098  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1099  		autorest.ByUnmarshallingJSON(&result),
  1100  		autorest.ByClosing())
  1101  	result.Response = autorest.Response{Response: resp}
  1102  	return
  1103  }
  1104  
  1105  // listForResourceGroupNextResults retrieves the next set of results, if any.
  1106  func (client AssignmentsClient) listForResourceGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
  1107  	req, err := lastResults.assignmentListResultPreparer(ctx)
  1108  	if err != nil {
  1109  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request")
  1110  	}
  1111  	if req == nil {
  1112  		return
  1113  	}
  1114  	resp, err := client.ListForResourceGroupSender(req)
  1115  	if err != nil {
  1116  		result.Response = autorest.Response{Response: resp}
  1117  		return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request")
  1118  	}
  1119  	result, err = client.ListForResourceGroupResponder(resp)
  1120  	if err != nil {
  1121  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request")
  1122  	}
  1123  	return
  1124  }
  1125  
  1126  // ListForResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
  1127  func (client AssignmentsClient) ListForResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
  1128  	if tracing.IsEnabled() {
  1129  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
  1130  		defer func() {
  1131  			sc := -1
  1132  			if result.Response().Response.Response != nil {
  1133  				sc = result.page.Response().Response.Response.StatusCode
  1134  			}
  1135  			tracing.EndSpan(ctx, sc, err)
  1136  		}()
  1137  	}
  1138  	result.page, err = client.ListForResourceGroup(ctx, resourceGroupName, filter, top)
  1139  	return
  1140  }
  1141  
  1142  // Update this operation updates a policy assignment with the given scope and name. Policy assignments apply to all
  1143  // resources contained within their scope. For example, when you assign a policy at resource group scope, that policy
  1144  // applies to all resources in the group.
  1145  // Parameters:
  1146  // scope - the scope of the policy assignment. Valid scopes are: management group (format:
  1147  // '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
  1148  // '/subscriptions/{subscriptionId}'), resource group (format:
  1149  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
  1150  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
  1151  // policyAssignmentName - the name of the policy assignment.
  1152  // parameters - parameters for policy assignment patch request.
  1153  func (client AssignmentsClient) Update(ctx context.Context, scope string, policyAssignmentName string, parameters AssignmentUpdate) (result Assignment, err error) {
  1154  	if tracing.IsEnabled() {
  1155  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Update")
  1156  		defer func() {
  1157  			sc := -1
  1158  			if result.Response.Response != nil {
  1159  				sc = result.Response.Response.StatusCode
  1160  			}
  1161  			tracing.EndSpan(ctx, sc, err)
  1162  		}()
  1163  	}
  1164  	req, err := client.UpdatePreparer(ctx, scope, policyAssignmentName, parameters)
  1165  	if err != nil {
  1166  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Update", nil, "Failure preparing request")
  1167  		return
  1168  	}
  1169  
  1170  	resp, err := client.UpdateSender(req)
  1171  	if err != nil {
  1172  		result.Response = autorest.Response{Response: resp}
  1173  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Update", resp, "Failure sending request")
  1174  		return
  1175  	}
  1176  
  1177  	result, err = client.UpdateResponder(resp)
  1178  	if err != nil {
  1179  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Update", resp, "Failure responding to request")
  1180  		return
  1181  	}
  1182  
  1183  	return
  1184  }
  1185  
  1186  // UpdatePreparer prepares the Update request.
  1187  func (client AssignmentsClient) UpdatePreparer(ctx context.Context, scope string, policyAssignmentName string, parameters AssignmentUpdate) (*http.Request, error) {
  1188  	pathParameters := map[string]interface{}{
  1189  		"policyAssignmentName": autorest.Encode("path", policyAssignmentName),
  1190  		"scope":                scope,
  1191  	}
  1192  
  1193  	const APIVersion = "2021-06-01"
  1194  	queryParameters := map[string]interface{}{
  1195  		"api-version": APIVersion,
  1196  	}
  1197  
  1198  	preparer := autorest.CreatePreparer(
  1199  		autorest.AsContentType("application/json; charset=utf-8"),
  1200  		autorest.AsPatch(),
  1201  		autorest.WithBaseURL(client.BaseURI),
  1202  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
  1203  		autorest.WithJSON(parameters),
  1204  		autorest.WithQueryParameters(queryParameters))
  1205  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1206  }
  1207  
  1208  // UpdateSender sends the Update request. The method will close the
  1209  // http.Response Body if it receives an error.
  1210  func (client AssignmentsClient) UpdateSender(req *http.Request) (*http.Response, error) {
  1211  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1212  }
  1213  
  1214  // UpdateResponder handles the response to the Update request. The method always
  1215  // closes the http.Response Body.
  1216  func (client AssignmentsClient) UpdateResponder(resp *http.Response) (result Assignment, err error) {
  1217  	err = autorest.Respond(
  1218  		resp,
  1219  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1220  		autorest.ByUnmarshallingJSON(&result),
  1221  		autorest.ByClosing())
  1222  	result.Response = autorest.Response{Response: resp}
  1223  	return
  1224  }
  1225  
  1226  // UpdateByID this operation updates the policy assignment with the given ID. Policy assignments made on a scope apply
  1227  // to all resources contained in that scope. For example, when you assign a policy to a resource group that policy
  1228  // applies to all resources in the group. Policy assignment IDs have this format:
  1229  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. Valid scopes are: management
  1230  // group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), subscription (format:
  1231  // '/subscriptions/{subscriptionId}'), resource group (format:
  1232  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format:
  1233  // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
  1234  // Parameters:
  1235  // policyAssignmentID - the ID of the policy assignment to update. Use the format
  1236  // '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
  1237  // parameters - parameters for policy assignment patch request.
  1238  func (client AssignmentsClient) UpdateByID(ctx context.Context, policyAssignmentID string, parameters AssignmentUpdate) (result Assignment, err error) {
  1239  	if tracing.IsEnabled() {
  1240  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.UpdateByID")
  1241  		defer func() {
  1242  			sc := -1
  1243  			if result.Response.Response != nil {
  1244  				sc = result.Response.Response.StatusCode
  1245  			}
  1246  			tracing.EndSpan(ctx, sc, err)
  1247  		}()
  1248  	}
  1249  	req, err := client.UpdateByIDPreparer(ctx, policyAssignmentID, parameters)
  1250  	if err != nil {
  1251  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "UpdateByID", nil, "Failure preparing request")
  1252  		return
  1253  	}
  1254  
  1255  	resp, err := client.UpdateByIDSender(req)
  1256  	if err != nil {
  1257  		result.Response = autorest.Response{Response: resp}
  1258  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "UpdateByID", resp, "Failure sending request")
  1259  		return
  1260  	}
  1261  
  1262  	result, err = client.UpdateByIDResponder(resp)
  1263  	if err != nil {
  1264  		err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "UpdateByID", resp, "Failure responding to request")
  1265  		return
  1266  	}
  1267  
  1268  	return
  1269  }
  1270  
  1271  // UpdateByIDPreparer prepares the UpdateByID request.
  1272  func (client AssignmentsClient) UpdateByIDPreparer(ctx context.Context, policyAssignmentID string, parameters AssignmentUpdate) (*http.Request, error) {
  1273  	pathParameters := map[string]interface{}{
  1274  		"policyAssignmentId": policyAssignmentID,
  1275  	}
  1276  
  1277  	const APIVersion = "2021-06-01"
  1278  	queryParameters := map[string]interface{}{
  1279  		"api-version": APIVersion,
  1280  	}
  1281  
  1282  	preparer := autorest.CreatePreparer(
  1283  		autorest.AsContentType("application/json; charset=utf-8"),
  1284  		autorest.AsPatch(),
  1285  		autorest.WithBaseURL(client.BaseURI),
  1286  		autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
  1287  		autorest.WithJSON(parameters),
  1288  		autorest.WithQueryParameters(queryParameters))
  1289  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
  1290  }
  1291  
  1292  // UpdateByIDSender sends the UpdateByID request. The method will close the
  1293  // http.Response Body if it receives an error.
  1294  func (client AssignmentsClient) UpdateByIDSender(req *http.Request) (*http.Response, error) {
  1295  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  1296  }
  1297  
  1298  // UpdateByIDResponder handles the response to the UpdateByID request. The method always
  1299  // closes the http.Response Body.
  1300  func (client AssignmentsClient) UpdateByIDResponder(resp *http.Response) (result Assignment, err error) {
  1301  	err = autorest.Respond(
  1302  		resp,
  1303  		azure.WithErrorUnlessStatusCode(http.StatusOK),
  1304  		autorest.ByUnmarshallingJSON(&result),
  1305  		autorest.ByClosing())
  1306  	result.Response = autorest.Response{Response: resp}
  1307  	return
  1308  }
  1309  

View as plain text