...

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

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

View as plain text