diff --git a/profiles/latest/cognitiveservices/face/faceapi/models.go b/profiles/latest/cognitiveservices/face/faceapi/models.go index 2be0e3d023f1..cfb1153bedef 100644 --- a/profiles/latest/cognitiveservices/face/faceapi/models.go +++ b/profiles/latest/cognitiveservices/face/faceapi/models.go @@ -28,3 +28,4 @@ type LargePersonGroupPersonClientAPI = original.LargePersonGroupPersonClientAPI type ListClientAPI = original.ListClientAPI type PersonGroupClientAPI = original.PersonGroupClientAPI type PersonGroupPersonClientAPI = original.PersonGroupPersonClientAPI +type SnapshotClientAPI = original.SnapshotClientAPI diff --git a/profiles/latest/cognitiveservices/face/models.go b/profiles/latest/cognitiveservices/face/models.go index a342afcc93e5..614952509e9c 100644 --- a/profiles/latest/cognitiveservices/face/models.go +++ b/profiles/latest/cognitiveservices/face/models.go @@ -109,17 +109,42 @@ const ( NoiseLevelMedium NoiseLevel = original.NoiseLevelMedium ) +type OperationStatusType = original.OperationStatusType + +const ( + Failed OperationStatusType = original.Failed + Notstarted OperationStatusType = original.Notstarted + Running OperationStatusType = original.Running + Succeeded OperationStatusType = original.Succeeded +) + +type SnapshotApplyMode = original.SnapshotApplyMode + +const ( + CreateNew SnapshotApplyMode = original.CreateNew +) + +type SnapshotObjectType = original.SnapshotObjectType + +const ( + SnapshotObjectTypeFaceList SnapshotObjectType = original.SnapshotObjectTypeFaceList + SnapshotObjectTypeLargeFaceList SnapshotObjectType = original.SnapshotObjectTypeLargeFaceList + SnapshotObjectTypeLargePersonGroup SnapshotObjectType = original.SnapshotObjectTypeLargePersonGroup + SnapshotObjectTypePersonGroup SnapshotObjectType = original.SnapshotObjectTypePersonGroup +) + type TrainingStatusType = original.TrainingStatusType const ( - Failed TrainingStatusType = original.Failed - Nonstarted TrainingStatusType = original.Nonstarted - Running TrainingStatusType = original.Running - Succeeded TrainingStatusType = original.Succeeded + TrainingStatusTypeFailed TrainingStatusType = original.TrainingStatusTypeFailed + TrainingStatusTypeNonstarted TrainingStatusType = original.TrainingStatusTypeNonstarted + TrainingStatusTypeRunning TrainingStatusType = original.TrainingStatusTypeRunning + TrainingStatusTypeSucceeded TrainingStatusType = original.TrainingStatusTypeSucceeded ) type APIError = original.APIError type Accessory = original.Accessory +type ApplySnapshotRequest = original.ApplySnapshotRequest type Attributes = original.Attributes type BaseClient = original.BaseClient type Blur = original.Blur @@ -157,10 +182,12 @@ type ListPersistedFace = original.ListPersistedFace type ListPerson = original.ListPerson type ListPersonGroup = original.ListPersonGroup type ListSimilarFace = original.ListSimilarFace +type ListSnapshot = original.ListSnapshot type Makeup = original.Makeup type NameAndUserDataContract = original.NameAndUserDataContract type Noise = original.Noise type Occlusion = original.Occlusion +type OperationStatus = original.OperationStatus type PersistedFace = original.PersistedFace type Person = original.Person type PersonGroup = original.PersonGroup @@ -168,8 +195,12 @@ type PersonGroupClient = original.PersonGroupClient type PersonGroupPersonClient = original.PersonGroupPersonClient type Rectangle = original.Rectangle type SimilarFace = original.SimilarFace +type Snapshot = original.Snapshot +type SnapshotClient = original.SnapshotClient +type TakeSnapshotRequest = original.TakeSnapshotRequest type TrainingStatus = original.TrainingStatus type UpdateFaceRequest = original.UpdateFaceRequest +type UpdateSnapshotRequest = original.UpdateSnapshotRequest type VerifyFaceToFaceRequest = original.VerifyFaceToFaceRequest type VerifyFaceToPersonRequest = original.VerifyFaceToPersonRequest type VerifyResult = original.VerifyResult @@ -198,6 +229,9 @@ func NewPersonGroupClient(endpoint string) PersonGroupClient { func NewPersonGroupPersonClient(endpoint string) PersonGroupPersonClient { return original.NewPersonGroupPersonClient(endpoint) } +func NewSnapshotClient(endpoint string) SnapshotClient { + return original.NewSnapshotClient(endpoint) +} func NewWithoutDefaults(endpoint string) BaseClient { return original.NewWithoutDefaults(endpoint) } @@ -228,6 +262,15 @@ func PossibleHairColorTypeValues() []HairColorType { func PossibleNoiseLevelValues() []NoiseLevel { return original.PossibleNoiseLevelValues() } +func PossibleOperationStatusTypeValues() []OperationStatusType { + return original.PossibleOperationStatusTypeValues() +} +func PossibleSnapshotApplyModeValues() []SnapshotApplyMode { + return original.PossibleSnapshotApplyModeValues() +} +func PossibleSnapshotObjectTypeValues() []SnapshotObjectType { + return original.PossibleSnapshotObjectTypeValues() +} func PossibleTrainingStatusTypeValues() []TrainingStatusType { return original.PossibleTrainingStatusTypeValues() } diff --git a/profiles/preview/cognitiveservices/face/faceapi/models.go b/profiles/preview/cognitiveservices/face/faceapi/models.go index 2be0e3d023f1..cfb1153bedef 100644 --- a/profiles/preview/cognitiveservices/face/faceapi/models.go +++ b/profiles/preview/cognitiveservices/face/faceapi/models.go @@ -28,3 +28,4 @@ type LargePersonGroupPersonClientAPI = original.LargePersonGroupPersonClientAPI type ListClientAPI = original.ListClientAPI type PersonGroupClientAPI = original.PersonGroupClientAPI type PersonGroupPersonClientAPI = original.PersonGroupPersonClientAPI +type SnapshotClientAPI = original.SnapshotClientAPI diff --git a/profiles/preview/cognitiveservices/face/models.go b/profiles/preview/cognitiveservices/face/models.go index 30e0cb11b1e7..71bb8182fb4d 100644 --- a/profiles/preview/cognitiveservices/face/models.go +++ b/profiles/preview/cognitiveservices/face/models.go @@ -109,17 +109,42 @@ const ( NoiseLevelMedium NoiseLevel = original.NoiseLevelMedium ) +type OperationStatusType = original.OperationStatusType + +const ( + Failed OperationStatusType = original.Failed + Notstarted OperationStatusType = original.Notstarted + Running OperationStatusType = original.Running + Succeeded OperationStatusType = original.Succeeded +) + +type SnapshotApplyMode = original.SnapshotApplyMode + +const ( + CreateNew SnapshotApplyMode = original.CreateNew +) + +type SnapshotObjectType = original.SnapshotObjectType + +const ( + SnapshotObjectTypeFaceList SnapshotObjectType = original.SnapshotObjectTypeFaceList + SnapshotObjectTypeLargeFaceList SnapshotObjectType = original.SnapshotObjectTypeLargeFaceList + SnapshotObjectTypeLargePersonGroup SnapshotObjectType = original.SnapshotObjectTypeLargePersonGroup + SnapshotObjectTypePersonGroup SnapshotObjectType = original.SnapshotObjectTypePersonGroup +) + type TrainingStatusType = original.TrainingStatusType const ( - Failed TrainingStatusType = original.Failed - Nonstarted TrainingStatusType = original.Nonstarted - Running TrainingStatusType = original.Running - Succeeded TrainingStatusType = original.Succeeded + TrainingStatusTypeFailed TrainingStatusType = original.TrainingStatusTypeFailed + TrainingStatusTypeNonstarted TrainingStatusType = original.TrainingStatusTypeNonstarted + TrainingStatusTypeRunning TrainingStatusType = original.TrainingStatusTypeRunning + TrainingStatusTypeSucceeded TrainingStatusType = original.TrainingStatusTypeSucceeded ) type APIError = original.APIError type Accessory = original.Accessory +type ApplySnapshotRequest = original.ApplySnapshotRequest type Attributes = original.Attributes type BaseClient = original.BaseClient type Blur = original.Blur @@ -157,10 +182,12 @@ type ListPersistedFace = original.ListPersistedFace type ListPerson = original.ListPerson type ListPersonGroup = original.ListPersonGroup type ListSimilarFace = original.ListSimilarFace +type ListSnapshot = original.ListSnapshot type Makeup = original.Makeup type NameAndUserDataContract = original.NameAndUserDataContract type Noise = original.Noise type Occlusion = original.Occlusion +type OperationStatus = original.OperationStatus type PersistedFace = original.PersistedFace type Person = original.Person type PersonGroup = original.PersonGroup @@ -168,8 +195,12 @@ type PersonGroupClient = original.PersonGroupClient type PersonGroupPersonClient = original.PersonGroupPersonClient type Rectangle = original.Rectangle type SimilarFace = original.SimilarFace +type Snapshot = original.Snapshot +type SnapshotClient = original.SnapshotClient +type TakeSnapshotRequest = original.TakeSnapshotRequest type TrainingStatus = original.TrainingStatus type UpdateFaceRequest = original.UpdateFaceRequest +type UpdateSnapshotRequest = original.UpdateSnapshotRequest type VerifyFaceToFaceRequest = original.VerifyFaceToFaceRequest type VerifyFaceToPersonRequest = original.VerifyFaceToPersonRequest type VerifyResult = original.VerifyResult @@ -198,6 +229,9 @@ func NewPersonGroupClient(endpoint string) PersonGroupClient { func NewPersonGroupPersonClient(endpoint string) PersonGroupPersonClient { return original.NewPersonGroupPersonClient(endpoint) } +func NewSnapshotClient(endpoint string) SnapshotClient { + return original.NewSnapshotClient(endpoint) +} func NewWithoutDefaults(endpoint string) BaseClient { return original.NewWithoutDefaults(endpoint) } @@ -228,6 +262,15 @@ func PossibleHairColorTypeValues() []HairColorType { func PossibleNoiseLevelValues() []NoiseLevel { return original.PossibleNoiseLevelValues() } +func PossibleOperationStatusTypeValues() []OperationStatusType { + return original.PossibleOperationStatusTypeValues() +} +func PossibleSnapshotApplyModeValues() []SnapshotApplyMode { + return original.PossibleSnapshotApplyModeValues() +} +func PossibleSnapshotObjectTypeValues() []SnapshotObjectType { + return original.PossibleSnapshotObjectTypeValues() +} func PossibleTrainingStatusTypeValues() []TrainingStatusType { return original.PossibleTrainingStatusTypeValues() } diff --git a/services/cognitiveservices/v1.0/face/faceapi/interfaces.go b/services/cognitiveservices/v1.0/face/faceapi/interfaces.go index eda77aa78a53..a25d6d6cbe10 100644 --- a/services/cognitiveservices/v1.0/face/faceapi/interfaces.go +++ b/services/cognitiveservices/v1.0/face/faceapi/interfaces.go @@ -128,3 +128,16 @@ type LargeFaceListClientAPI interface { } var _ LargeFaceListClientAPI = (*face.LargeFaceListClient)(nil) + +// SnapshotClientAPI contains the set of methods on the SnapshotClient type. +type SnapshotClientAPI interface { + Apply(ctx context.Context, snapshotID uuid.UUID, body face.ApplySnapshotRequest) (result autorest.Response, err error) + Delete(ctx context.Context, snapshotID uuid.UUID) (result autorest.Response, err error) + Get(ctx context.Context, snapshotID uuid.UUID) (result face.Snapshot, err error) + GetOperationStatus(ctx context.Context, operationID uuid.UUID) (result face.OperationStatus, err error) + List(ctx context.Context, typeParameter face.SnapshotObjectType, applyScope []uuid.UUID) (result face.ListSnapshot, err error) + Take(ctx context.Context, body face.TakeSnapshotRequest) (result autorest.Response, err error) + Update(ctx context.Context, snapshotID uuid.UUID, body face.UpdateSnapshotRequest) (result autorest.Response, err error) +} + +var _ SnapshotClientAPI = (*face.SnapshotClient)(nil) diff --git a/services/cognitiveservices/v1.0/face/models.go b/services/cognitiveservices/v1.0/face/models.go index a6398fb02707..4323f616fe7a 100644 --- a/services/cognitiveservices/v1.0/face/models.go +++ b/services/cognitiveservices/v1.0/face/models.go @@ -211,23 +211,74 @@ func PossibleNoiseLevelValues() []NoiseLevel { return []NoiseLevel{NoiseLevelHigh, NoiseLevelLow, NoiseLevelMedium} } -// TrainingStatusType enumerates the values for training status type. -type TrainingStatusType string +// OperationStatusType enumerates the values for operation status type. +type OperationStatusType string const ( // Failed ... - Failed TrainingStatusType = "failed" - // Nonstarted ... - Nonstarted TrainingStatusType = "nonstarted" + Failed OperationStatusType = "failed" + // Notstarted ... + Notstarted OperationStatusType = "notstarted" // Running ... - Running TrainingStatusType = "running" + Running OperationStatusType = "running" // Succeeded ... - Succeeded TrainingStatusType = "succeeded" + Succeeded OperationStatusType = "succeeded" +) + +// PossibleOperationStatusTypeValues returns an array of possible values for the OperationStatusType const type. +func PossibleOperationStatusTypeValues() []OperationStatusType { + return []OperationStatusType{Failed, Notstarted, Running, Succeeded} +} + +// SnapshotApplyMode enumerates the values for snapshot apply mode. +type SnapshotApplyMode string + +const ( + // CreateNew ... + CreateNew SnapshotApplyMode = "CreateNew" +) + +// PossibleSnapshotApplyModeValues returns an array of possible values for the SnapshotApplyMode const type. +func PossibleSnapshotApplyModeValues() []SnapshotApplyMode { + return []SnapshotApplyMode{CreateNew} +} + +// SnapshotObjectType enumerates the values for snapshot object type. +type SnapshotObjectType string + +const ( + // SnapshotObjectTypeFaceList ... + SnapshotObjectTypeFaceList SnapshotObjectType = "FaceList" + // SnapshotObjectTypeLargeFaceList ... + SnapshotObjectTypeLargeFaceList SnapshotObjectType = "LargeFaceList" + // SnapshotObjectTypeLargePersonGroup ... + SnapshotObjectTypeLargePersonGroup SnapshotObjectType = "LargePersonGroup" + // SnapshotObjectTypePersonGroup ... + SnapshotObjectTypePersonGroup SnapshotObjectType = "PersonGroup" +) + +// PossibleSnapshotObjectTypeValues returns an array of possible values for the SnapshotObjectType const type. +func PossibleSnapshotObjectTypeValues() []SnapshotObjectType { + return []SnapshotObjectType{SnapshotObjectTypeFaceList, SnapshotObjectTypeLargeFaceList, SnapshotObjectTypeLargePersonGroup, SnapshotObjectTypePersonGroup} +} + +// TrainingStatusType enumerates the values for training status type. +type TrainingStatusType string + +const ( + // TrainingStatusTypeFailed ... + TrainingStatusTypeFailed TrainingStatusType = "failed" + // TrainingStatusTypeNonstarted ... + TrainingStatusTypeNonstarted TrainingStatusType = "nonstarted" + // TrainingStatusTypeRunning ... + TrainingStatusTypeRunning TrainingStatusType = "running" + // TrainingStatusTypeSucceeded ... + TrainingStatusTypeSucceeded TrainingStatusType = "succeeded" ) // PossibleTrainingStatusTypeValues returns an array of possible values for the TrainingStatusType const type. func PossibleTrainingStatusTypeValues() []TrainingStatusType { - return []TrainingStatusType{Failed, Nonstarted, Running, Succeeded} + return []TrainingStatusType{TrainingStatusTypeFailed, TrainingStatusTypeNonstarted, TrainingStatusTypeRunning, TrainingStatusTypeSucceeded} } // Accessory accessory item and corresponding confidence level. @@ -243,6 +294,14 @@ type APIError struct { Error *Error `json:"error,omitempty"` } +// ApplySnapshotRequest request body for applying snapshot operation. +type ApplySnapshotRequest struct { + // ObjectID - User specified target object id to be created from the snapshot. + ObjectID *string `json:"objectId,omitempty"` + // Mode - Snapshot applying mode. Currently only CreateNew is supported, which means the apply operation will fail if target subscription already contains an object of same type and using the same objectId. Users can specify the "objectId" in request body to avoid such conflicts. Possible values include: 'CreateNew' + Mode SnapshotApplyMode `json:"mode,omitempty"` +} + // Attributes face Attributes type Attributes struct { // Age - Age in years @@ -545,6 +604,12 @@ type ListSimilarFace struct { Value *[]SimilarFace `json:"value,omitempty"` } +// ListSnapshot ... +type ListSnapshot struct { + autorest.Response `json:"-"` + Value *[]Snapshot `json:"value,omitempty"` +} + // Makeup properties describing present makeups on a given face. type Makeup struct { // EyeMakeup - A boolean value describing whether eye makeup is present on a face. @@ -580,6 +645,22 @@ type Occlusion struct { MouthOccluded *bool `json:"mouthOccluded,omitempty"` } +// OperationStatus operation status object. Operation refers to the asynchronous backend task including +// taking a snapshot and applying a snapshot. +type OperationStatus struct { + autorest.Response `json:"-"` + // Status - Operation status: notstarted, running, succeeded, failed. If the operation is requested and waiting to perform, the status is notstarted. If the operation is ongoing in backend, the status is running. Status succeeded means the operation is completed successfully, specifically for snapshot taking operation, it illustrates the snapshot is well taken and ready to apply, and for snapshot applying operation, it presents the target object has finished creating by the snapshot and ready to be used. Status failed is often caused by editing the source object while taking the snapshot or editing the target object while applying the snapshot before completion, see the field "message" to check the failure reason. Possible values include: 'Notstarted', 'Running', 'Succeeded', 'Failed' + Status OperationStatusType `json:"status,omitempty"` + // CreatedTime - A combined UTC date and time string that describes the time when the operation (take or apply a snapshot) is requested. E.g. 2018-12-25T11:41:02.2331413Z. + CreatedTime *date.Time `json:"createdTime,omitempty"` + // LastActionTime - A combined UTC date and time string that describes the last time the operation (take or apply a snapshot) is actively migrating data. The lastActionTime will keep increasing until the operation finishes. E.g. 2018-12-25T11:51:27.8705696Z. + LastActionTime *date.Time `json:"lastActionTime,omitempty"` + // ResourceLocation - When the operation succeeds successfully, for snapshot taking operation the snapshot id will be included in this field, and for snapshot applying operation, the path to get the target object will be returned in this field. + ResourceLocation *string `json:"resourceLocation,omitempty"` + // Message - Show failure message when operation fails (omitted when operation succeeds). + Message *string `json:"message,omitempty"` +} + // PersistedFace personFace object. type PersistedFace struct { autorest.Response `json:"-"` @@ -635,10 +716,41 @@ type SimilarFace struct { Confidence *float64 `json:"confidence,omitempty"` } +// Snapshot snapshot object. +type Snapshot struct { + autorest.Response `json:"-"` + // ID - Snapshot id. + ID *uuid.UUID `json:"id,omitempty"` + // Account - Azure Cognitive Service Face account id of the subscriber who created the snapshot by Snapshot - Take. + Account *string `json:"account,omitempty"` + // Type - Type of the source object in the snapshot, specified by the subscriber who created the snapshot when calling Snapshot - Take. Currently FaceList, PersonGroup, LargeFaceList and LargePersonGroup are supported. Possible values include: 'SnapshotObjectTypeFaceList', 'SnapshotObjectTypeLargeFaceList', 'SnapshotObjectTypeLargePersonGroup', 'SnapshotObjectTypePersonGroup' + Type SnapshotObjectType `json:"type,omitempty"` + // ApplyScope - Array of the target Face subscription ids for the snapshot, specified by the user who created the snapshot when calling Snapshot - Take. For each snapshot, only subscriptions included in the applyScope of Snapshot - Take can apply it. + ApplyScope *[]uuid.UUID `json:"applyScope,omitempty"` + // UserData - User specified data about the snapshot for any purpose. Length should not exceed 16KB. + UserData *string `json:"userData,omitempty"` + // CreatedTime - A combined UTC date and time string that describes the created time of the snapshot. E.g. 2018-12-25T11:41:02.2331413Z. + CreatedTime *date.Time `json:"createdTime,omitempty"` + // LastUpdateTime - A combined UTC date and time string that describes the last time when the snapshot was created or updated by Snapshot - Update. E.g. 2018-12-25T11:51:27.8705696Z. + LastUpdateTime *date.Time `json:"lastUpdateTime,omitempty"` +} + +// TakeSnapshotRequest request body for taking snapshot operation. +type TakeSnapshotRequest struct { + // Type - User specified type for the source object to take snapshot from. Currently FaceList, PersonGroup, LargeFaceList and LargePersonGroup are supported. Possible values include: 'SnapshotObjectTypeFaceList', 'SnapshotObjectTypeLargeFaceList', 'SnapshotObjectTypeLargePersonGroup', 'SnapshotObjectTypePersonGroup' + Type SnapshotObjectType `json:"type,omitempty"` + // ObjectID - User specified source object id to take snapshot from. + ObjectID *string `json:"objectId,omitempty"` + // ApplyScope - User specified array of target Face subscription ids for the snapshot. For each snapshot, only subscriptions included in the applyScope of Snapshot - Take can apply it. + ApplyScope *[]uuid.UUID `json:"applyScope,omitempty"` + // UserData - User specified data about the snapshot for any purpose. Length should not exceed 16KB. + UserData *string `json:"userData,omitempty"` +} + // TrainingStatus training status object. type TrainingStatus struct { autorest.Response `json:"-"` - // Status - Training status: notstarted, running, succeeded, failed. If the training process is waiting to perform, the status is notstarted. If the training is ongoing, the status is running. Status succeed means this person group or large person group is ready for Face - Identify, or this large face list is ready for Face - Find Similar. Status failed is often caused by no person or no persisted face exist in the person group or large person group, or no persisted face exist in the large face list. Possible values include: 'Nonstarted', 'Running', 'Succeeded', 'Failed' + // Status - Training status: notstarted, running, succeeded, failed. If the training process is waiting to perform, the status is notstarted. If the training is ongoing, the status is running. Status succeed means this person group or large person group is ready for Face - Identify, or this large face list is ready for Face - Find Similar. Status failed is often caused by no person or no persisted face exist in the person group or large person group, or no persisted face exist in the large face list. Possible values include: 'TrainingStatusTypeNonstarted', 'TrainingStatusTypeRunning', 'TrainingStatusTypeSucceeded', 'TrainingStatusTypeFailed' Status TrainingStatusType `json:"status,omitempty"` // Created - A combined UTC date and time string that describes the created time of the person group, large person group or large face list. Created *date.Time `json:"createdDateTime,omitempty"` @@ -656,6 +768,15 @@ type UpdateFaceRequest struct { UserData *string `json:"userData,omitempty"` } +// UpdateSnapshotRequest request body for updating a snapshot, with a combination of user defined apply +// scope and user specified data. +type UpdateSnapshotRequest struct { + // ApplyScope - Array of the target Face subscription ids for the snapshot, specified by the user who created the snapshot when calling Snapshot - Take. For each snapshot, only subscriptions included in the applyScope of Snapshot - Take can apply it. + ApplyScope *[]uuid.UUID `json:"applyScope,omitempty"` + // UserData - User specified data about the snapshot for any purpose. Length should not exceed 16KB. + UserData *string `json:"userData,omitempty"` +} + // VerifyFaceToFaceRequest request body for face to face verification. type VerifyFaceToFaceRequest struct { // FaceID1 - FaceId of the first face, comes from Face - Detect diff --git a/services/cognitiveservices/v1.0/face/snapshot.go b/services/cognitiveservices/v1.0/face/snapshot.go new file mode 100644 index 000000000000..251ef90883a3 --- /dev/null +++ b/services/cognitiveservices/v1.0/face/snapshot.go @@ -0,0 +1,618 @@ +package face + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "github.com/satori/go.uuid" + "net/http" +) + +// SnapshotClient is the an API for face detection, verification, and identification. +type SnapshotClient struct { + BaseClient +} + +// NewSnapshotClient creates an instance of the SnapshotClient client. +func NewSnapshotClient(endpoint string) SnapshotClient { + return SnapshotClient{New(endpoint)} +} + +// Apply submit an operation to apply a snapshot to current subscription. For each snapshot, only subscriptions +// included in the applyScope of Snapshot - Take can apply it. +// The snapshot interfaces are for users to backup and restore their face data from one face subscription to another, +// inside same region or across regions. The workflow contains two phases, user first calls Snapshot - Take to create a +// copy of the source object and store it as a snapshot, then calls Snapshot - Apply to paste the snapshot to target +// subscription. The snapshots are stored in a centralized location (per Azure instance), so that they can be applied +// cross accounts and regions. +// Applying snapshot is an asynchronous operation. An operation id can be obtained from the "Operation-Location" field +// in response header, to be used in OperationStatus - Get for tracking the progress of applying the snapshot. The +// target object id will be included in the "resourceLocation" field in OperationStatus - Get response when the +// operation status is "succeeded". +// Snapshot applying time depends on the number of person and face entries in the snapshot object. It could be in +// seconds, or up to 1 hour for 1,000,000 persons with multiple faces. +// Snapshots will be automatically expired and cleaned in 48 hours after it is created by Snapshot - Take. So the +// target subscription is required to apply the snapshot in 48 hours since its creation. +// Applying a snapshot will not block any other operations against the target object, however it is not recommended +// because the correctness cannot be guaranteed during snapshot applying. After snapshot applying is completed, all +// operations towards the target object can work as normal. Snapshot also includes the training results of the source +// object, which means target subscription the snapshot applied to does not need re-train the target object before +// calling Identify/FindSimilar. +// One snapshot can be applied multiple times in parallel, while currently only CreateNew apply mode is supported, +// which means the apply operation will fail if target subscription already contains an object of same type and using +// the same objectId. Users can specify the "objectId" in request body to avoid such conflicts. +// Parameters: +// snapshotID - id referencing a particular snapshot. +// body - request body for applying a snapshot. +func (client SnapshotClient) Apply(ctx context.Context, snapshotID uuid.UUID, body ApplySnapshotRequest) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Apply") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ObjectID", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "body.ObjectID", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "body.ObjectID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("face.SnapshotClient", "Apply", err.Error()) + } + + req, err := client.ApplyPreparer(ctx, snapshotID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", nil, "Failure preparing request") + return + } + + resp, err := client.ApplySender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", resp, "Failure sending request") + return + } + + result, err = client.ApplyResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Apply", resp, "Failure responding to request") + } + + return +} + +// ApplyPreparer prepares the Apply request. +func (client SnapshotClient) ApplyPreparer(ctx context.Context, snapshotID uuid.UUID, body ApplySnapshotRequest) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "snapshotId": autorest.Encode("path", snapshotID), + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPathParameters("/snapshots/{snapshotId}/apply", pathParameters), + autorest.WithJSON(body)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ApplySender sends the Apply request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) ApplySender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ApplyResponder handles the response to the Apply request. The method always +// closes the http.Response Body. +func (client SnapshotClient) ApplyResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Delete delete an existing snapshot according to the snapshotId. All object data and information in the snapshot will +// also be deleted. Only the source subscription who took the snapshot can delete the snapshot. If the user does not +// delete a snapshot with this API, the snapshot will still be automatically deleted in 48 hours after creation. +// Parameters: +// snapshotID - id referencing a particular snapshot. +func (client SnapshotClient) Delete(ctx context.Context, snapshotID uuid.UUID) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, snapshotID) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client SnapshotClient) DeletePreparer(ctx context.Context, snapshotID uuid.UUID) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "snapshotId": autorest.Encode("path", snapshotID), + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client SnapshotClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get retrieve information about a snapshot. Snapshot is only accessible to the source subscription who took it, and +// target subscriptions included in the applyScope in Snapshot - Take. +// Parameters: +// snapshotID - id referencing a particular snapshot. +func (client SnapshotClient) Get(ctx context.Context, snapshotID uuid.UUID) (result Snapshot, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx, snapshotID) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client SnapshotClient) GetPreparer(ctx context.Context, snapshotID uuid.UUID) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "snapshotId": autorest.Encode("path", snapshotID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client SnapshotClient) GetResponder(resp *http.Response) (result Snapshot, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetOperationStatus retrieve the status of a take/apply snapshot operation. +// Parameters: +// operationID - id referencing a particular take/apply snapshot operation. +func (client SnapshotClient) GetOperationStatus(ctx context.Context, operationID uuid.UUID) (result OperationStatus, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.GetOperationStatus") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetOperationStatusPreparer(ctx, operationID) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", nil, "Failure preparing request") + return + } + + resp, err := client.GetOperationStatusSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", resp, "Failure sending request") + return + } + + result, err = client.GetOperationStatusResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "GetOperationStatus", resp, "Failure responding to request") + } + + return +} + +// GetOperationStatusPreparer prepares the GetOperationStatus request. +func (client SnapshotClient) GetOperationStatusPreparer(ctx context.Context, operationID uuid.UUID) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "operationId": autorest.Encode("path", operationID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPathParameters("/operations/{operationId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetOperationStatusSender sends the GetOperationStatus request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) GetOperationStatusSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetOperationStatusResponder handles the response to the GetOperationStatus request. The method always +// closes the http.Response Body. +func (client SnapshotClient) GetOperationStatusResponder(resp *http.Response) (result OperationStatus, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List list all accessible snapshots with related information, including snapshots that were taken by the user, or +// snapshots to be applied to the user (subscription id was included in the applyScope in Snapshot - Take). +// Parameters: +// typeParameter - user specified object type as a search filter. +// applyScope - user specified snapshot apply scopes as a search filter. ApplyScope is an array of the target +// Azure subscription ids for the snapshot, specified by the user who created the snapshot by Snapshot - Take. +func (client SnapshotClient) List(ctx context.Context, typeParameter SnapshotObjectType, applyScope []uuid.UUID) (result ListSnapshot, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.List") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListPreparer(ctx, typeParameter, applyScope) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client SnapshotClient) ListPreparer(ctx context.Context, typeParameter SnapshotObjectType, applyScope []uuid.UUID) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + queryParameters := map[string]interface{}{} + if len(string(typeParameter)) > 0 { + queryParameters["type"] = autorest.Encode("query", typeParameter) + } + if applyScope != nil && len(applyScope) > 0 { + queryParameters["applyScope"] = autorest.Encode("query", applyScope, ",") + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPath("/snapshots"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client SnapshotClient) ListResponder(resp *http.Response) (result ListSnapshot, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Value), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Take submit an operation to take a snapshot of face list, large face list, person group or large person group, with +// user-specified snapshot type, source object id, apply scope and an optional user data. +// The snapshot interfaces are for users to backup and restore their face data from one face subscription to another, +// inside same region or across regions. The workflow contains two phases, user first calls Snapshot - Take to create a +// copy of the source object and store it as a snapshot, then calls Snapshot - Apply to paste the snapshot to target +// subscription. The snapshots are stored in a centralized location (per Azure instance), so that they can be applied +// cross accounts and regions. +// Taking snapshot is an asynchronous operation. An operation id can be obtained from the "Operation-Location" field in +// response header, to be used in OperationStatus - Get for tracking the progress of creating the snapshot. The +// snapshot id will be included in the "resourceLocation" field in OperationStatus - Get response when the operation +// status is "succeeded". +// Snapshot taking time depends on the number of person and face entries in the source object. It could be in seconds, +// or up to several hours for 1,000,000 persons with multiple faces. +// Snapshots will be automatically expired and cleaned in 48 hours after it is created by Snapshot - Take. User can +// delete the snapshot using Snapshot - Delete by themselves any time before expiration. +// Taking snapshot for a certain object will not block any other operations against the object. All read-only +// operations (Get/List and Identify/FindSimilar/Verify) can be conducted as usual. For all writable operations, +// including Add/Update/Delete the source object or its persons/faces and Train, they are not blocked but not +// recommended because writable updates may not be reflected on the snapshot during its taking. After snapshot taking +// is completed, all readable and writable operations can work as normal. Snapshot will also include the training +// results of the source object, which means target subscription the snapshot applied to does not need re-train the +// target object before calling Identify/FindSimilar. +// Parameters: +// body - request body for taking a snapshot. +func (client SnapshotClient) Take(ctx context.Context, body TakeSnapshotRequest) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Take") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: body, + Constraints: []validation.Constraint{{Target: "body.ObjectID", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "body.ObjectID", Name: validation.MaxLength, Rule: 64, Chain: nil}, + {Target: "body.ObjectID", Name: validation.Pattern, Rule: `^[a-z0-9-_]+$`, Chain: nil}, + }}, + {Target: "body.ApplyScope", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "body.UserData", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "body.UserData", Name: validation.MaxLength, Rule: 16384, Chain: nil}}}}}}); err != nil { + return result, validation.NewError("face.SnapshotClient", "Take", err.Error()) + } + + req, err := client.TakePreparer(ctx, body) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", nil, "Failure preparing request") + return + } + + resp, err := client.TakeSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", resp, "Failure sending request") + return + } + + result, err = client.TakeResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Take", resp, "Failure responding to request") + } + + return +} + +// TakePreparer prepares the Take request. +func (client SnapshotClient) TakePreparer(ctx context.Context, body TakeSnapshotRequest) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPath("/snapshots"), + autorest.WithJSON(body)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// TakeSender sends the Take request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) TakeSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// TakeResponder handles the response to the Take request. The method always +// closes the http.Response Body. +func (client SnapshotClient) TakeResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update update the information of a snapshot. Only the source subscription who took the snapshot can update the +// snapshot. +// Parameters: +// snapshotID - id referencing a particular snapshot. +// body - request body for updating a snapshot. +func (client SnapshotClient) Update(ctx context.Context, snapshotID uuid.UUID, body UpdateSnapshotRequest) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotClient.Update") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, snapshotID, body) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "face.SnapshotClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client SnapshotClient) UpdatePreparer(ctx context.Context, snapshotID uuid.UUID, body UpdateSnapshotRequest) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "snapshotId": autorest.Encode("path", snapshotID), + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("{Endpoint}/face/v1.0", urlParameters), + autorest.WithPathParameters("/snapshots/{snapshotId}", pathParameters), + autorest.WithJSON(body)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client SnapshotClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client SnapshotClient) UpdateResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +}