...

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

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

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

View as plain text