...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/policy/setdefinitions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-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  // SetDefinitionsClient is the to manage and control access to your resources, you can define customized policies and
    19  // assign them at a scope.
    20  type SetDefinitionsClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewSetDefinitionsClient creates an instance of the SetDefinitionsClient client.
    25  func NewSetDefinitionsClient(subscriptionID string) SetDefinitionsClient {
    26  	return NewSetDefinitionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewSetDefinitionsClientWithBaseURI creates an instance of the SetDefinitionsClient client using a custom endpoint.
    30  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewSetDefinitionsClientWithBaseURI(baseURI string, subscriptionID string) SetDefinitionsClient {
    32  	return SetDefinitionsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate this operation creates or updates a policy set definition in the given subscription with the given
    36  // name.
    37  // Parameters:
    38  // policySetDefinitionName - the name of the policy set definition to create.
    39  // parameters - the policy set definition properties.
    40  func (client SetDefinitionsClient) CreateOrUpdate(ctx context.Context, policySetDefinitionName string, parameters SetDefinition) (result SetDefinition, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.CreateOrUpdate")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: parameters,
    53  			Constraints: []validation.Constraint{{Target: "parameters.SetDefinitionProperties", Name: validation.Null, Rule: false,
    54  				Chain: []validation.Constraint{{Target: "parameters.SetDefinitionProperties.PolicyDefinitions", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    55  		return result, validation.NewError("policy.SetDefinitionsClient", "CreateOrUpdate", err.Error())
    56  	}
    57  
    58  	req, err := client.CreateOrUpdatePreparer(ctx, policySetDefinitionName, parameters)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "CreateOrUpdate", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	resp, err := client.CreateOrUpdateSender(req)
    65  	if err != nil {
    66  		result.Response = autorest.Response{Response: resp}
    67  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "CreateOrUpdate", resp, "Failure sending request")
    68  		return
    69  	}
    70  
    71  	result, err = client.CreateOrUpdateResponder(resp)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "CreateOrUpdate", resp, "Failure responding to request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    81  func (client SetDefinitionsClient) CreateOrUpdatePreparer(ctx context.Context, policySetDefinitionName string, parameters SetDefinition) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
    84  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2018-05-01"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	parameters.ID = nil
    93  	parameters.Name = nil
    94  	parameters.Type = nil
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsContentType("application/json; charset=utf-8"),
    97  		autorest.AsPut(),
    98  		autorest.WithBaseURL(client.BaseURI),
    99  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   100  		autorest.WithJSON(parameters),
   101  		autorest.WithQueryParameters(queryParameters))
   102  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   103  }
   104  
   105  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   106  // http.Response Body if it receives an error.
   107  func (client SetDefinitionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   108  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   109  }
   110  
   111  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   112  // closes the http.Response Body.
   113  func (client SetDefinitionsClient) CreateOrUpdateResponder(resp *http.Response) (result SetDefinition, err error) {
   114  	err = autorest.Respond(
   115  		resp,
   116  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   117  		autorest.ByUnmarshallingJSON(&result),
   118  		autorest.ByClosing())
   119  	result.Response = autorest.Response{Response: resp}
   120  	return
   121  }
   122  
   123  // CreateOrUpdateAtManagementGroup this operation creates or updates a policy set definition in the given management
   124  // group with the given name.
   125  // Parameters:
   126  // policySetDefinitionName - the name of the policy set definition to create.
   127  // parameters - the policy set definition properties.
   128  // managementGroupID - the ID of the management group.
   129  func (client SetDefinitionsClient) CreateOrUpdateAtManagementGroup(ctx context.Context, policySetDefinitionName string, parameters SetDefinition, managementGroupID string) (result SetDefinition, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.CreateOrUpdateAtManagementGroup")
   132  		defer func() {
   133  			sc := -1
   134  			if result.Response.Response != nil {
   135  				sc = result.Response.Response.StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	if err := validation.Validate([]validation.Validation{
   141  		{TargetValue: parameters,
   142  			Constraints: []validation.Constraint{{Target: "parameters.SetDefinitionProperties", Name: validation.Null, Rule: false,
   143  				Chain: []validation.Constraint{{Target: "parameters.SetDefinitionProperties.PolicyDefinitions", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
   144  		return result, validation.NewError("policy.SetDefinitionsClient", "CreateOrUpdateAtManagementGroup", err.Error())
   145  	}
   146  
   147  	req, err := client.CreateOrUpdateAtManagementGroupPreparer(ctx, policySetDefinitionName, parameters, managementGroupID)
   148  	if err != nil {
   149  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "CreateOrUpdateAtManagementGroup", nil, "Failure preparing request")
   150  		return
   151  	}
   152  
   153  	resp, err := client.CreateOrUpdateAtManagementGroupSender(req)
   154  	if err != nil {
   155  		result.Response = autorest.Response{Response: resp}
   156  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "CreateOrUpdateAtManagementGroup", resp, "Failure sending request")
   157  		return
   158  	}
   159  
   160  	result, err = client.CreateOrUpdateAtManagementGroupResponder(resp)
   161  	if err != nil {
   162  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "CreateOrUpdateAtManagementGroup", resp, "Failure responding to request")
   163  		return
   164  	}
   165  
   166  	return
   167  }
   168  
   169  // CreateOrUpdateAtManagementGroupPreparer prepares the CreateOrUpdateAtManagementGroup request.
   170  func (client SetDefinitionsClient) CreateOrUpdateAtManagementGroupPreparer(ctx context.Context, policySetDefinitionName string, parameters SetDefinition, managementGroupID string) (*http.Request, error) {
   171  	pathParameters := map[string]interface{}{
   172  		"managementGroupId":       autorest.Encode("path", managementGroupID),
   173  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
   174  	}
   175  
   176  	const APIVersion = "2018-05-01"
   177  	queryParameters := map[string]interface{}{
   178  		"api-version": APIVersion,
   179  	}
   180  
   181  	parameters.ID = nil
   182  	parameters.Name = nil
   183  	parameters.Type = nil
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsContentType("application/json; charset=utf-8"),
   186  		autorest.AsPut(),
   187  		autorest.WithBaseURL(client.BaseURI),
   188  		autorest.WithPathParameters("/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   189  		autorest.WithJSON(parameters),
   190  		autorest.WithQueryParameters(queryParameters))
   191  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   192  }
   193  
   194  // CreateOrUpdateAtManagementGroupSender sends the CreateOrUpdateAtManagementGroup request. The method will close the
   195  // http.Response Body if it receives an error.
   196  func (client SetDefinitionsClient) CreateOrUpdateAtManagementGroupSender(req *http.Request) (*http.Response, error) {
   197  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   198  }
   199  
   200  // CreateOrUpdateAtManagementGroupResponder handles the response to the CreateOrUpdateAtManagementGroup request. The method always
   201  // closes the http.Response Body.
   202  func (client SetDefinitionsClient) CreateOrUpdateAtManagementGroupResponder(resp *http.Response) (result SetDefinition, err error) {
   203  	err = autorest.Respond(
   204  		resp,
   205  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   206  		autorest.ByUnmarshallingJSON(&result),
   207  		autorest.ByClosing())
   208  	result.Response = autorest.Response{Response: resp}
   209  	return
   210  }
   211  
   212  // Delete this operation deletes the policy set definition in the given subscription with the given name.
   213  // Parameters:
   214  // policySetDefinitionName - the name of the policy set definition to delete.
   215  func (client SetDefinitionsClient) Delete(ctx context.Context, policySetDefinitionName string) (result autorest.Response, err error) {
   216  	if tracing.IsEnabled() {
   217  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.Delete")
   218  		defer func() {
   219  			sc := -1
   220  			if result.Response != nil {
   221  				sc = result.Response.StatusCode
   222  			}
   223  			tracing.EndSpan(ctx, sc, err)
   224  		}()
   225  	}
   226  	req, err := client.DeletePreparer(ctx, policySetDefinitionName)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "Delete", nil, "Failure preparing request")
   229  		return
   230  	}
   231  
   232  	resp, err := client.DeleteSender(req)
   233  	if err != nil {
   234  		result.Response = resp
   235  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "Delete", resp, "Failure sending request")
   236  		return
   237  	}
   238  
   239  	result, err = client.DeleteResponder(resp)
   240  	if err != nil {
   241  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "Delete", resp, "Failure responding to request")
   242  		return
   243  	}
   244  
   245  	return
   246  }
   247  
   248  // DeletePreparer prepares the Delete request.
   249  func (client SetDefinitionsClient) DeletePreparer(ctx context.Context, policySetDefinitionName string) (*http.Request, error) {
   250  	pathParameters := map[string]interface{}{
   251  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
   252  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   253  	}
   254  
   255  	const APIVersion = "2018-05-01"
   256  	queryParameters := map[string]interface{}{
   257  		"api-version": APIVersion,
   258  	}
   259  
   260  	preparer := autorest.CreatePreparer(
   261  		autorest.AsDelete(),
   262  		autorest.WithBaseURL(client.BaseURI),
   263  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   264  		autorest.WithQueryParameters(queryParameters))
   265  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   266  }
   267  
   268  // DeleteSender sends the Delete request. The method will close the
   269  // http.Response Body if it receives an error.
   270  func (client SetDefinitionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   271  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   272  }
   273  
   274  // DeleteResponder handles the response to the Delete request. The method always
   275  // closes the http.Response Body.
   276  func (client SetDefinitionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   277  	err = autorest.Respond(
   278  		resp,
   279  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   280  		autorest.ByClosing())
   281  	result.Response = resp
   282  	return
   283  }
   284  
   285  // DeleteAtManagementGroup this operation deletes the policy set definition in the given management group with the
   286  // given name.
   287  // Parameters:
   288  // policySetDefinitionName - the name of the policy set definition to delete.
   289  // managementGroupID - the ID of the management group.
   290  func (client SetDefinitionsClient) DeleteAtManagementGroup(ctx context.Context, policySetDefinitionName string, managementGroupID string) (result autorest.Response, err error) {
   291  	if tracing.IsEnabled() {
   292  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.DeleteAtManagementGroup")
   293  		defer func() {
   294  			sc := -1
   295  			if result.Response != nil {
   296  				sc = result.Response.StatusCode
   297  			}
   298  			tracing.EndSpan(ctx, sc, err)
   299  		}()
   300  	}
   301  	req, err := client.DeleteAtManagementGroupPreparer(ctx, policySetDefinitionName, managementGroupID)
   302  	if err != nil {
   303  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "DeleteAtManagementGroup", nil, "Failure preparing request")
   304  		return
   305  	}
   306  
   307  	resp, err := client.DeleteAtManagementGroupSender(req)
   308  	if err != nil {
   309  		result.Response = resp
   310  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "DeleteAtManagementGroup", resp, "Failure sending request")
   311  		return
   312  	}
   313  
   314  	result, err = client.DeleteAtManagementGroupResponder(resp)
   315  	if err != nil {
   316  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "DeleteAtManagementGroup", resp, "Failure responding to request")
   317  		return
   318  	}
   319  
   320  	return
   321  }
   322  
   323  // DeleteAtManagementGroupPreparer prepares the DeleteAtManagementGroup request.
   324  func (client SetDefinitionsClient) DeleteAtManagementGroupPreparer(ctx context.Context, policySetDefinitionName string, managementGroupID string) (*http.Request, error) {
   325  	pathParameters := map[string]interface{}{
   326  		"managementGroupId":       autorest.Encode("path", managementGroupID),
   327  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
   328  	}
   329  
   330  	const APIVersion = "2018-05-01"
   331  	queryParameters := map[string]interface{}{
   332  		"api-version": APIVersion,
   333  	}
   334  
   335  	preparer := autorest.CreatePreparer(
   336  		autorest.AsDelete(),
   337  		autorest.WithBaseURL(client.BaseURI),
   338  		autorest.WithPathParameters("/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   339  		autorest.WithQueryParameters(queryParameters))
   340  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   341  }
   342  
   343  // DeleteAtManagementGroupSender sends the DeleteAtManagementGroup request. The method will close the
   344  // http.Response Body if it receives an error.
   345  func (client SetDefinitionsClient) DeleteAtManagementGroupSender(req *http.Request) (*http.Response, error) {
   346  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   347  }
   348  
   349  // DeleteAtManagementGroupResponder handles the response to the DeleteAtManagementGroup request. The method always
   350  // closes the http.Response Body.
   351  func (client SetDefinitionsClient) DeleteAtManagementGroupResponder(resp *http.Response) (result autorest.Response, err error) {
   352  	err = autorest.Respond(
   353  		resp,
   354  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   355  		autorest.ByClosing())
   356  	result.Response = resp
   357  	return
   358  }
   359  
   360  // Get this operation retrieves the policy set definition in the given subscription with the given name.
   361  // Parameters:
   362  // policySetDefinitionName - the name of the policy set definition to get.
   363  func (client SetDefinitionsClient) Get(ctx context.Context, policySetDefinitionName string) (result SetDefinition, err error) {
   364  	if tracing.IsEnabled() {
   365  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.Get")
   366  		defer func() {
   367  			sc := -1
   368  			if result.Response.Response != nil {
   369  				sc = result.Response.Response.StatusCode
   370  			}
   371  			tracing.EndSpan(ctx, sc, err)
   372  		}()
   373  	}
   374  	req, err := client.GetPreparer(ctx, policySetDefinitionName)
   375  	if err != nil {
   376  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "Get", nil, "Failure preparing request")
   377  		return
   378  	}
   379  
   380  	resp, err := client.GetSender(req)
   381  	if err != nil {
   382  		result.Response = autorest.Response{Response: resp}
   383  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "Get", resp, "Failure sending request")
   384  		return
   385  	}
   386  
   387  	result, err = client.GetResponder(resp)
   388  	if err != nil {
   389  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "Get", resp, "Failure responding to request")
   390  		return
   391  	}
   392  
   393  	return
   394  }
   395  
   396  // GetPreparer prepares the Get request.
   397  func (client SetDefinitionsClient) GetPreparer(ctx context.Context, policySetDefinitionName string) (*http.Request, error) {
   398  	pathParameters := map[string]interface{}{
   399  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
   400  		"subscriptionId":          autorest.Encode("path", client.SubscriptionID),
   401  	}
   402  
   403  	const APIVersion = "2018-05-01"
   404  	queryParameters := map[string]interface{}{
   405  		"api-version": APIVersion,
   406  	}
   407  
   408  	preparer := autorest.CreatePreparer(
   409  		autorest.AsGet(),
   410  		autorest.WithBaseURL(client.BaseURI),
   411  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   412  		autorest.WithQueryParameters(queryParameters))
   413  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   414  }
   415  
   416  // GetSender sends the Get request. The method will close the
   417  // http.Response Body if it receives an error.
   418  func (client SetDefinitionsClient) GetSender(req *http.Request) (*http.Response, error) {
   419  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   420  }
   421  
   422  // GetResponder handles the response to the Get request. The method always
   423  // closes the http.Response Body.
   424  func (client SetDefinitionsClient) GetResponder(resp *http.Response) (result SetDefinition, err error) {
   425  	err = autorest.Respond(
   426  		resp,
   427  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   428  		autorest.ByUnmarshallingJSON(&result),
   429  		autorest.ByClosing())
   430  	result.Response = autorest.Response{Response: resp}
   431  	return
   432  }
   433  
   434  // GetAtManagementGroup this operation retrieves the policy set definition in the given management group with the given
   435  // name.
   436  // Parameters:
   437  // policySetDefinitionName - the name of the policy set definition to get.
   438  // managementGroupID - the ID of the management group.
   439  func (client SetDefinitionsClient) GetAtManagementGroup(ctx context.Context, policySetDefinitionName string, managementGroupID string) (result SetDefinition, err error) {
   440  	if tracing.IsEnabled() {
   441  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.GetAtManagementGroup")
   442  		defer func() {
   443  			sc := -1
   444  			if result.Response.Response != nil {
   445  				sc = result.Response.Response.StatusCode
   446  			}
   447  			tracing.EndSpan(ctx, sc, err)
   448  		}()
   449  	}
   450  	req, err := client.GetAtManagementGroupPreparer(ctx, policySetDefinitionName, managementGroupID)
   451  	if err != nil {
   452  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "GetAtManagementGroup", nil, "Failure preparing request")
   453  		return
   454  	}
   455  
   456  	resp, err := client.GetAtManagementGroupSender(req)
   457  	if err != nil {
   458  		result.Response = autorest.Response{Response: resp}
   459  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "GetAtManagementGroup", resp, "Failure sending request")
   460  		return
   461  	}
   462  
   463  	result, err = client.GetAtManagementGroupResponder(resp)
   464  	if err != nil {
   465  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "GetAtManagementGroup", resp, "Failure responding to request")
   466  		return
   467  	}
   468  
   469  	return
   470  }
   471  
   472  // GetAtManagementGroupPreparer prepares the GetAtManagementGroup request.
   473  func (client SetDefinitionsClient) GetAtManagementGroupPreparer(ctx context.Context, policySetDefinitionName string, managementGroupID string) (*http.Request, error) {
   474  	pathParameters := map[string]interface{}{
   475  		"managementGroupId":       autorest.Encode("path", managementGroupID),
   476  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
   477  	}
   478  
   479  	const APIVersion = "2018-05-01"
   480  	queryParameters := map[string]interface{}{
   481  		"api-version": APIVersion,
   482  	}
   483  
   484  	preparer := autorest.CreatePreparer(
   485  		autorest.AsGet(),
   486  		autorest.WithBaseURL(client.BaseURI),
   487  		autorest.WithPathParameters("/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   488  		autorest.WithQueryParameters(queryParameters))
   489  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   490  }
   491  
   492  // GetAtManagementGroupSender sends the GetAtManagementGroup request. The method will close the
   493  // http.Response Body if it receives an error.
   494  func (client SetDefinitionsClient) GetAtManagementGroupSender(req *http.Request) (*http.Response, error) {
   495  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   496  }
   497  
   498  // GetAtManagementGroupResponder handles the response to the GetAtManagementGroup request. The method always
   499  // closes the http.Response Body.
   500  func (client SetDefinitionsClient) GetAtManagementGroupResponder(resp *http.Response) (result SetDefinition, err error) {
   501  	err = autorest.Respond(
   502  		resp,
   503  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   504  		autorest.ByUnmarshallingJSON(&result),
   505  		autorest.ByClosing())
   506  	result.Response = autorest.Response{Response: resp}
   507  	return
   508  }
   509  
   510  // GetBuiltIn this operation retrieves the built-in policy set definition with the given name.
   511  // Parameters:
   512  // policySetDefinitionName - the name of the policy set definition to get.
   513  func (client SetDefinitionsClient) GetBuiltIn(ctx context.Context, policySetDefinitionName string) (result SetDefinition, err error) {
   514  	if tracing.IsEnabled() {
   515  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.GetBuiltIn")
   516  		defer func() {
   517  			sc := -1
   518  			if result.Response.Response != nil {
   519  				sc = result.Response.Response.StatusCode
   520  			}
   521  			tracing.EndSpan(ctx, sc, err)
   522  		}()
   523  	}
   524  	req, err := client.GetBuiltInPreparer(ctx, policySetDefinitionName)
   525  	if err != nil {
   526  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "GetBuiltIn", nil, "Failure preparing request")
   527  		return
   528  	}
   529  
   530  	resp, err := client.GetBuiltInSender(req)
   531  	if err != nil {
   532  		result.Response = autorest.Response{Response: resp}
   533  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "GetBuiltIn", resp, "Failure sending request")
   534  		return
   535  	}
   536  
   537  	result, err = client.GetBuiltInResponder(resp)
   538  	if err != nil {
   539  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "GetBuiltIn", resp, "Failure responding to request")
   540  		return
   541  	}
   542  
   543  	return
   544  }
   545  
   546  // GetBuiltInPreparer prepares the GetBuiltIn request.
   547  func (client SetDefinitionsClient) GetBuiltInPreparer(ctx context.Context, policySetDefinitionName string) (*http.Request, error) {
   548  	pathParameters := map[string]interface{}{
   549  		"policySetDefinitionName": autorest.Encode("path", policySetDefinitionName),
   550  	}
   551  
   552  	const APIVersion = "2018-05-01"
   553  	queryParameters := map[string]interface{}{
   554  		"api-version": APIVersion,
   555  	}
   556  
   557  	preparer := autorest.CreatePreparer(
   558  		autorest.AsGet(),
   559  		autorest.WithBaseURL(client.BaseURI),
   560  		autorest.WithPathParameters("/providers/Microsoft.Authorization/policySetDefinitions/{policySetDefinitionName}", pathParameters),
   561  		autorest.WithQueryParameters(queryParameters))
   562  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   563  }
   564  
   565  // GetBuiltInSender sends the GetBuiltIn request. The method will close the
   566  // http.Response Body if it receives an error.
   567  func (client SetDefinitionsClient) GetBuiltInSender(req *http.Request) (*http.Response, error) {
   568  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   569  }
   570  
   571  // GetBuiltInResponder handles the response to the GetBuiltIn request. The method always
   572  // closes the http.Response Body.
   573  func (client SetDefinitionsClient) GetBuiltInResponder(resp *http.Response) (result SetDefinition, err error) {
   574  	err = autorest.Respond(
   575  		resp,
   576  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   577  		autorest.ByUnmarshallingJSON(&result),
   578  		autorest.ByClosing())
   579  	result.Response = autorest.Response{Response: resp}
   580  	return
   581  }
   582  
   583  // List this operation retrieves a list of all the policy set definitions in the given subscription.
   584  func (client SetDefinitionsClient) List(ctx context.Context) (result SetDefinitionListResultPage, err error) {
   585  	if tracing.IsEnabled() {
   586  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.List")
   587  		defer func() {
   588  			sc := -1
   589  			if result.sdlr.Response.Response != nil {
   590  				sc = result.sdlr.Response.Response.StatusCode
   591  			}
   592  			tracing.EndSpan(ctx, sc, err)
   593  		}()
   594  	}
   595  	result.fn = client.listNextResults
   596  	req, err := client.ListPreparer(ctx)
   597  	if err != nil {
   598  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "List", nil, "Failure preparing request")
   599  		return
   600  	}
   601  
   602  	resp, err := client.ListSender(req)
   603  	if err != nil {
   604  		result.sdlr.Response = autorest.Response{Response: resp}
   605  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "List", resp, "Failure sending request")
   606  		return
   607  	}
   608  
   609  	result.sdlr, err = client.ListResponder(resp)
   610  	if err != nil {
   611  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "List", resp, "Failure responding to request")
   612  		return
   613  	}
   614  	if result.sdlr.hasNextLink() && result.sdlr.IsEmpty() {
   615  		err = result.NextWithContext(ctx)
   616  		return
   617  	}
   618  
   619  	return
   620  }
   621  
   622  // ListPreparer prepares the List request.
   623  func (client SetDefinitionsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   624  	pathParameters := map[string]interface{}{
   625  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   626  	}
   627  
   628  	const APIVersion = "2018-05-01"
   629  	queryParameters := map[string]interface{}{
   630  		"api-version": APIVersion,
   631  	}
   632  
   633  	preparer := autorest.CreatePreparer(
   634  		autorest.AsGet(),
   635  		autorest.WithBaseURL(client.BaseURI),
   636  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policySetDefinitions", pathParameters),
   637  		autorest.WithQueryParameters(queryParameters))
   638  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   639  }
   640  
   641  // ListSender sends the List request. The method will close the
   642  // http.Response Body if it receives an error.
   643  func (client SetDefinitionsClient) ListSender(req *http.Request) (*http.Response, error) {
   644  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   645  }
   646  
   647  // ListResponder handles the response to the List request. The method always
   648  // closes the http.Response Body.
   649  func (client SetDefinitionsClient) ListResponder(resp *http.Response) (result SetDefinitionListResult, err error) {
   650  	err = autorest.Respond(
   651  		resp,
   652  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   653  		autorest.ByUnmarshallingJSON(&result),
   654  		autorest.ByClosing())
   655  	result.Response = autorest.Response{Response: resp}
   656  	return
   657  }
   658  
   659  // listNextResults retrieves the next set of results, if any.
   660  func (client SetDefinitionsClient) listNextResults(ctx context.Context, lastResults SetDefinitionListResult) (result SetDefinitionListResult, err error) {
   661  	req, err := lastResults.setDefinitionListResultPreparer(ctx)
   662  	if err != nil {
   663  		return result, autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listNextResults", nil, "Failure preparing next results request")
   664  	}
   665  	if req == nil {
   666  		return
   667  	}
   668  	resp, err := client.ListSender(req)
   669  	if err != nil {
   670  		result.Response = autorest.Response{Response: resp}
   671  		return result, autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listNextResults", resp, "Failure sending next results request")
   672  	}
   673  	result, err = client.ListResponder(resp)
   674  	if err != nil {
   675  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listNextResults", resp, "Failure responding to next results request")
   676  	}
   677  	return
   678  }
   679  
   680  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   681  func (client SetDefinitionsClient) ListComplete(ctx context.Context) (result SetDefinitionListResultIterator, err error) {
   682  	if tracing.IsEnabled() {
   683  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.List")
   684  		defer func() {
   685  			sc := -1
   686  			if result.Response().Response.Response != nil {
   687  				sc = result.page.Response().Response.Response.StatusCode
   688  			}
   689  			tracing.EndSpan(ctx, sc, err)
   690  		}()
   691  	}
   692  	result.page, err = client.List(ctx)
   693  	return
   694  }
   695  
   696  // ListBuiltIn this operation retrieves a list of all the built-in policy set definitions.
   697  func (client SetDefinitionsClient) ListBuiltIn(ctx context.Context) (result SetDefinitionListResultPage, err error) {
   698  	if tracing.IsEnabled() {
   699  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.ListBuiltIn")
   700  		defer func() {
   701  			sc := -1
   702  			if result.sdlr.Response.Response != nil {
   703  				sc = result.sdlr.Response.Response.StatusCode
   704  			}
   705  			tracing.EndSpan(ctx, sc, err)
   706  		}()
   707  	}
   708  	result.fn = client.listBuiltInNextResults
   709  	req, err := client.ListBuiltInPreparer(ctx)
   710  	if err != nil {
   711  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "ListBuiltIn", nil, "Failure preparing request")
   712  		return
   713  	}
   714  
   715  	resp, err := client.ListBuiltInSender(req)
   716  	if err != nil {
   717  		result.sdlr.Response = autorest.Response{Response: resp}
   718  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "ListBuiltIn", resp, "Failure sending request")
   719  		return
   720  	}
   721  
   722  	result.sdlr, err = client.ListBuiltInResponder(resp)
   723  	if err != nil {
   724  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "ListBuiltIn", resp, "Failure responding to request")
   725  		return
   726  	}
   727  	if result.sdlr.hasNextLink() && result.sdlr.IsEmpty() {
   728  		err = result.NextWithContext(ctx)
   729  		return
   730  	}
   731  
   732  	return
   733  }
   734  
   735  // ListBuiltInPreparer prepares the ListBuiltIn request.
   736  func (client SetDefinitionsClient) ListBuiltInPreparer(ctx context.Context) (*http.Request, error) {
   737  	const APIVersion = "2018-05-01"
   738  	queryParameters := map[string]interface{}{
   739  		"api-version": APIVersion,
   740  	}
   741  
   742  	preparer := autorest.CreatePreparer(
   743  		autorest.AsGet(),
   744  		autorest.WithBaseURL(client.BaseURI),
   745  		autorest.WithPath("/providers/Microsoft.Authorization/policySetDefinitions"),
   746  		autorest.WithQueryParameters(queryParameters))
   747  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   748  }
   749  
   750  // ListBuiltInSender sends the ListBuiltIn request. The method will close the
   751  // http.Response Body if it receives an error.
   752  func (client SetDefinitionsClient) ListBuiltInSender(req *http.Request) (*http.Response, error) {
   753  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   754  }
   755  
   756  // ListBuiltInResponder handles the response to the ListBuiltIn request. The method always
   757  // closes the http.Response Body.
   758  func (client SetDefinitionsClient) ListBuiltInResponder(resp *http.Response) (result SetDefinitionListResult, err error) {
   759  	err = autorest.Respond(
   760  		resp,
   761  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   762  		autorest.ByUnmarshallingJSON(&result),
   763  		autorest.ByClosing())
   764  	result.Response = autorest.Response{Response: resp}
   765  	return
   766  }
   767  
   768  // listBuiltInNextResults retrieves the next set of results, if any.
   769  func (client SetDefinitionsClient) listBuiltInNextResults(ctx context.Context, lastResults SetDefinitionListResult) (result SetDefinitionListResult, err error) {
   770  	req, err := lastResults.setDefinitionListResultPreparer(ctx)
   771  	if err != nil {
   772  		return result, autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listBuiltInNextResults", nil, "Failure preparing next results request")
   773  	}
   774  	if req == nil {
   775  		return
   776  	}
   777  	resp, err := client.ListBuiltInSender(req)
   778  	if err != nil {
   779  		result.Response = autorest.Response{Response: resp}
   780  		return result, autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listBuiltInNextResults", resp, "Failure sending next results request")
   781  	}
   782  	result, err = client.ListBuiltInResponder(resp)
   783  	if err != nil {
   784  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listBuiltInNextResults", resp, "Failure responding to next results request")
   785  	}
   786  	return
   787  }
   788  
   789  // ListBuiltInComplete enumerates all values, automatically crossing page boundaries as required.
   790  func (client SetDefinitionsClient) ListBuiltInComplete(ctx context.Context) (result SetDefinitionListResultIterator, err error) {
   791  	if tracing.IsEnabled() {
   792  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.ListBuiltIn")
   793  		defer func() {
   794  			sc := -1
   795  			if result.Response().Response.Response != nil {
   796  				sc = result.page.Response().Response.Response.StatusCode
   797  			}
   798  			tracing.EndSpan(ctx, sc, err)
   799  		}()
   800  	}
   801  	result.page, err = client.ListBuiltIn(ctx)
   802  	return
   803  }
   804  
   805  // ListByManagementGroup this operation retrieves a list of all the a policy set definition in the given management
   806  // group.
   807  // Parameters:
   808  // managementGroupID - the ID of the management group.
   809  func (client SetDefinitionsClient) ListByManagementGroup(ctx context.Context, managementGroupID string) (result SetDefinitionListResultPage, err error) {
   810  	if tracing.IsEnabled() {
   811  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.ListByManagementGroup")
   812  		defer func() {
   813  			sc := -1
   814  			if result.sdlr.Response.Response != nil {
   815  				sc = result.sdlr.Response.Response.StatusCode
   816  			}
   817  			tracing.EndSpan(ctx, sc, err)
   818  		}()
   819  	}
   820  	result.fn = client.listByManagementGroupNextResults
   821  	req, err := client.ListByManagementGroupPreparer(ctx, managementGroupID)
   822  	if err != nil {
   823  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "ListByManagementGroup", nil, "Failure preparing request")
   824  		return
   825  	}
   826  
   827  	resp, err := client.ListByManagementGroupSender(req)
   828  	if err != nil {
   829  		result.sdlr.Response = autorest.Response{Response: resp}
   830  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "ListByManagementGroup", resp, "Failure sending request")
   831  		return
   832  	}
   833  
   834  	result.sdlr, err = client.ListByManagementGroupResponder(resp)
   835  	if err != nil {
   836  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "ListByManagementGroup", resp, "Failure responding to request")
   837  		return
   838  	}
   839  	if result.sdlr.hasNextLink() && result.sdlr.IsEmpty() {
   840  		err = result.NextWithContext(ctx)
   841  		return
   842  	}
   843  
   844  	return
   845  }
   846  
   847  // ListByManagementGroupPreparer prepares the ListByManagementGroup request.
   848  func (client SetDefinitionsClient) ListByManagementGroupPreparer(ctx context.Context, managementGroupID string) (*http.Request, error) {
   849  	pathParameters := map[string]interface{}{
   850  		"managementGroupId": autorest.Encode("path", managementGroupID),
   851  	}
   852  
   853  	const APIVersion = "2018-05-01"
   854  	queryParameters := map[string]interface{}{
   855  		"api-version": APIVersion,
   856  	}
   857  
   858  	preparer := autorest.CreatePreparer(
   859  		autorest.AsGet(),
   860  		autorest.WithBaseURL(client.BaseURI),
   861  		autorest.WithPathParameters("/providers/Microsoft.Management/managementgroups/{managementGroupId}/providers/Microsoft.Authorization/policySetDefinitions", pathParameters),
   862  		autorest.WithQueryParameters(queryParameters))
   863  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   864  }
   865  
   866  // ListByManagementGroupSender sends the ListByManagementGroup request. The method will close the
   867  // http.Response Body if it receives an error.
   868  func (client SetDefinitionsClient) ListByManagementGroupSender(req *http.Request) (*http.Response, error) {
   869  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   870  }
   871  
   872  // ListByManagementGroupResponder handles the response to the ListByManagementGroup request. The method always
   873  // closes the http.Response Body.
   874  func (client SetDefinitionsClient) ListByManagementGroupResponder(resp *http.Response) (result SetDefinitionListResult, err error) {
   875  	err = autorest.Respond(
   876  		resp,
   877  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   878  		autorest.ByUnmarshallingJSON(&result),
   879  		autorest.ByClosing())
   880  	result.Response = autorest.Response{Response: resp}
   881  	return
   882  }
   883  
   884  // listByManagementGroupNextResults retrieves the next set of results, if any.
   885  func (client SetDefinitionsClient) listByManagementGroupNextResults(ctx context.Context, lastResults SetDefinitionListResult) (result SetDefinitionListResult, err error) {
   886  	req, err := lastResults.setDefinitionListResultPreparer(ctx)
   887  	if err != nil {
   888  		return result, autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listByManagementGroupNextResults", nil, "Failure preparing next results request")
   889  	}
   890  	if req == nil {
   891  		return
   892  	}
   893  	resp, err := client.ListByManagementGroupSender(req)
   894  	if err != nil {
   895  		result.Response = autorest.Response{Response: resp}
   896  		return result, autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listByManagementGroupNextResults", resp, "Failure sending next results request")
   897  	}
   898  	result, err = client.ListByManagementGroupResponder(resp)
   899  	if err != nil {
   900  		err = autorest.NewErrorWithError(err, "policy.SetDefinitionsClient", "listByManagementGroupNextResults", resp, "Failure responding to next results request")
   901  	}
   902  	return
   903  }
   904  
   905  // ListByManagementGroupComplete enumerates all values, automatically crossing page boundaries as required.
   906  func (client SetDefinitionsClient) ListByManagementGroupComplete(ctx context.Context, managementGroupID string) (result SetDefinitionListResultIterator, err error) {
   907  	if tracing.IsEnabled() {
   908  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionsClient.ListByManagementGroup")
   909  		defer func() {
   910  			sc := -1
   911  			if result.Response().Response.Response != nil {
   912  				sc = result.page.Response().Response.Response.StatusCode
   913  			}
   914  			tracing.EndSpan(ctx, sc, err)
   915  		}()
   916  	}
   917  	result.page, err = client.ListByManagementGroup(ctx, managementGroupID)
   918  	return
   919  }
   920  

View as plain text