diff --git a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/__init__.py b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/__init__.py index dd78bfef8aab..9500726cdd23 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/__init__.py +++ b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/__init__.py @@ -12,6 +12,10 @@ try: from ._models_py3 import AnalyzeOperationResult from ._models_py3 import AnalyzeResult + from ._models_py3 import CopyAuthorizationResult + from ._models_py3 import CopyOperationResult + from ._models_py3 import CopyRequest + from ._models_py3 import CopyResult from ._models_py3 import DataTable from ._models_py3 import DataTableCell from ._models_py3 import DocumentResult @@ -38,6 +42,10 @@ except (SyntaxError, ImportError): from ._models import AnalyzeOperationResult from ._models import AnalyzeResult + from ._models import CopyAuthorizationResult + from ._models import CopyOperationResult + from ._models import CopyRequest + from ._models import CopyResult from ._models import DataTable from ._models import DataTableCell from ._models import DocumentResult @@ -73,6 +81,10 @@ __all__ = [ 'AnalyzeOperationResult', 'AnalyzeResult', + 'CopyAuthorizationResult', + 'CopyOperationResult', + 'CopyRequest', + 'CopyResult', 'DataTable', 'DataTableCell', 'DocumentResult', diff --git a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models.py b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models.py index 3cbfba51f004..1b806764c717 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models.py +++ b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models.py @@ -98,6 +98,145 @@ def __init__(self, **kwargs): self.errors = kwargs.get('errors', None) +class CopyAuthorizationResult(Model): + """Request parameter that contains authorization claims for copy operation. + + All required parameters must be populated in order to send to Azure. + + :param model_id: Required. Model identifier. + :type model_id: str + :param access_token: Required. Token claim used to authorize the request. + :type access_token: str + :param expiration_date_time_ticks: Required. The time when the access + token expires. The date is represented as the number of seconds from + 1970-01-01T0:0:0Z UTC until the expiration time. + :type expiration_date_time_ticks: long + """ + + _validation = { + 'model_id': {'required': True}, + 'access_token': {'required': True}, + 'expiration_date_time_ticks': {'required': True}, + } + + _attribute_map = { + 'model_id': {'key': 'modelId', 'type': 'str'}, + 'access_token': {'key': 'accessToken', 'type': 'str'}, + 'expiration_date_time_ticks': {'key': 'expirationDateTimeTicks', 'type': 'long'}, + } + + def __init__(self, **kwargs): + super(CopyAuthorizationResult, self).__init__(**kwargs) + self.model_id = kwargs.get('model_id', None) + self.access_token = kwargs.get('access_token', None) + self.expiration_date_time_ticks = kwargs.get('expiration_date_time_ticks', None) + + +class CopyOperationResult(Model): + """Status and result of the queued copy operation. + + All required parameters must be populated in order to send to Azure. + + :param status: Required. Operation status. Possible values include: + 'notStarted', 'running', 'succeeded', 'failed' + :type status: str or + ~azure.cognitiveservices.formrecognizer.models.OperationStatus + :param created_date_time: Required. Date and time (UTC) when the copy + operation was submitted. + :type created_date_time: datetime + :param last_updated_date_time: Required. Date and time (UTC) when the + status was last updated. + :type last_updated_date_time: datetime + :param copy_result: Results of the copy operation. + :type copy_result: + ~azure.cognitiveservices.formrecognizer.models.CopyResult + """ + + _validation = { + 'status': {'required': True}, + 'created_date_time': {'required': True}, + 'last_updated_date_time': {'required': True}, + } + + _attribute_map = { + 'status': {'key': 'status', 'type': 'OperationStatus'}, + 'created_date_time': {'key': 'createdDateTime', 'type': 'iso-8601'}, + 'last_updated_date_time': {'key': 'lastUpdatedDateTime', 'type': 'iso-8601'}, + 'copy_result': {'key': 'copyResult', 'type': 'CopyResult'}, + } + + def __init__(self, **kwargs): + super(CopyOperationResult, self).__init__(**kwargs) + self.status = kwargs.get('status', None) + self.created_date_time = kwargs.get('created_date_time', None) + self.last_updated_date_time = kwargs.get('last_updated_date_time', None) + self.copy_result = kwargs.get('copy_result', None) + + +class CopyRequest(Model): + """Request parameter to copy an existing custom model from the source resource + to a target resource referenced by the resource ID. + + All required parameters must be populated in order to send to Azure. + + :param target_resource_id: Required. Azure Resource Id of the target Form + Recognizer resource where the model is copied to. + :type target_resource_id: str + :param target_resource_region: Required. Location of the target Azure + resource. A valid Azure region name supported by Cognitive Services. + :type target_resource_region: str + :param copy_authorization: Required. Entity that encodes claims to + authorize the copy request. + :type copy_authorization: + ~azure.cognitiveservices.formrecognizer.models.CopyAuthorizationResult + """ + + _validation = { + 'target_resource_id': {'required': True, 'max_length': 1024, 'pattern': r'^/subscriptions/[^/]*/resourceGroups/[^/]*/providers/Microsoft.CognitiveServices/accounts/[^/]*$'}, + 'target_resource_region': {'required': True, 'max_length': 24, 'min_length': 1, 'pattern': r'^[a-z0-9]+$'}, + 'copy_authorization': {'required': True}, + } + + _attribute_map = { + 'target_resource_id': {'key': 'targetResourceId', 'type': 'str'}, + 'target_resource_region': {'key': 'targetResourceRegion', 'type': 'str'}, + 'copy_authorization': {'key': 'copyAuthorization', 'type': 'CopyAuthorizationResult'}, + } + + def __init__(self, **kwargs): + super(CopyRequest, self).__init__(**kwargs) + self.target_resource_id = kwargs.get('target_resource_id', None) + self.target_resource_region = kwargs.get('target_resource_region', None) + self.copy_authorization = kwargs.get('copy_authorization', None) + + +class CopyResult(Model): + """Custom model copy result. + + All required parameters must be populated in order to send to Azure. + + :param model_id: Required. Identifier of the target model. + :type model_id: str + :param errors: Errors returned during the copy operation. + :type errors: + list[~azure.cognitiveservices.formrecognizer.models.ErrorInformation] + """ + + _validation = { + 'model_id': {'required': True}, + } + + _attribute_map = { + 'model_id': {'key': 'modelId', 'type': 'str'}, + 'errors': {'key': 'errors', 'type': '[ErrorInformation]'}, + } + + def __init__(self, **kwargs): + super(CopyResult, self).__init__(**kwargs) + self.model_id = kwargs.get('model_id', None) + self.errors = kwargs.get('errors', None) + + class DataTable(Model): """Information about the extracted table contained in a page. diff --git a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models_py3.py b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models_py3.py index be49b44f0f58..63e4da25aa7a 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models_py3.py +++ b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/models/_models_py3.py @@ -98,6 +98,145 @@ def __init__(self, *, version: str, read_results, page_results=None, document_re self.errors = errors +class CopyAuthorizationResult(Model): + """Request parameter that contains authorization claims for copy operation. + + All required parameters must be populated in order to send to Azure. + + :param model_id: Required. Model identifier. + :type model_id: str + :param access_token: Required. Token claim used to authorize the request. + :type access_token: str + :param expiration_date_time_ticks: Required. The time when the access + token expires. The date is represented as the number of seconds from + 1970-01-01T0:0:0Z UTC until the expiration time. + :type expiration_date_time_ticks: long + """ + + _validation = { + 'model_id': {'required': True}, + 'access_token': {'required': True}, + 'expiration_date_time_ticks': {'required': True}, + } + + _attribute_map = { + 'model_id': {'key': 'modelId', 'type': 'str'}, + 'access_token': {'key': 'accessToken', 'type': 'str'}, + 'expiration_date_time_ticks': {'key': 'expirationDateTimeTicks', 'type': 'long'}, + } + + def __init__(self, *, model_id: str, access_token: str, expiration_date_time_ticks: int, **kwargs) -> None: + super(CopyAuthorizationResult, self).__init__(**kwargs) + self.model_id = model_id + self.access_token = access_token + self.expiration_date_time_ticks = expiration_date_time_ticks + + +class CopyOperationResult(Model): + """Status and result of the queued copy operation. + + All required parameters must be populated in order to send to Azure. + + :param status: Required. Operation status. Possible values include: + 'notStarted', 'running', 'succeeded', 'failed' + :type status: str or + ~azure.cognitiveservices.formrecognizer.models.OperationStatus + :param created_date_time: Required. Date and time (UTC) when the copy + operation was submitted. + :type created_date_time: datetime + :param last_updated_date_time: Required. Date and time (UTC) when the + status was last updated. + :type last_updated_date_time: datetime + :param copy_result: Results of the copy operation. + :type copy_result: + ~azure.cognitiveservices.formrecognizer.models.CopyResult + """ + + _validation = { + 'status': {'required': True}, + 'created_date_time': {'required': True}, + 'last_updated_date_time': {'required': True}, + } + + _attribute_map = { + 'status': {'key': 'status', 'type': 'OperationStatus'}, + 'created_date_time': {'key': 'createdDateTime', 'type': 'iso-8601'}, + 'last_updated_date_time': {'key': 'lastUpdatedDateTime', 'type': 'iso-8601'}, + 'copy_result': {'key': 'copyResult', 'type': 'CopyResult'}, + } + + def __init__(self, *, status, created_date_time, last_updated_date_time, copy_result=None, **kwargs) -> None: + super(CopyOperationResult, self).__init__(**kwargs) + self.status = status + self.created_date_time = created_date_time + self.last_updated_date_time = last_updated_date_time + self.copy_result = copy_result + + +class CopyRequest(Model): + """Request parameter to copy an existing custom model from the source resource + to a target resource referenced by the resource ID. + + All required parameters must be populated in order to send to Azure. + + :param target_resource_id: Required. Azure Resource Id of the target Form + Recognizer resource where the model is copied to. + :type target_resource_id: str + :param target_resource_region: Required. Location of the target Azure + resource. A valid Azure region name supported by Cognitive Services. + :type target_resource_region: str + :param copy_authorization: Required. Entity that encodes claims to + authorize the copy request. + :type copy_authorization: + ~azure.cognitiveservices.formrecognizer.models.CopyAuthorizationResult + """ + + _validation = { + 'target_resource_id': {'required': True, 'max_length': 1024, 'pattern': r'^/subscriptions/[^/]*/resourceGroups/[^/]*/providers/Microsoft.CognitiveServices/accounts/[^/]*$'}, + 'target_resource_region': {'required': True, 'max_length': 24, 'min_length': 1, 'pattern': r'^[a-z0-9]+$'}, + 'copy_authorization': {'required': True}, + } + + _attribute_map = { + 'target_resource_id': {'key': 'targetResourceId', 'type': 'str'}, + 'target_resource_region': {'key': 'targetResourceRegion', 'type': 'str'}, + 'copy_authorization': {'key': 'copyAuthorization', 'type': 'CopyAuthorizationResult'}, + } + + def __init__(self, *, target_resource_id: str, target_resource_region: str, copy_authorization, **kwargs) -> None: + super(CopyRequest, self).__init__(**kwargs) + self.target_resource_id = target_resource_id + self.target_resource_region = target_resource_region + self.copy_authorization = copy_authorization + + +class CopyResult(Model): + """Custom model copy result. + + All required parameters must be populated in order to send to Azure. + + :param model_id: Required. Identifier of the target model. + :type model_id: str + :param errors: Errors returned during the copy operation. + :type errors: + list[~azure.cognitiveservices.formrecognizer.models.ErrorInformation] + """ + + _validation = { + 'model_id': {'required': True}, + } + + _attribute_map = { + 'model_id': {'key': 'modelId', 'type': 'str'}, + 'errors': {'key': 'errors', 'type': '[ErrorInformation]'}, + } + + def __init__(self, *, model_id: str, errors=None, **kwargs) -> None: + super(CopyResult, self).__init__(**kwargs) + self.model_id = model_id + self.errors = errors + + class DataTable(Model): """Information about the extracted table contained in a page. diff --git a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/operations/_form_recognizer_client_operations.py b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/operations/_form_recognizer_client_operations.py index b574e05b0cd8..125d3d7c5312 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/operations/_form_recognizer_client_operations.py +++ b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/azure/cognitiveservices/formrecognizer/operations/_form_recognizer_client_operations.py @@ -314,6 +314,179 @@ def get_analyze_form_result( return deserialized get_analyze_form_result.metadata = {'url': '/custom/models/{modelId}/analyzeResults/{resultId}'} + def copy_custom_model( + self, model_id, copy_request, custom_headers=None, raw=False, **operation_config): + """Copy Custom Model. + + Copy custom model stored in this resource (the source) to user + specified target Form Recognizer resource. + + :param model_id: Model identifier. + :type model_id: str + :param copy_request: Copy request parameters. + :type copy_request: + ~azure.cognitiveservices.formrecognizer.models.CopyRequest + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: None or ClientRawResponse if raw=true + :rtype: None or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.copy_custom_model.metadata['url'] + path_format_arguments = { + 'endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), + 'modelId': self._serialize.url("model_id", model_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if custom_headers: + header_parameters.update(custom_headers) + + # Construct body + body_content = self._serialize.body(copy_request, 'CopyRequest') + + # Construct and send request + request = self._client.post(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [202]: + raise models.ErrorResponseException(self._deserialize, response) + + if raw: + client_raw_response = ClientRawResponse(None, response) + client_raw_response.add_headers({ + 'Operation-Location': 'str', + }) + return client_raw_response + copy_custom_model.metadata = {'url': '/custom/models/{modelId}/copy'} + + def get_custom_model_copy_result( + self, model_id, result_id, custom_headers=None, raw=False, **operation_config): + """Get Custom Model Copy Result. + + Obtain current status and the result of a custom model copy operation. + + :param model_id: Model identifier. + :type model_id: str + :param result_id: Copy operation result identifier. + :type result_id: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: CopyOperationResult or ClientRawResponse if raw=true + :rtype: + ~azure.cognitiveservices.formrecognizer.models.CopyOperationResult or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.get_custom_model_copy_result.metadata['url'] + path_format_arguments = { + 'endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True), + 'modelId': self._serialize.url("model_id", model_id, 'str'), + 'resultId': self._serialize.url("result_id", result_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if custom_headers: + header_parameters.update(custom_headers) + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ErrorResponseException(self._deserialize, response) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('CopyOperationResult', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + get_custom_model_copy_result.metadata = {'url': '/custom/models/{modelId}/copyResults/{resultId}'} + + def generate_model_copy_authorization( + self, custom_headers=None, raw=False, **operation_config): + """Generate Copy Authorization. + + Generate authorization to copy a model into the target Form Recognizer + resource. + + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: CopyAuthorizationResult or ClientRawResponse if raw=true + :rtype: + ~azure.cognitiveservices.formrecognizer.models.CopyAuthorizationResult + or ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.generate_model_copy_authorization.metadata['url'] + path_format_arguments = { + 'endpoint': self._serialize.url("self.config.endpoint", self.config.endpoint, 'str', skip_quote=True) + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + if custom_headers: + header_parameters.update(custom_headers) + + # Construct and send request + request = self._client.post(url, query_parameters, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [201]: + raise models.ErrorResponseException(self._deserialize, response) + + header_dict = {} + deserialized = None + if response.status_code == 201: + deserialized = self._deserialize('CopyAuthorizationResult', response) + header_dict = { + 'Location': 'str', + } + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + client_raw_response.add_headers(header_dict) + return client_raw_response + + return deserialized + generate_model_copy_authorization.metadata = {'url': '/custom/models/copyAuthorization'} + def analyze_receipt_async( self, include_text_details=False, source=None, custom_headers=None, raw=False, **operation_config): """Analyze Receipt. diff --git a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/setup.py b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/setup.py index 0b5143a234ba..99186215d297 100644 --- a/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/setup.py +++ b/sdk/cognitiveservices/azure-cognitiveservices-formrecognizer/setup.py @@ -36,7 +36,9 @@ pass # Version extraction inspired from 'requests' -with open(os.path.join(package_folder_path, 'version.py'), 'r') as fd: +with open(os.path.join(package_folder_path, 'version.py') + if os.path.exists(os.path.join(package_folder_path, 'version.py')) + else os.path.join(package_folder_path, '_version.py'), 'r') as fd: version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1)