...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/solutions/mgmt/2021-02-01-preview/managedapplications/jitrequests.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/solutions/mgmt/2021-02-01-preview/managedapplications

     1  package managedapplications
     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  // JitRequestsClient is the ARM applications
    19  type JitRequestsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewJitRequestsClient creates an instance of the JitRequestsClient client.
    24  func NewJitRequestsClient(subscriptionID string) JitRequestsClient {
    25  	return NewJitRequestsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewJitRequestsClientWithBaseURI creates an instance of the JitRequestsClient client using a custom endpoint.  Use
    29  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewJitRequestsClientWithBaseURI(baseURI string, subscriptionID string) JitRequestsClient {
    31  	return JitRequestsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or updates the JIT request.
    35  // Parameters:
    36  // resourceGroupName - the name of the resource group. The name is case insensitive.
    37  // jitRequestName - the name of the JIT request.
    38  // parameters - parameters supplied to the update JIT request.
    39  func (client JitRequestsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, jitRequestName string, parameters JitRequestDefinition) (result JitRequestsCreateOrUpdateFuture, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/JitRequestsClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    45  				sc = result.FutureAPI.Response().StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	if err := validation.Validate([]validation.Validation{
    51  		{TargetValue: client.SubscriptionID,
    52  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    53  		{TargetValue: resourceGroupName,
    54  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
    55  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
    56  		{TargetValue: parameters,
    57  			Constraints: []validation.Constraint{{Target: "parameters.JitRequestProperties", Name: validation.Null, Rule: false,
    58  				Chain: []validation.Constraint{{Target: "parameters.JitRequestProperties.ApplicationResourceID", Name: validation.Null, Rule: true, Chain: nil},
    59  					{Target: "parameters.JitRequestProperties.JitAuthorizationPolicies", Name: validation.Null, Rule: true, Chain: nil},
    60  					{Target: "parameters.JitRequestProperties.JitSchedulingPolicy", Name: validation.Null, Rule: true,
    61  						Chain: []validation.Constraint{{Target: "parameters.JitRequestProperties.JitSchedulingPolicy.Duration", Name: validation.Null, Rule: true, Chain: nil},
    62  							{Target: "parameters.JitRequestProperties.JitSchedulingPolicy.StartTime", Name: validation.Null, Rule: true, Chain: nil},
    63  						}},
    64  				}}}}}); err != nil {
    65  		return result, validation.NewError("managedapplications.JitRequestsClient", "CreateOrUpdate", err.Error())
    66  	}
    67  
    68  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, jitRequestName, parameters)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "CreateOrUpdate", nil, "Failure preparing request")
    71  		return
    72  	}
    73  
    74  	result, err = client.CreateOrUpdateSender(req)
    75  	if err != nil {
    76  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    77  		return
    78  	}
    79  
    80  	return
    81  }
    82  
    83  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    84  func (client JitRequestsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, jitRequestName string, parameters JitRequestDefinition) (*http.Request, error) {
    85  	pathParameters := map[string]interface{}{
    86  		"jitRequestName":    autorest.Encode("path", jitRequestName),
    87  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    88  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    89  	}
    90  
    91  	const APIVersion = "2021-02-01-preview"
    92  	queryParameters := map[string]interface{}{
    93  		"api-version": APIVersion,
    94  	}
    95  
    96  	preparer := autorest.CreatePreparer(
    97  		autorest.AsContentType("application/json; charset=utf-8"),
    98  		autorest.AsPut(),
    99  		autorest.WithBaseURL(client.BaseURI),
   100  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Solutions/jitRequests/{jitRequestName}", pathParameters),
   101  		autorest.WithJSON(parameters),
   102  		autorest.WithQueryParameters(queryParameters))
   103  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   104  }
   105  
   106  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   107  // http.Response Body if it receives an error.
   108  func (client JitRequestsClient) CreateOrUpdateSender(req *http.Request) (future JitRequestsCreateOrUpdateFuture, err error) {
   109  	var resp *http.Response
   110  	future.FutureAPI = &azure.Future{}
   111  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   112  	if err != nil {
   113  		return
   114  	}
   115  	var azf azure.Future
   116  	azf, err = azure.NewFutureFromResponse(resp)
   117  	future.FutureAPI = &azf
   118  	future.Result = future.result
   119  	return
   120  }
   121  
   122  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   123  // closes the http.Response Body.
   124  func (client JitRequestsClient) CreateOrUpdateResponder(resp *http.Response) (result JitRequestDefinition, err error) {
   125  	err = autorest.Respond(
   126  		resp,
   127  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   128  		autorest.ByUnmarshallingJSON(&result),
   129  		autorest.ByClosing())
   130  	result.Response = autorest.Response{Response: resp}
   131  	return
   132  }
   133  
   134  // Delete deletes the JIT request.
   135  // Parameters:
   136  // resourceGroupName - the name of the resource group. The name is case insensitive.
   137  // jitRequestName - the name of the JIT request.
   138  func (client JitRequestsClient) Delete(ctx context.Context, resourceGroupName string, jitRequestName string) (result autorest.Response, err error) {
   139  	if tracing.IsEnabled() {
   140  		ctx = tracing.StartSpan(ctx, fqdn+"/JitRequestsClient.Delete")
   141  		defer func() {
   142  			sc := -1
   143  			if result.Response != nil {
   144  				sc = result.Response.StatusCode
   145  			}
   146  			tracing.EndSpan(ctx, sc, err)
   147  		}()
   148  	}
   149  	if err := validation.Validate([]validation.Validation{
   150  		{TargetValue: client.SubscriptionID,
   151  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   152  		{TargetValue: resourceGroupName,
   153  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   154  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   155  		return result, validation.NewError("managedapplications.JitRequestsClient", "Delete", err.Error())
   156  	}
   157  
   158  	req, err := client.DeletePreparer(ctx, resourceGroupName, jitRequestName)
   159  	if err != nil {
   160  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Delete", nil, "Failure preparing request")
   161  		return
   162  	}
   163  
   164  	resp, err := client.DeleteSender(req)
   165  	if err != nil {
   166  		result.Response = resp
   167  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Delete", resp, "Failure sending request")
   168  		return
   169  	}
   170  
   171  	result, err = client.DeleteResponder(resp)
   172  	if err != nil {
   173  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Delete", resp, "Failure responding to request")
   174  		return
   175  	}
   176  
   177  	return
   178  }
   179  
   180  // DeletePreparer prepares the Delete request.
   181  func (client JitRequestsClient) DeletePreparer(ctx context.Context, resourceGroupName string, jitRequestName string) (*http.Request, error) {
   182  	pathParameters := map[string]interface{}{
   183  		"jitRequestName":    autorest.Encode("path", jitRequestName),
   184  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   185  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   186  	}
   187  
   188  	const APIVersion = "2021-02-01-preview"
   189  	queryParameters := map[string]interface{}{
   190  		"api-version": APIVersion,
   191  	}
   192  
   193  	preparer := autorest.CreatePreparer(
   194  		autorest.AsDelete(),
   195  		autorest.WithBaseURL(client.BaseURI),
   196  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Solutions/jitRequests/{jitRequestName}", pathParameters),
   197  		autorest.WithQueryParameters(queryParameters))
   198  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   199  }
   200  
   201  // DeleteSender sends the Delete request. The method will close the
   202  // http.Response Body if it receives an error.
   203  func (client JitRequestsClient) DeleteSender(req *http.Request) (*http.Response, error) {
   204  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   205  }
   206  
   207  // DeleteResponder handles the response to the Delete request. The method always
   208  // closes the http.Response Body.
   209  func (client JitRequestsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   210  	err = autorest.Respond(
   211  		resp,
   212  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   213  		autorest.ByClosing())
   214  	result.Response = resp
   215  	return
   216  }
   217  
   218  // Get gets the JIT request.
   219  // Parameters:
   220  // resourceGroupName - the name of the resource group. The name is case insensitive.
   221  // jitRequestName - the name of the JIT request.
   222  func (client JitRequestsClient) Get(ctx context.Context, resourceGroupName string, jitRequestName string) (result JitRequestDefinition, err error) {
   223  	if tracing.IsEnabled() {
   224  		ctx = tracing.StartSpan(ctx, fqdn+"/JitRequestsClient.Get")
   225  		defer func() {
   226  			sc := -1
   227  			if result.Response.Response != nil {
   228  				sc = result.Response.Response.StatusCode
   229  			}
   230  			tracing.EndSpan(ctx, sc, err)
   231  		}()
   232  	}
   233  	if err := validation.Validate([]validation.Validation{
   234  		{TargetValue: client.SubscriptionID,
   235  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   236  		{TargetValue: resourceGroupName,
   237  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   238  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   239  		return result, validation.NewError("managedapplications.JitRequestsClient", "Get", err.Error())
   240  	}
   241  
   242  	req, err := client.GetPreparer(ctx, resourceGroupName, jitRequestName)
   243  	if err != nil {
   244  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Get", nil, "Failure preparing request")
   245  		return
   246  	}
   247  
   248  	resp, err := client.GetSender(req)
   249  	if err != nil {
   250  		result.Response = autorest.Response{Response: resp}
   251  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Get", resp, "Failure sending request")
   252  		return
   253  	}
   254  
   255  	result, err = client.GetResponder(resp)
   256  	if err != nil {
   257  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Get", resp, "Failure responding to request")
   258  		return
   259  	}
   260  
   261  	return
   262  }
   263  
   264  // GetPreparer prepares the Get request.
   265  func (client JitRequestsClient) GetPreparer(ctx context.Context, resourceGroupName string, jitRequestName string) (*http.Request, error) {
   266  	pathParameters := map[string]interface{}{
   267  		"jitRequestName":    autorest.Encode("path", jitRequestName),
   268  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   269  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   270  	}
   271  
   272  	const APIVersion = "2021-02-01-preview"
   273  	queryParameters := map[string]interface{}{
   274  		"api-version": APIVersion,
   275  	}
   276  
   277  	preparer := autorest.CreatePreparer(
   278  		autorest.AsGet(),
   279  		autorest.WithBaseURL(client.BaseURI),
   280  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Solutions/jitRequests/{jitRequestName}", pathParameters),
   281  		autorest.WithQueryParameters(queryParameters))
   282  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   283  }
   284  
   285  // GetSender sends the Get request. The method will close the
   286  // http.Response Body if it receives an error.
   287  func (client JitRequestsClient) GetSender(req *http.Request) (*http.Response, error) {
   288  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   289  }
   290  
   291  // GetResponder handles the response to the Get request. The method always
   292  // closes the http.Response Body.
   293  func (client JitRequestsClient) GetResponder(resp *http.Response) (result JitRequestDefinition, err error) {
   294  	err = autorest.Respond(
   295  		resp,
   296  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound),
   297  		autorest.ByUnmarshallingJSON(&result),
   298  		autorest.ByClosing())
   299  	result.Response = autorest.Response{Response: resp}
   300  	return
   301  }
   302  
   303  // ListByResourceGroup lists all JIT requests within the resource group.
   304  // Parameters:
   305  // resourceGroupName - the name of the resource group. The name is case insensitive.
   306  func (client JitRequestsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result JitRequestDefinitionListResult, err error) {
   307  	if tracing.IsEnabled() {
   308  		ctx = tracing.StartSpan(ctx, fqdn+"/JitRequestsClient.ListByResourceGroup")
   309  		defer func() {
   310  			sc := -1
   311  			if result.Response.Response != nil {
   312  				sc = result.Response.Response.StatusCode
   313  			}
   314  			tracing.EndSpan(ctx, sc, err)
   315  		}()
   316  	}
   317  	if err := validation.Validate([]validation.Validation{
   318  		{TargetValue: client.SubscriptionID,
   319  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   320  		{TargetValue: resourceGroupName,
   321  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   322  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   323  		return result, validation.NewError("managedapplications.JitRequestsClient", "ListByResourceGroup", err.Error())
   324  	}
   325  
   326  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   327  	if err != nil {
   328  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "ListByResourceGroup", nil, "Failure preparing request")
   329  		return
   330  	}
   331  
   332  	resp, err := client.ListByResourceGroupSender(req)
   333  	if err != nil {
   334  		result.Response = autorest.Response{Response: resp}
   335  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "ListByResourceGroup", resp, "Failure sending request")
   336  		return
   337  	}
   338  
   339  	result, err = client.ListByResourceGroupResponder(resp)
   340  	if err != nil {
   341  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "ListByResourceGroup", resp, "Failure responding to request")
   342  		return
   343  	}
   344  
   345  	return
   346  }
   347  
   348  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   349  func (client JitRequestsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   350  	pathParameters := map[string]interface{}{
   351  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   352  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   353  	}
   354  
   355  	const APIVersion = "2021-02-01-preview"
   356  	queryParameters := map[string]interface{}{
   357  		"api-version": APIVersion,
   358  	}
   359  
   360  	preparer := autorest.CreatePreparer(
   361  		autorest.AsGet(),
   362  		autorest.WithBaseURL(client.BaseURI),
   363  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Solutions/jitRequests", pathParameters),
   364  		autorest.WithQueryParameters(queryParameters))
   365  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   366  }
   367  
   368  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   369  // http.Response Body if it receives an error.
   370  func (client JitRequestsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   371  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   372  }
   373  
   374  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   375  // closes the http.Response Body.
   376  func (client JitRequestsClient) ListByResourceGroupResponder(resp *http.Response) (result JitRequestDefinitionListResult, err error) {
   377  	err = autorest.Respond(
   378  		resp,
   379  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   380  		autorest.ByUnmarshallingJSON(&result),
   381  		autorest.ByClosing())
   382  	result.Response = autorest.Response{Response: resp}
   383  	return
   384  }
   385  
   386  // ListBySubscription lists all JIT requests within the subscription.
   387  func (client JitRequestsClient) ListBySubscription(ctx context.Context) (result JitRequestDefinitionListResult, err error) {
   388  	if tracing.IsEnabled() {
   389  		ctx = tracing.StartSpan(ctx, fqdn+"/JitRequestsClient.ListBySubscription")
   390  		defer func() {
   391  			sc := -1
   392  			if result.Response.Response != nil {
   393  				sc = result.Response.Response.StatusCode
   394  			}
   395  			tracing.EndSpan(ctx, sc, err)
   396  		}()
   397  	}
   398  	if err := validation.Validate([]validation.Validation{
   399  		{TargetValue: client.SubscriptionID,
   400  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   401  		return result, validation.NewError("managedapplications.JitRequestsClient", "ListBySubscription", err.Error())
   402  	}
   403  
   404  	req, err := client.ListBySubscriptionPreparer(ctx)
   405  	if err != nil {
   406  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "ListBySubscription", nil, "Failure preparing request")
   407  		return
   408  	}
   409  
   410  	resp, err := client.ListBySubscriptionSender(req)
   411  	if err != nil {
   412  		result.Response = autorest.Response{Response: resp}
   413  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "ListBySubscription", resp, "Failure sending request")
   414  		return
   415  	}
   416  
   417  	result, err = client.ListBySubscriptionResponder(resp)
   418  	if err != nil {
   419  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "ListBySubscription", resp, "Failure responding to request")
   420  		return
   421  	}
   422  
   423  	return
   424  }
   425  
   426  // ListBySubscriptionPreparer prepares the ListBySubscription request.
   427  func (client JitRequestsClient) ListBySubscriptionPreparer(ctx context.Context) (*http.Request, error) {
   428  	pathParameters := map[string]interface{}{
   429  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   430  	}
   431  
   432  	const APIVersion = "2021-02-01-preview"
   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("/subscriptions/{subscriptionId}/providers/Microsoft.Solutions/jitRequests", pathParameters),
   441  		autorest.WithQueryParameters(queryParameters))
   442  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   443  }
   444  
   445  // ListBySubscriptionSender sends the ListBySubscription request. The method will close the
   446  // http.Response Body if it receives an error.
   447  func (client JitRequestsClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
   448  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   449  }
   450  
   451  // ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
   452  // closes the http.Response Body.
   453  func (client JitRequestsClient) ListBySubscriptionResponder(resp *http.Response) (result JitRequestDefinitionListResult, 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  // Update updates the JIT request.
   464  // Parameters:
   465  // resourceGroupName - the name of the resource group. The name is case insensitive.
   466  // jitRequestName - the name of the JIT request.
   467  // parameters - parameters supplied to the update JIT request.
   468  func (client JitRequestsClient) Update(ctx context.Context, resourceGroupName string, jitRequestName string, parameters JitRequestPatchable) (result JitRequestDefinition, err error) {
   469  	if tracing.IsEnabled() {
   470  		ctx = tracing.StartSpan(ctx, fqdn+"/JitRequestsClient.Update")
   471  		defer func() {
   472  			sc := -1
   473  			if result.Response.Response != nil {
   474  				sc = result.Response.Response.StatusCode
   475  			}
   476  			tracing.EndSpan(ctx, sc, err)
   477  		}()
   478  	}
   479  	if err := validation.Validate([]validation.Validation{
   480  		{TargetValue: client.SubscriptionID,
   481  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   482  		{TargetValue: resourceGroupName,
   483  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   484  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   485  		return result, validation.NewError("managedapplications.JitRequestsClient", "Update", err.Error())
   486  	}
   487  
   488  	req, err := client.UpdatePreparer(ctx, resourceGroupName, jitRequestName, parameters)
   489  	if err != nil {
   490  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Update", nil, "Failure preparing request")
   491  		return
   492  	}
   493  
   494  	resp, err := client.UpdateSender(req)
   495  	if err != nil {
   496  		result.Response = autorest.Response{Response: resp}
   497  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Update", resp, "Failure sending request")
   498  		return
   499  	}
   500  
   501  	result, err = client.UpdateResponder(resp)
   502  	if err != nil {
   503  		err = autorest.NewErrorWithError(err, "managedapplications.JitRequestsClient", "Update", resp, "Failure responding to request")
   504  		return
   505  	}
   506  
   507  	return
   508  }
   509  
   510  // UpdatePreparer prepares the Update request.
   511  func (client JitRequestsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, jitRequestName string, parameters JitRequestPatchable) (*http.Request, error) {
   512  	pathParameters := map[string]interface{}{
   513  		"jitRequestName":    autorest.Encode("path", jitRequestName),
   514  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   515  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   516  	}
   517  
   518  	const APIVersion = "2021-02-01-preview"
   519  	queryParameters := map[string]interface{}{
   520  		"api-version": APIVersion,
   521  	}
   522  
   523  	preparer := autorest.CreatePreparer(
   524  		autorest.AsContentType("application/json; charset=utf-8"),
   525  		autorest.AsPatch(),
   526  		autorest.WithBaseURL(client.BaseURI),
   527  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Solutions/jitRequests/{jitRequestName}", pathParameters),
   528  		autorest.WithJSON(parameters),
   529  		autorest.WithQueryParameters(queryParameters))
   530  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   531  }
   532  
   533  // UpdateSender sends the Update request. The method will close the
   534  // http.Response Body if it receives an error.
   535  func (client JitRequestsClient) UpdateSender(req *http.Request) (*http.Response, error) {
   536  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   537  }
   538  
   539  // UpdateResponder handles the response to the Update request. The method always
   540  // closes the http.Response Body.
   541  func (client JitRequestsClient) UpdateResponder(resp *http.Response) (result JitRequestDefinition, err error) {
   542  	err = autorest.Respond(
   543  		resp,
   544  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   545  		autorest.ByUnmarshallingJSON(&result),
   546  		autorest.ByClosing())
   547  	result.Response = autorest.Response{Response: resp}
   548  	return
   549  }
   550  

View as plain text