...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2021-06-01-preview/policy/variablevalues.go

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

     1  package policy
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // VariableValuesClient is the client for the VariableValues methods of the Policy service.
    19  type VariableValuesClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewVariableValuesClient creates an instance of the VariableValuesClient client.
    24  func NewVariableValuesClient(subscriptionID string) VariableValuesClient {
    25  	return NewVariableValuesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewVariableValuesClientWithBaseURI creates an instance of the VariableValuesClient client using a custom endpoint.
    29  // Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewVariableValuesClientWithBaseURI(baseURI string, subscriptionID string) VariableValuesClient {
    31  	return VariableValuesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate this operation creates or updates a variable value with the given subscription and name for a given
    35  // variable. Variable values are scoped to the variable for which they are created for.
    36  // Parameters:
    37  // variableName - the name of the variable to operate on.
    38  // variableValueName - the name of the variable value to operate on.
    39  // parameters - parameters for the variable value.
    40  func (client VariableValuesClient) CreateOrUpdate(ctx context.Context, variableName string, variableValueName string, parameters VariableValue) (result VariableValue, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.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.VariableValueProperties", Name: validation.Null, Rule: true,
    54  				Chain: []validation.Constraint{{Target: "parameters.VariableValueProperties.Values", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
    55  		return result, validation.NewError("policy.VariableValuesClient", "CreateOrUpdate", err.Error())
    56  	}
    57  
    58  	req, err := client.CreateOrUpdatePreparer(ctx, variableName, variableValueName, parameters)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "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.VariableValuesClient", "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.VariableValuesClient", "CreateOrUpdate", resp, "Failure responding to request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    81  func (client VariableValuesClient) CreateOrUpdatePreparer(ctx context.Context, variableName string, variableValueName string, parameters VariableValue) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    84  		"variableName":      autorest.Encode("path", variableName),
    85  		"variableValueName": autorest.Encode("path", variableValueName),
    86  	}
    87  
    88  	const APIVersion = "2022-08-01-preview"
    89  	queryParameters := map[string]interface{}{
    90  		"api-version": APIVersion,
    91  	}
    92  
    93  	parameters.SystemData = nil
    94  	parameters.ID = nil
    95  	parameters.Name = nil
    96  	parameters.Type = nil
    97  	preparer := autorest.CreatePreparer(
    98  		autorest.AsContentType("application/json; charset=utf-8"),
    99  		autorest.AsPut(),
   100  		autorest.WithBaseURL(client.BaseURI),
   101  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", pathParameters),
   102  		autorest.WithJSON(parameters),
   103  		autorest.WithQueryParameters(queryParameters))
   104  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   105  }
   106  
   107  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   108  // http.Response Body if it receives an error.
   109  func (client VariableValuesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   110  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   111  }
   112  
   113  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   114  // closes the http.Response Body.
   115  func (client VariableValuesClient) CreateOrUpdateResponder(resp *http.Response) (result VariableValue, err error) {
   116  	err = autorest.Respond(
   117  		resp,
   118  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   119  		autorest.ByUnmarshallingJSON(&result),
   120  		autorest.ByClosing())
   121  	result.Response = autorest.Response{Response: resp}
   122  	return
   123  }
   124  
   125  // CreateOrUpdateAtManagementGroup this operation creates or updates a variable value with the given management group
   126  // and name for a given variable. Variable values are scoped to the variable for which they are created for.
   127  // Parameters:
   128  // managementGroupID - the ID of the management group.
   129  // variableName - the name of the variable to operate on.
   130  // variableValueName - the name of the variable value to operate on.
   131  // parameters - parameters for the variable value.
   132  func (client VariableValuesClient) CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, parameters VariableValue) (result VariableValue, err error) {
   133  	if tracing.IsEnabled() {
   134  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.CreateOrUpdateAtManagementGroup")
   135  		defer func() {
   136  			sc := -1
   137  			if result.Response.Response != nil {
   138  				sc = result.Response.Response.StatusCode
   139  			}
   140  			tracing.EndSpan(ctx, sc, err)
   141  		}()
   142  	}
   143  	if err := validation.Validate([]validation.Validation{
   144  		{TargetValue: parameters,
   145  			Constraints: []validation.Constraint{{Target: "parameters.VariableValueProperties", Name: validation.Null, Rule: true,
   146  				Chain: []validation.Constraint{{Target: "parameters.VariableValueProperties.Values", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
   147  		return result, validation.NewError("policy.VariableValuesClient", "CreateOrUpdateAtManagementGroup", err.Error())
   148  	}
   149  
   150  	req, err := client.CreateOrUpdateAtManagementGroupPreparer(ctx, managementGroupID, variableName, variableValueName, parameters)
   151  	if err != nil {
   152  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "CreateOrUpdateAtManagementGroup", nil, "Failure preparing request")
   153  		return
   154  	}
   155  
   156  	resp, err := client.CreateOrUpdateAtManagementGroupSender(req)
   157  	if err != nil {
   158  		result.Response = autorest.Response{Response: resp}
   159  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "CreateOrUpdateAtManagementGroup", resp, "Failure sending request")
   160  		return
   161  	}
   162  
   163  	result, err = client.CreateOrUpdateAtManagementGroupResponder(resp)
   164  	if err != nil {
   165  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "CreateOrUpdateAtManagementGroup", resp, "Failure responding to request")
   166  		return
   167  	}
   168  
   169  	return
   170  }
   171  
   172  // CreateOrUpdateAtManagementGroupPreparer prepares the CreateOrUpdateAtManagementGroup request.
   173  func (client VariableValuesClient) CreateOrUpdateAtManagementGroupPreparer(ctx context.Context, managementGroupID string, variableName string, variableValueName string, parameters VariableValue) (*http.Request, error) {
   174  	pathParameters := map[string]interface{}{
   175  		"managementGroupId": autorest.Encode("path", managementGroupID),
   176  		"variableName":      autorest.Encode("path", variableName),
   177  		"variableValueName": autorest.Encode("path", variableValueName),
   178  	}
   179  
   180  	const APIVersion = "2022-08-01-preview"
   181  	queryParameters := map[string]interface{}{
   182  		"api-version": APIVersion,
   183  	}
   184  
   185  	parameters.SystemData = nil
   186  	parameters.ID = nil
   187  	parameters.Name = nil
   188  	parameters.Type = nil
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsContentType("application/json; charset=utf-8"),
   191  		autorest.AsPut(),
   192  		autorest.WithBaseURL(client.BaseURI),
   193  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", pathParameters),
   194  		autorest.WithJSON(parameters),
   195  		autorest.WithQueryParameters(queryParameters))
   196  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   197  }
   198  
   199  // CreateOrUpdateAtManagementGroupSender sends the CreateOrUpdateAtManagementGroup request. The method will close the
   200  // http.Response Body if it receives an error.
   201  func (client VariableValuesClient) CreateOrUpdateAtManagementGroupSender(req *http.Request) (*http.Response, error) {
   202  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   203  }
   204  
   205  // CreateOrUpdateAtManagementGroupResponder handles the response to the CreateOrUpdateAtManagementGroup request. The method always
   206  // closes the http.Response Body.
   207  func (client VariableValuesClient) CreateOrUpdateAtManagementGroupResponder(resp *http.Response) (result VariableValue, err error) {
   208  	err = autorest.Respond(
   209  		resp,
   210  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   211  		autorest.ByUnmarshallingJSON(&result),
   212  		autorest.ByClosing())
   213  	result.Response = autorest.Response{Response: resp}
   214  	return
   215  }
   216  
   217  // Delete this operation deletes a variable value, given its name, the subscription it was created in, and the variable
   218  // it belongs to. The scope of a variable value is the part of its ID preceding
   219  // '/providers/Microsoft.Authorization/variables/{variableName}'.
   220  // Parameters:
   221  // variableName - the name of the variable to operate on.
   222  // variableValueName - the name of the variable value to operate on.
   223  func (client VariableValuesClient) Delete(ctx context.Context, variableName string, variableValueName string) (result autorest.Response, err error) {
   224  	if tracing.IsEnabled() {
   225  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.Delete")
   226  		defer func() {
   227  			sc := -1
   228  			if result.Response != nil {
   229  				sc = result.Response.StatusCode
   230  			}
   231  			tracing.EndSpan(ctx, sc, err)
   232  		}()
   233  	}
   234  	req, err := client.DeletePreparer(ctx, variableName, variableValueName)
   235  	if err != nil {
   236  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "Delete", nil, "Failure preparing request")
   237  		return
   238  	}
   239  
   240  	resp, err := client.DeleteSender(req)
   241  	if err != nil {
   242  		result.Response = resp
   243  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "Delete", resp, "Failure sending request")
   244  		return
   245  	}
   246  
   247  	result, err = client.DeleteResponder(resp)
   248  	if err != nil {
   249  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "Delete", resp, "Failure responding to request")
   250  		return
   251  	}
   252  
   253  	return
   254  }
   255  
   256  // DeletePreparer prepares the Delete request.
   257  func (client VariableValuesClient) DeletePreparer(ctx context.Context, variableName string, variableValueName string) (*http.Request, error) {
   258  	pathParameters := map[string]interface{}{
   259  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   260  		"variableName":      autorest.Encode("path", variableName),
   261  		"variableValueName": autorest.Encode("path", variableValueName),
   262  	}
   263  
   264  	const APIVersion = "2022-08-01-preview"
   265  	queryParameters := map[string]interface{}{
   266  		"api-version": APIVersion,
   267  	}
   268  
   269  	preparer := autorest.CreatePreparer(
   270  		autorest.AsDelete(),
   271  		autorest.WithBaseURL(client.BaseURI),
   272  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", pathParameters),
   273  		autorest.WithQueryParameters(queryParameters))
   274  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   275  }
   276  
   277  // DeleteSender sends the Delete request. The method will close the
   278  // http.Response Body if it receives an error.
   279  func (client VariableValuesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   280  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   281  }
   282  
   283  // DeleteResponder handles the response to the Delete request. The method always
   284  // closes the http.Response Body.
   285  func (client VariableValuesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   286  	err = autorest.Respond(
   287  		resp,
   288  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   289  		autorest.ByClosing())
   290  	result.Response = resp
   291  	return
   292  }
   293  
   294  // DeleteAtManagementGroup this operation deletes a variable value, given its name, the management group it was created
   295  // in, and the variable it belongs to. The scope of a variable value is the part of its ID preceding
   296  // '/providers/Microsoft.Authorization/variables/{variableName}'.
   297  // Parameters:
   298  // managementGroupID - the ID of the management group.
   299  // variableName - the name of the variable to operate on.
   300  // variableValueName - the name of the variable value to operate on.
   301  func (client VariableValuesClient) DeleteAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string) (result autorest.Response, err error) {
   302  	if tracing.IsEnabled() {
   303  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.DeleteAtManagementGroup")
   304  		defer func() {
   305  			sc := -1
   306  			if result.Response != nil {
   307  				sc = result.Response.StatusCode
   308  			}
   309  			tracing.EndSpan(ctx, sc, err)
   310  		}()
   311  	}
   312  	req, err := client.DeleteAtManagementGroupPreparer(ctx, managementGroupID, variableName, variableValueName)
   313  	if err != nil {
   314  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "DeleteAtManagementGroup", nil, "Failure preparing request")
   315  		return
   316  	}
   317  
   318  	resp, err := client.DeleteAtManagementGroupSender(req)
   319  	if err != nil {
   320  		result.Response = resp
   321  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "DeleteAtManagementGroup", resp, "Failure sending request")
   322  		return
   323  	}
   324  
   325  	result, err = client.DeleteAtManagementGroupResponder(resp)
   326  	if err != nil {
   327  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "DeleteAtManagementGroup", resp, "Failure responding to request")
   328  		return
   329  	}
   330  
   331  	return
   332  }
   333  
   334  // DeleteAtManagementGroupPreparer prepares the DeleteAtManagementGroup request.
   335  func (client VariableValuesClient) DeleteAtManagementGroupPreparer(ctx context.Context, managementGroupID string, variableName string, variableValueName string) (*http.Request, error) {
   336  	pathParameters := map[string]interface{}{
   337  		"managementGroupId": autorest.Encode("path", managementGroupID),
   338  		"variableName":      autorest.Encode("path", variableName),
   339  		"variableValueName": autorest.Encode("path", variableValueName),
   340  	}
   341  
   342  	const APIVersion = "2022-08-01-preview"
   343  	queryParameters := map[string]interface{}{
   344  		"api-version": APIVersion,
   345  	}
   346  
   347  	preparer := autorest.CreatePreparer(
   348  		autorest.AsDelete(),
   349  		autorest.WithBaseURL(client.BaseURI),
   350  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", pathParameters),
   351  		autorest.WithQueryParameters(queryParameters))
   352  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   353  }
   354  
   355  // DeleteAtManagementGroupSender sends the DeleteAtManagementGroup request. The method will close the
   356  // http.Response Body if it receives an error.
   357  func (client VariableValuesClient) DeleteAtManagementGroupSender(req *http.Request) (*http.Response, error) {
   358  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   359  }
   360  
   361  // DeleteAtManagementGroupResponder handles the response to the DeleteAtManagementGroup request. The method always
   362  // closes the http.Response Body.
   363  func (client VariableValuesClient) DeleteAtManagementGroupResponder(resp *http.Response) (result autorest.Response, err error) {
   364  	err = autorest.Respond(
   365  		resp,
   366  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   367  		autorest.ByClosing())
   368  	result.Response = resp
   369  	return
   370  }
   371  
   372  // Get this operation retrieves a single variable value; given its name, subscription it was created at and the
   373  // variable it's created for.
   374  // Parameters:
   375  // variableName - the name of the variable to operate on.
   376  // variableValueName - the name of the variable value to operate on.
   377  func (client VariableValuesClient) Get(ctx context.Context, variableName string, variableValueName string) (result VariableValue, err error) {
   378  	if tracing.IsEnabled() {
   379  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.Get")
   380  		defer func() {
   381  			sc := -1
   382  			if result.Response.Response != nil {
   383  				sc = result.Response.Response.StatusCode
   384  			}
   385  			tracing.EndSpan(ctx, sc, err)
   386  		}()
   387  	}
   388  	req, err := client.GetPreparer(ctx, variableName, variableValueName)
   389  	if err != nil {
   390  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "Get", nil, "Failure preparing request")
   391  		return
   392  	}
   393  
   394  	resp, err := client.GetSender(req)
   395  	if err != nil {
   396  		result.Response = autorest.Response{Response: resp}
   397  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "Get", resp, "Failure sending request")
   398  		return
   399  	}
   400  
   401  	result, err = client.GetResponder(resp)
   402  	if err != nil {
   403  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "Get", resp, "Failure responding to request")
   404  		return
   405  	}
   406  
   407  	return
   408  }
   409  
   410  // GetPreparer prepares the Get request.
   411  func (client VariableValuesClient) GetPreparer(ctx context.Context, variableName string, variableValueName string) (*http.Request, error) {
   412  	pathParameters := map[string]interface{}{
   413  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   414  		"variableName":      autorest.Encode("path", variableName),
   415  		"variableValueName": autorest.Encode("path", variableValueName),
   416  	}
   417  
   418  	const APIVersion = "2022-08-01-preview"
   419  	queryParameters := map[string]interface{}{
   420  		"api-version": APIVersion,
   421  	}
   422  
   423  	preparer := autorest.CreatePreparer(
   424  		autorest.AsGet(),
   425  		autorest.WithBaseURL(client.BaseURI),
   426  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", pathParameters),
   427  		autorest.WithQueryParameters(queryParameters))
   428  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   429  }
   430  
   431  // GetSender sends the Get request. The method will close the
   432  // http.Response Body if it receives an error.
   433  func (client VariableValuesClient) GetSender(req *http.Request) (*http.Response, error) {
   434  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   435  }
   436  
   437  // GetResponder handles the response to the Get request. The method always
   438  // closes the http.Response Body.
   439  func (client VariableValuesClient) GetResponder(resp *http.Response) (result VariableValue, err error) {
   440  	err = autorest.Respond(
   441  		resp,
   442  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   443  		autorest.ByUnmarshallingJSON(&result),
   444  		autorest.ByClosing())
   445  	result.Response = autorest.Response{Response: resp}
   446  	return
   447  }
   448  
   449  // GetAtManagementGroup this operation retrieves a single variable value; given its name,  management group it was
   450  // created at and the variable it's created for.
   451  // Parameters:
   452  // managementGroupID - the ID of the management group.
   453  // variableName - the name of the variable to operate on.
   454  // variableValueName - the name of the variable value to operate on.
   455  func (client VariableValuesClient) GetAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string) (result VariableValue, err error) {
   456  	if tracing.IsEnabled() {
   457  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.GetAtManagementGroup")
   458  		defer func() {
   459  			sc := -1
   460  			if result.Response.Response != nil {
   461  				sc = result.Response.Response.StatusCode
   462  			}
   463  			tracing.EndSpan(ctx, sc, err)
   464  		}()
   465  	}
   466  	req, err := client.GetAtManagementGroupPreparer(ctx, managementGroupID, variableName, variableValueName)
   467  	if err != nil {
   468  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "GetAtManagementGroup", nil, "Failure preparing request")
   469  		return
   470  	}
   471  
   472  	resp, err := client.GetAtManagementGroupSender(req)
   473  	if err != nil {
   474  		result.Response = autorest.Response{Response: resp}
   475  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "GetAtManagementGroup", resp, "Failure sending request")
   476  		return
   477  	}
   478  
   479  	result, err = client.GetAtManagementGroupResponder(resp)
   480  	if err != nil {
   481  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "GetAtManagementGroup", resp, "Failure responding to request")
   482  		return
   483  	}
   484  
   485  	return
   486  }
   487  
   488  // GetAtManagementGroupPreparer prepares the GetAtManagementGroup request.
   489  func (client VariableValuesClient) GetAtManagementGroupPreparer(ctx context.Context, managementGroupID string, variableName string, variableValueName string) (*http.Request, error) {
   490  	pathParameters := map[string]interface{}{
   491  		"managementGroupId": autorest.Encode("path", managementGroupID),
   492  		"variableName":      autorest.Encode("path", variableName),
   493  		"variableValueName": autorest.Encode("path", variableValueName),
   494  	}
   495  
   496  	const APIVersion = "2022-08-01-preview"
   497  	queryParameters := map[string]interface{}{
   498  		"api-version": APIVersion,
   499  	}
   500  
   501  	preparer := autorest.CreatePreparer(
   502  		autorest.AsGet(),
   503  		autorest.WithBaseURL(client.BaseURI),
   504  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}", pathParameters),
   505  		autorest.WithQueryParameters(queryParameters))
   506  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   507  }
   508  
   509  // GetAtManagementGroupSender sends the GetAtManagementGroup request. The method will close the
   510  // http.Response Body if it receives an error.
   511  func (client VariableValuesClient) GetAtManagementGroupSender(req *http.Request) (*http.Response, error) {
   512  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   513  }
   514  
   515  // GetAtManagementGroupResponder handles the response to the GetAtManagementGroup request. The method always
   516  // closes the http.Response Body.
   517  func (client VariableValuesClient) GetAtManagementGroupResponder(resp *http.Response) (result VariableValue, err error) {
   518  	err = autorest.Respond(
   519  		resp,
   520  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   521  		autorest.ByUnmarshallingJSON(&result),
   522  		autorest.ByClosing())
   523  	result.Response = autorest.Response{Response: resp}
   524  	return
   525  }
   526  
   527  // List this operation retrieves the list of all variable values associated with the given variable that is at a
   528  // subscription level.
   529  // Parameters:
   530  // variableName - the name of the variable to operate on.
   531  func (client VariableValuesClient) List(ctx context.Context, variableName string) (result VariableValueListResultPage, err error) {
   532  	if tracing.IsEnabled() {
   533  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.List")
   534  		defer func() {
   535  			sc := -1
   536  			if result.vvlr.Response.Response != nil {
   537  				sc = result.vvlr.Response.Response.StatusCode
   538  			}
   539  			tracing.EndSpan(ctx, sc, err)
   540  		}()
   541  	}
   542  	result.fn = client.listNextResults
   543  	req, err := client.ListPreparer(ctx, variableName)
   544  	if err != nil {
   545  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "List", nil, "Failure preparing request")
   546  		return
   547  	}
   548  
   549  	resp, err := client.ListSender(req)
   550  	if err != nil {
   551  		result.vvlr.Response = autorest.Response{Response: resp}
   552  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "List", resp, "Failure sending request")
   553  		return
   554  	}
   555  
   556  	result.vvlr, err = client.ListResponder(resp)
   557  	if err != nil {
   558  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "List", resp, "Failure responding to request")
   559  		return
   560  	}
   561  	if result.vvlr.hasNextLink() && result.vvlr.IsEmpty() {
   562  		err = result.NextWithContext(ctx)
   563  		return
   564  	}
   565  
   566  	return
   567  }
   568  
   569  // ListPreparer prepares the List request.
   570  func (client VariableValuesClient) ListPreparer(ctx context.Context, variableName string) (*http.Request, error) {
   571  	pathParameters := map[string]interface{}{
   572  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   573  		"variableName":   autorest.Encode("path", variableName),
   574  	}
   575  
   576  	const APIVersion = "2022-08-01-preview"
   577  	queryParameters := map[string]interface{}{
   578  		"api-version": APIVersion,
   579  	}
   580  
   581  	preparer := autorest.CreatePreparer(
   582  		autorest.AsGet(),
   583  		autorest.WithBaseURL(client.BaseURI),
   584  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values", pathParameters),
   585  		autorest.WithQueryParameters(queryParameters))
   586  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   587  }
   588  
   589  // ListSender sends the List request. The method will close the
   590  // http.Response Body if it receives an error.
   591  func (client VariableValuesClient) ListSender(req *http.Request) (*http.Response, error) {
   592  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   593  }
   594  
   595  // ListResponder handles the response to the List request. The method always
   596  // closes the http.Response Body.
   597  func (client VariableValuesClient) ListResponder(resp *http.Response) (result VariableValueListResult, err error) {
   598  	err = autorest.Respond(
   599  		resp,
   600  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   601  		autorest.ByUnmarshallingJSON(&result),
   602  		autorest.ByClosing())
   603  	result.Response = autorest.Response{Response: resp}
   604  	return
   605  }
   606  
   607  // listNextResults retrieves the next set of results, if any.
   608  func (client VariableValuesClient) listNextResults(ctx context.Context, lastResults VariableValueListResult) (result VariableValueListResult, err error) {
   609  	req, err := lastResults.variableValueListResultPreparer(ctx)
   610  	if err != nil {
   611  		return result, autorest.NewErrorWithError(err, "policy.VariableValuesClient", "listNextResults", nil, "Failure preparing next results request")
   612  	}
   613  	if req == nil {
   614  		return
   615  	}
   616  	resp, err := client.ListSender(req)
   617  	if err != nil {
   618  		result.Response = autorest.Response{Response: resp}
   619  		return result, autorest.NewErrorWithError(err, "policy.VariableValuesClient", "listNextResults", resp, "Failure sending next results request")
   620  	}
   621  	result, err = client.ListResponder(resp)
   622  	if err != nil {
   623  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "listNextResults", resp, "Failure responding to next results request")
   624  	}
   625  	return
   626  }
   627  
   628  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   629  func (client VariableValuesClient) ListComplete(ctx context.Context, variableName string) (result VariableValueListResultIterator, err error) {
   630  	if tracing.IsEnabled() {
   631  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.List")
   632  		defer func() {
   633  			sc := -1
   634  			if result.Response().Response.Response != nil {
   635  				sc = result.page.Response().Response.Response.StatusCode
   636  			}
   637  			tracing.EndSpan(ctx, sc, err)
   638  		}()
   639  	}
   640  	result.page, err = client.List(ctx, variableName)
   641  	return
   642  }
   643  
   644  // ListForManagementGroup this operation retrieves the list of all variable values applicable the variable indicated at
   645  // the management group scope.
   646  // Parameters:
   647  // managementGroupID - the ID of the management group.
   648  // variableName - the name of the variable to operate on.
   649  func (client VariableValuesClient) ListForManagementGroup(ctx context.Context, managementGroupID string, variableName string) (result VariableValueListResultPage, err error) {
   650  	if tracing.IsEnabled() {
   651  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.ListForManagementGroup")
   652  		defer func() {
   653  			sc := -1
   654  			if result.vvlr.Response.Response != nil {
   655  				sc = result.vvlr.Response.Response.StatusCode
   656  			}
   657  			tracing.EndSpan(ctx, sc, err)
   658  		}()
   659  	}
   660  	result.fn = client.listForManagementGroupNextResults
   661  	req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, variableName)
   662  	if err != nil {
   663  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "ListForManagementGroup", nil, "Failure preparing request")
   664  		return
   665  	}
   666  
   667  	resp, err := client.ListForManagementGroupSender(req)
   668  	if err != nil {
   669  		result.vvlr.Response = autorest.Response{Response: resp}
   670  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "ListForManagementGroup", resp, "Failure sending request")
   671  		return
   672  	}
   673  
   674  	result.vvlr, err = client.ListForManagementGroupResponder(resp)
   675  	if err != nil {
   676  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "ListForManagementGroup", resp, "Failure responding to request")
   677  		return
   678  	}
   679  	if result.vvlr.hasNextLink() && result.vvlr.IsEmpty() {
   680  		err = result.NextWithContext(ctx)
   681  		return
   682  	}
   683  
   684  	return
   685  }
   686  
   687  // ListForManagementGroupPreparer prepares the ListForManagementGroup request.
   688  func (client VariableValuesClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, variableName string) (*http.Request, error) {
   689  	pathParameters := map[string]interface{}{
   690  		"managementGroupId": autorest.Encode("path", managementGroupID),
   691  		"variableName":      autorest.Encode("path", variableName),
   692  	}
   693  
   694  	const APIVersion = "2022-08-01-preview"
   695  	queryParameters := map[string]interface{}{
   696  		"api-version": APIVersion,
   697  	}
   698  
   699  	preparer := autorest.CreatePreparer(
   700  		autorest.AsGet(),
   701  		autorest.WithBaseURL(client.BaseURI),
   702  		autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values", pathParameters),
   703  		autorest.WithQueryParameters(queryParameters))
   704  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   705  }
   706  
   707  // ListForManagementGroupSender sends the ListForManagementGroup request. The method will close the
   708  // http.Response Body if it receives an error.
   709  func (client VariableValuesClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
   710  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   711  }
   712  
   713  // ListForManagementGroupResponder handles the response to the ListForManagementGroup request. The method always
   714  // closes the http.Response Body.
   715  func (client VariableValuesClient) ListForManagementGroupResponder(resp *http.Response) (result VariableValueListResult, err error) {
   716  	err = autorest.Respond(
   717  		resp,
   718  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   719  		autorest.ByUnmarshallingJSON(&result),
   720  		autorest.ByClosing())
   721  	result.Response = autorest.Response{Response: resp}
   722  	return
   723  }
   724  
   725  // listForManagementGroupNextResults retrieves the next set of results, if any.
   726  func (client VariableValuesClient) listForManagementGroupNextResults(ctx context.Context, lastResults VariableValueListResult) (result VariableValueListResult, err error) {
   727  	req, err := lastResults.variableValueListResultPreparer(ctx)
   728  	if err != nil {
   729  		return result, autorest.NewErrorWithError(err, "policy.VariableValuesClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
   730  	}
   731  	if req == nil {
   732  		return
   733  	}
   734  	resp, err := client.ListForManagementGroupSender(req)
   735  	if err != nil {
   736  		result.Response = autorest.Response{Response: resp}
   737  		return result, autorest.NewErrorWithError(err, "policy.VariableValuesClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
   738  	}
   739  	result, err = client.ListForManagementGroupResponder(resp)
   740  	if err != nil {
   741  		err = autorest.NewErrorWithError(err, "policy.VariableValuesClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
   742  	}
   743  	return
   744  }
   745  
   746  // ListForManagementGroupComplete enumerates all values, automatically crossing page boundaries as required.
   747  func (client VariableValuesClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, variableName string) (result VariableValueListResultIterator, err error) {
   748  	if tracing.IsEnabled() {
   749  		ctx = tracing.StartSpan(ctx, fqdn+"/VariableValuesClient.ListForManagementGroup")
   750  		defer func() {
   751  			sc := -1
   752  			if result.Response().Response.Response != nil {
   753  				sc = result.page.Response().Response.Response.StatusCode
   754  			}
   755  			tracing.EndSpan(ctx, sc, err)
   756  		}()
   757  	}
   758  	result.page, err = client.ListForManagementGroup(ctx, managementGroupID, variableName)
   759  	return
   760  }
   761  

View as plain text