...

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

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

View as plain text