...

Source file src/github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/face/snapshot.go

Documentation: github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v1.0/face

     1  package face
     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  	"github.com/gofrs/uuid"
    16  	"net/http"
    17  )
    18  
    19  // SnapshotClient is the an API for face detection, verification, and identification.
    20  type SnapshotClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewSnapshotClient creates an instance of the SnapshotClient client.
    25  func NewSnapshotClient(endpoint string) SnapshotClient {
    26  	return SnapshotClient{New(endpoint)}
    27  }
    28  
    29  // Apply submit an operation to apply a snapshot to current subscription. For each snapshot, only subscriptions
    30  // included in the applyScope of Snapshot - Take can apply it.<br />
    31  // The snapshot interfaces are for users to backup and restore their face data from one face subscription to another,
    32  // inside same region or across regions. The workflow contains two phases, user first calls Snapshot - Take to create a
    33  // copy of the source object and store it as a snapshot, then calls Snapshot - Apply to paste the snapshot to target
    34  // subscription. The snapshots are stored in a centralized location (per Azure instance), so that they can be applied
    35  // cross accounts and regions.<br />
    36  // Applying snapshot is an asynchronous operation. An operation id can be obtained from the "Operation-Location" field
    37  // in response header, to be used in OperationStatus - Get for tracking the progress of applying the snapshot. The
    38  // target object id will be included in the "resourceLocation" field in OperationStatus - Get response when the
    39  // operation status is "succeeded".<br />
    40  // Snapshot applying time depends on the number of person and face entries in the snapshot object. It could be in
    41  // seconds, or up to 1 hour for 1,000,000 persons with multiple faces.<br />
    42  // Snapshots will be automatically expired and cleaned in 48 hours after it is created by Snapshot - Take. So the
    43  // target subscription is required to apply the snapshot in 48 hours since its creation.<br />
    44  // Applying a snapshot will not block any other operations against the target object, however it is not recommended
    45  // because the correctness cannot be guaranteed during snapshot applying. After snapshot applying is completed, all
    46  // operations towards the target object can work as normal. Snapshot also includes the training results of the source
    47  // object, which means target subscription the snapshot applied to does not need re-train the target object before
    48  // calling Identify/FindSimilar.<br />
    49  // One snapshot can be applied multiple times in parallel, while currently only CreateNew apply mode is supported,
    50  // which means the apply operation will fail if target subscription already contains an object of same type and using
    51  // the same objectId. Users can specify the "objectId" in request body to avoid such conflicts.<br />
    52  // * Free-tier subscription quota: 100 apply operations per month.
    53  // * S0-tier subscription quota: 100 apply operations per day.
    54  // Parameters:
    55  // snapshotID - id referencing a particular snapshot.
    56  // body - request body for applying a snapshot.
    57  func (client SnapshotClient) Apply(ctx context.Context, snapshotID uuid.UUID, body ApplySnapshotRequest) (result autorest.Response, err error) {
    58  	if tracing.IsEnabled() {
    59  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Apply")
    60  		defer func() {
    61  			sc := -1
    62  			if result.Response != nil {
    63  				sc = result.Response.StatusCode
    64  			}
    65  			tracing.EndSpan(ctx, sc, err)
    66  		}()
    67  	}
    68  	if err := validation.Validate([]validation.Validation{
    69  		{TargetValue: body,
    70  			Constraints: []validation.Constraint{{Target: "body.ObjectID", Name: validation.Null, Rule: true,
    71  				Chain: []validation.Constraint{{Target: "body.ObjectID", Name: validation.MaxLength, Rule: 64, Chain: nil},
    72  					{Target: "body.ObjectID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil},
    73  				}}}}}); err != nil {
    74  		return result, validation.NewError("face.SnapshotClient", "Apply", err.Error())
    75  	}
    76  
    77  	req, err := client.ApplyPreparer(ctx, snapshotID, body)
    78  	if err != nil {
    79  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", nil, "Failure preparing request")
    80  		return
    81  	}
    82  
    83  	resp, err := client.ApplySender(req)
    84  	if err != nil {
    85  		result.Response = resp
    86  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", resp, "Failure sending request")
    87  		return
    88  	}
    89  
    90  	result, err = client.ApplyResponder(resp)
    91  	if err != nil {
    92  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", resp, "Failure responding to request")
    93  		return
    94  	}
    95  
    96  	return
    97  }
    98  
    99  // ApplyPreparer prepares the Apply request.
   100  func (client SnapshotClient) ApplyPreparer(ctx context.Context, snapshotID uuid.UUID, body ApplySnapshotRequest) (*http.Request, error) {
   101  	urlParameters := map[string]interface{}{
   102  		"Endpoint": client.Endpoint,
   103  	}
   104  
   105  	pathParameters := map[string]interface{}{
   106  		"snapshotId": autorest.Encode("path", snapshotID),
   107  	}
   108  
   109  	preparer := autorest.CreatePreparer(
   110  		autorest.AsContentType("application/json; charset=utf-8"),
   111  		autorest.AsPost(),
   112  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   113  		autorest.WithPathParameters("/snapshots/{snapshotId}/apply", pathParameters),
   114  		autorest.WithJSON(body))
   115  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   116  }
   117  
   118  // ApplySender sends the Apply request. The method will close the
   119  // http.Response Body if it receives an error.
   120  func (client SnapshotClient) ApplySender(req *http.Request) (*http.Response, error) {
   121  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   122  }
   123  
   124  // ApplyResponder handles the response to the Apply request. The method always
   125  // closes the http.Response Body.
   126  func (client SnapshotClient) ApplyResponder(resp *http.Response) (result autorest.Response, err error) {
   127  	err = autorest.Respond(
   128  		resp,
   129  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   130  		autorest.ByClosing())
   131  	result.Response = resp
   132  	return
   133  }
   134  
   135  // Delete delete an existing snapshot according to the snapshotId. All object data and information in the snapshot will
   136  // also be deleted. Only the source subscription who took the snapshot can delete the snapshot. If the user does not
   137  // delete a snapshot with this API, the snapshot will still be automatically deleted in 48 hours after creation.
   138  // Parameters:
   139  // snapshotID - id referencing a particular snapshot.
   140  func (client SnapshotClient) Delete(ctx context.Context, snapshotID uuid.UUID) (result autorest.Response, err error) {
   141  	if tracing.IsEnabled() {
   142  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Delete")
   143  		defer func() {
   144  			sc := -1
   145  			if result.Response != nil {
   146  				sc = result.Response.StatusCode
   147  			}
   148  			tracing.EndSpan(ctx, sc, err)
   149  		}()
   150  	}
   151  	req, err := client.DeletePreparer(ctx, snapshotID)
   152  	if err != nil {
   153  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", nil, "Failure preparing request")
   154  		return
   155  	}
   156  
   157  	resp, err := client.DeleteSender(req)
   158  	if err != nil {
   159  		result.Response = resp
   160  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", resp, "Failure sending request")
   161  		return
   162  	}
   163  
   164  	result, err = client.DeleteResponder(resp)
   165  	if err != nil {
   166  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", resp, "Failure responding to request")
   167  		return
   168  	}
   169  
   170  	return
   171  }
   172  
   173  // DeletePreparer prepares the Delete request.
   174  func (client SnapshotClient) DeletePreparer(ctx context.Context, snapshotID uuid.UUID) (*http.Request, error) {
   175  	urlParameters := map[string]interface{}{
   176  		"Endpoint": client.Endpoint,
   177  	}
   178  
   179  	pathParameters := map[string]interface{}{
   180  		"snapshotId": autorest.Encode("path", snapshotID),
   181  	}
   182  
   183  	preparer := autorest.CreatePreparer(
   184  		autorest.AsDelete(),
   185  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   186  		autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters))
   187  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   188  }
   189  
   190  // DeleteSender sends the Delete request. The method will close the
   191  // http.Response Body if it receives an error.
   192  func (client SnapshotClient) DeleteSender(req *http.Request) (*http.Response, error) {
   193  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   194  }
   195  
   196  // DeleteResponder handles the response to the Delete request. The method always
   197  // closes the http.Response Body.
   198  func (client SnapshotClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   199  	err = autorest.Respond(
   200  		resp,
   201  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   202  		autorest.ByClosing())
   203  	result.Response = resp
   204  	return
   205  }
   206  
   207  // Get retrieve information about a snapshot. Snapshot is only accessible to the source subscription who took it, and
   208  // target subscriptions included in the applyScope in Snapshot - Take.
   209  // Parameters:
   210  // snapshotID - id referencing a particular snapshot.
   211  func (client SnapshotClient) Get(ctx context.Context, snapshotID uuid.UUID) (result Snapshot, err error) {
   212  	if tracing.IsEnabled() {
   213  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Get")
   214  		defer func() {
   215  			sc := -1
   216  			if result.Response.Response != nil {
   217  				sc = result.Response.Response.StatusCode
   218  			}
   219  			tracing.EndSpan(ctx, sc, err)
   220  		}()
   221  	}
   222  	req, err := client.GetPreparer(ctx, snapshotID)
   223  	if err != nil {
   224  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", nil, "Failure preparing request")
   225  		return
   226  	}
   227  
   228  	resp, err := client.GetSender(req)
   229  	if err != nil {
   230  		result.Response = autorest.Response{Response: resp}
   231  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", resp, "Failure sending request")
   232  		return
   233  	}
   234  
   235  	result, err = client.GetResponder(resp)
   236  	if err != nil {
   237  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", resp, "Failure responding to request")
   238  		return
   239  	}
   240  
   241  	return
   242  }
   243  
   244  // GetPreparer prepares the Get request.
   245  func (client SnapshotClient) GetPreparer(ctx context.Context, snapshotID uuid.UUID) (*http.Request, error) {
   246  	urlParameters := map[string]interface{}{
   247  		"Endpoint": client.Endpoint,
   248  	}
   249  
   250  	pathParameters := map[string]interface{}{
   251  		"snapshotId": autorest.Encode("path", snapshotID),
   252  	}
   253  
   254  	preparer := autorest.CreatePreparer(
   255  		autorest.AsGet(),
   256  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   257  		autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters))
   258  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   259  }
   260  
   261  // GetSender sends the Get request. The method will close the
   262  // http.Response Body if it receives an error.
   263  func (client SnapshotClient) GetSender(req *http.Request) (*http.Response, error) {
   264  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   265  }
   266  
   267  // GetResponder handles the response to the Get request. The method always
   268  // closes the http.Response Body.
   269  func (client SnapshotClient) GetResponder(resp *http.Response) (result Snapshot, err error) {
   270  	err = autorest.Respond(
   271  		resp,
   272  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   273  		autorest.ByUnmarshallingJSON(&result),
   274  		autorest.ByClosing())
   275  	result.Response = autorest.Response{Response: resp}
   276  	return
   277  }
   278  
   279  // GetOperationStatus retrieve the status of a take/apply snapshot operation.
   280  // Parameters:
   281  // operationID - id referencing a particular take/apply snapshot operation.
   282  func (client SnapshotClient) GetOperationStatus(ctx context.Context, operationID uuid.UUID) (result OperationStatus, err error) {
   283  	if tracing.IsEnabled() {
   284  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.GetOperationStatus")
   285  		defer func() {
   286  			sc := -1
   287  			if result.Response.Response != nil {
   288  				sc = result.Response.Response.StatusCode
   289  			}
   290  			tracing.EndSpan(ctx, sc, err)
   291  		}()
   292  	}
   293  	req, err := client.GetOperationStatusPreparer(ctx, operationID)
   294  	if err != nil {
   295  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", nil, "Failure preparing request")
   296  		return
   297  	}
   298  
   299  	resp, err := client.GetOperationStatusSender(req)
   300  	if err != nil {
   301  		result.Response = autorest.Response{Response: resp}
   302  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", resp, "Failure sending request")
   303  		return
   304  	}
   305  
   306  	result, err = client.GetOperationStatusResponder(resp)
   307  	if err != nil {
   308  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", resp, "Failure responding to request")
   309  		return
   310  	}
   311  
   312  	return
   313  }
   314  
   315  // GetOperationStatusPreparer prepares the GetOperationStatus request.
   316  func (client SnapshotClient) GetOperationStatusPreparer(ctx context.Context, operationID uuid.UUID) (*http.Request, error) {
   317  	urlParameters := map[string]interface{}{
   318  		"Endpoint": client.Endpoint,
   319  	}
   320  
   321  	pathParameters := map[string]interface{}{
   322  		"operationId": autorest.Encode("path", operationID),
   323  	}
   324  
   325  	preparer := autorest.CreatePreparer(
   326  		autorest.AsGet(),
   327  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   328  		autorest.WithPathParameters("/operations/{operationId}", pathParameters))
   329  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   330  }
   331  
   332  // GetOperationStatusSender sends the GetOperationStatus request. The method will close the
   333  // http.Response Body if it receives an error.
   334  func (client SnapshotClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) {
   335  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   336  }
   337  
   338  // GetOperationStatusResponder handles the response to the GetOperationStatus request. The method always
   339  // closes the http.Response Body.
   340  func (client SnapshotClient) GetOperationStatusResponder(resp *http.Response) (result OperationStatus, err error) {
   341  	err = autorest.Respond(
   342  		resp,
   343  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   344  		autorest.ByUnmarshallingJSON(&result),
   345  		autorest.ByClosing())
   346  	result.Response = autorest.Response{Response: resp}
   347  	return
   348  }
   349  
   350  // List list all accessible snapshots with related information, including snapshots that were taken by the user, or
   351  // snapshots to be applied to the user (subscription id was included in the applyScope in Snapshot - Take).
   352  // Parameters:
   353  // typeParameter - user specified object type as a search filter.
   354  // applyScope - user specified snapshot apply scopes as a search filter. ApplyScope is an array of the target
   355  // Azure subscription ids for the snapshot, specified by the user who created the snapshot by Snapshot - Take.
   356  func (client SnapshotClient) List(ctx context.Context, typeParameter SnapshotObjectType, applyScope []uuid.UUID) (result ListSnapshot, err error) {
   357  	if tracing.IsEnabled() {
   358  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.List")
   359  		defer func() {
   360  			sc := -1
   361  			if result.Response.Response != nil {
   362  				sc = result.Response.Response.StatusCode
   363  			}
   364  			tracing.EndSpan(ctx, sc, err)
   365  		}()
   366  	}
   367  	req, err := client.ListPreparer(ctx, typeParameter, applyScope)
   368  	if err != nil {
   369  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", nil, "Failure preparing request")
   370  		return
   371  	}
   372  
   373  	resp, err := client.ListSender(req)
   374  	if err != nil {
   375  		result.Response = autorest.Response{Response: resp}
   376  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", resp, "Failure sending request")
   377  		return
   378  	}
   379  
   380  	result, err = client.ListResponder(resp)
   381  	if err != nil {
   382  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", resp, "Failure responding to request")
   383  		return
   384  	}
   385  
   386  	return
   387  }
   388  
   389  // ListPreparer prepares the List request.
   390  func (client SnapshotClient) ListPreparer(ctx context.Context, typeParameter SnapshotObjectType, applyScope []uuid.UUID) (*http.Request, error) {
   391  	urlParameters := map[string]interface{}{
   392  		"Endpoint": client.Endpoint,
   393  	}
   394  
   395  	queryParameters := map[string]interface{}{}
   396  	if len(string(typeParameter)) > 0 {
   397  		queryParameters["type"] = autorest.Encode("query", typeParameter)
   398  	}
   399  	if applyScope != nil && len(applyScope) > 0 {
   400  		queryParameters["applyScope"] = autorest.Encode("query", applyScope, ",")
   401  	}
   402  
   403  	preparer := autorest.CreatePreparer(
   404  		autorest.AsGet(),
   405  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   406  		autorest.WithPath("/snapshots"),
   407  		autorest.WithQueryParameters(queryParameters))
   408  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   409  }
   410  
   411  // ListSender sends the List request. The method will close the
   412  // http.Response Body if it receives an error.
   413  func (client SnapshotClient) ListSender(req *http.Request) (*http.Response, error) {
   414  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   415  }
   416  
   417  // ListResponder handles the response to the List request. The method always
   418  // closes the http.Response Body.
   419  func (client SnapshotClient) ListResponder(resp *http.Response) (result ListSnapshot, err error) {
   420  	err = autorest.Respond(
   421  		resp,
   422  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   423  		autorest.ByUnmarshallingJSON(&result.Value),
   424  		autorest.ByClosing())
   425  	result.Response = autorest.Response{Response: resp}
   426  	return
   427  }
   428  
   429  // Take submit an operation to take a snapshot of face list, large face list, person group or large person group, with
   430  // user-specified snapshot type, source object id, apply scope and an optional user data.<br />
   431  // The snapshot interfaces are for users to backup and restore their face data from one face subscription to another,
   432  // inside same region or across regions. The workflow contains two phases, user first calls Snapshot - Take to create a
   433  // copy of the source object and store it as a snapshot, then calls Snapshot - Apply to paste the snapshot to target
   434  // subscription. The snapshots are stored in a centralized location (per Azure instance), so that they can be applied
   435  // cross accounts and regions.<br />
   436  // Taking snapshot is an asynchronous operation. An operation id can be obtained from the "Operation-Location" field in
   437  // response header, to be used in OperationStatus - Get for tracking the progress of creating the snapshot. The
   438  // snapshot id will be included in the "resourceLocation" field in OperationStatus - Get response when the operation
   439  // status is "succeeded".<br />
   440  // Snapshot taking time depends on the number of person and face entries in the source object. It could be in seconds,
   441  // or up to several hours for 1,000,000 persons with multiple faces.<br />
   442  // Snapshots will be automatically expired and cleaned in 48 hours after it is created by Snapshot - Take. User can
   443  // delete the snapshot using Snapshot - Delete by themselves any time before expiration.<br />
   444  // Taking snapshot for a certain object will not block any other operations against the object. All read-only
   445  // operations (Get/List and Identify/FindSimilar/Verify) can be conducted as usual. For all writable operations,
   446  // including Add/Update/Delete the source object or its persons/faces and Train, they are not blocked but not
   447  // recommended because writable updates may not be reflected on the snapshot during its taking. After snapshot taking
   448  // is completed, all readable and writable operations can work as normal. Snapshot will also include the training
   449  // results of the source object, which means target subscription the snapshot applied to does not need re-train the
   450  // target object before calling Identify/FindSimilar.<br />
   451  // * Free-tier subscription quota: 100 take operations per month.
   452  // * S0-tier subscription quota: 100 take operations per day.
   453  // Parameters:
   454  // body - request body for taking a snapshot.
   455  func (client SnapshotClient) Take(ctx context.Context, body TakeSnapshotRequest) (result autorest.Response, err error) {
   456  	if tracing.IsEnabled() {
   457  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Take")
   458  		defer func() {
   459  			sc := -1
   460  			if result.Response != nil {
   461  				sc = result.Response.StatusCode
   462  			}
   463  			tracing.EndSpan(ctx, sc, err)
   464  		}()
   465  	}
   466  	if err := validation.Validate([]validation.Validation{
   467  		{TargetValue: body,
   468  			Constraints: []validation.Constraint{{Target: "body.ObjectID", Name: validation.Null, Rule: true,
   469  				Chain: []validation.Constraint{{Target: "body.ObjectID", Name: validation.MaxLength, Rule: 64, Chain: nil},
   470  					{Target: "body.ObjectID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil},
   471  				}},
   472  				{Target: "body.ApplyScope", Name: validation.Null, Rule: true, Chain: nil},
   473  				{Target: "body.UserData", Name: validation.Null, Rule: false,
   474  					Chain: []validation.Constraint{{Target: "body.UserData", Name: validation.MaxLength, Rule: 16384, Chain: nil}}}}}}); err != nil {
   475  		return result, validation.NewError("face.SnapshotClient", "Take", err.Error())
   476  	}
   477  
   478  	req, err := client.TakePreparer(ctx, body)
   479  	if err != nil {
   480  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", nil, "Failure preparing request")
   481  		return
   482  	}
   483  
   484  	resp, err := client.TakeSender(req)
   485  	if err != nil {
   486  		result.Response = resp
   487  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", resp, "Failure sending request")
   488  		return
   489  	}
   490  
   491  	result, err = client.TakeResponder(resp)
   492  	if err != nil {
   493  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", resp, "Failure responding to request")
   494  		return
   495  	}
   496  
   497  	return
   498  }
   499  
   500  // TakePreparer prepares the Take request.
   501  func (client SnapshotClient) TakePreparer(ctx context.Context, body TakeSnapshotRequest) (*http.Request, error) {
   502  	urlParameters := map[string]interface{}{
   503  		"Endpoint": client.Endpoint,
   504  	}
   505  
   506  	preparer := autorest.CreatePreparer(
   507  		autorest.AsContentType("application/json; charset=utf-8"),
   508  		autorest.AsPost(),
   509  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   510  		autorest.WithPath("/snapshots"),
   511  		autorest.WithJSON(body))
   512  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   513  }
   514  
   515  // TakeSender sends the Take request. The method will close the
   516  // http.Response Body if it receives an error.
   517  func (client SnapshotClient) TakeSender(req *http.Request) (*http.Response, error) {
   518  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   519  }
   520  
   521  // TakeResponder handles the response to the Take request. The method always
   522  // closes the http.Response Body.
   523  func (client SnapshotClient) TakeResponder(resp *http.Response) (result autorest.Response, err error) {
   524  	err = autorest.Respond(
   525  		resp,
   526  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   527  		autorest.ByClosing())
   528  	result.Response = resp
   529  	return
   530  }
   531  
   532  // Update update the information of a snapshot. Only the source subscription who took the snapshot can update the
   533  // snapshot.
   534  // Parameters:
   535  // snapshotID - id referencing a particular snapshot.
   536  // body - request body for updating a snapshot.
   537  func (client SnapshotClient) Update(ctx context.Context, snapshotID uuid.UUID, body UpdateSnapshotRequest) (result autorest.Response, err error) {
   538  	if tracing.IsEnabled() {
   539  		ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Update")
   540  		defer func() {
   541  			sc := -1
   542  			if result.Response != nil {
   543  				sc = result.Response.StatusCode
   544  			}
   545  			tracing.EndSpan(ctx, sc, err)
   546  		}()
   547  	}
   548  	req, err := client.UpdatePreparer(ctx, snapshotID, body)
   549  	if err != nil {
   550  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", nil, "Failure preparing request")
   551  		return
   552  	}
   553  
   554  	resp, err := client.UpdateSender(req)
   555  	if err != nil {
   556  		result.Response = resp
   557  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", resp, "Failure sending request")
   558  		return
   559  	}
   560  
   561  	result, err = client.UpdateResponder(resp)
   562  	if err != nil {
   563  		err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", resp, "Failure responding to request")
   564  		return
   565  	}
   566  
   567  	return
   568  }
   569  
   570  // UpdatePreparer prepares the Update request.
   571  func (client SnapshotClient) UpdatePreparer(ctx context.Context, snapshotID uuid.UUID, body UpdateSnapshotRequest) (*http.Request, error) {
   572  	urlParameters := map[string]interface{}{
   573  		"Endpoint": client.Endpoint,
   574  	}
   575  
   576  	pathParameters := map[string]interface{}{
   577  		"snapshotId": autorest.Encode("path", snapshotID),
   578  	}
   579  
   580  	preparer := autorest.CreatePreparer(
   581  		autorest.AsContentType("application/json; charset=utf-8"),
   582  		autorest.AsPatch(),
   583  		autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters),
   584  		autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters),
   585  		autorest.WithJSON(body))
   586  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   587  }
   588  
   589  // UpdateSender sends the Update request. The method will close the
   590  // http.Response Body if it receives an error.
   591  func (client SnapshotClient) UpdateSender(req *http.Request) (*http.Response, error) {
   592  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   593  }
   594  
   595  // UpdateResponder handles the response to the Update request. The method always
   596  // closes the http.Response Body.
   597  func (client SnapshotClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) {
   598  	err = autorest.Respond(
   599  		resp,
   600  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   601  		autorest.ByClosing())
   602  	result.Response = resp
   603  	return
   604  }
   605  

View as plain text