restpki-ng-python-client 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- restpki_ng_python_client/__init__.py +200 -0
- restpki_ng_python_client/api/__init__.py +17 -0
- restpki_ng_python_client/api/authentication_api.py +2041 -0
- restpki_ng_python_client/api/cades_signature_api.py +2376 -0
- restpki_ng_python_client/api/document_keys_api.py +1199 -0
- restpki_ng_python_client/api/documents_api.py +868 -0
- restpki_ng_python_client/api/pades_signature_api.py +1797 -0
- restpki_ng_python_client/api/pades_visual_positioning_presets_api.py +869 -0
- restpki_ng_python_client/api/pdf_api.py +334 -0
- restpki_ng_python_client/api/signature_api.py +624 -0
- restpki_ng_python_client/api/signature_inspection_api.py +337 -0
- restpki_ng_python_client/api/signature_sessions_api.py +891 -0
- restpki_ng_python_client/api/timestamp_api.py +654 -0
- restpki_ng_python_client/api/upload_api.py +1124 -0
- restpki_ng_python_client/api/xml_signature_api.py +1781 -0
- restpki_ng_python_client/api_client.py +741 -0
- restpki_ng_python_client/api_response.py +21 -0
- restpki_ng_python_client/configuration.py +426 -0
- restpki_ng_python_client/exceptions.py +166 -0
- restpki_ng_python_client/file_utils.py +122 -0
- restpki_ng_python_client/models/__init__.py +165 -0
- restpki_ng_python_client/models/allocate_document_key_batch_request.py +96 -0
- restpki_ng_python_client/models/allocate_document_key_request.py +93 -0
- restpki_ng_python_client/models/attribute_certificate_model.py +141 -0
- restpki_ng_python_client/models/audit_package_options.py +90 -0
- restpki_ng_python_client/models/authentication_failures.py +45 -0
- restpki_ng_python_client/models/authentication_get_response.py +92 -0
- restpki_ng_python_client/models/authentication_post_request.py +116 -0
- restpki_ng_python_client/models/authentication_post_response.py +98 -0
- restpki_ng_python_client/models/authentications_post_request.py +95 -0
- restpki_ng_python_client/models/authentications_post_response.py +114 -0
- restpki_ng_python_client/models/authentications_post_signed_bytes_request.py +99 -0
- restpki_ng_python_client/models/authentications_post_signed_bytes_response.py +98 -0
- restpki_ng_python_client/models/auto_positioning_horizontal_directions.py +45 -0
- restpki_ng_python_client/models/auto_positioning_vertical_directions.py +45 -0
- restpki_ng_python_client/models/blockchains.py +45 -0
- restpki_ng_python_client/models/cades_signature_model.py +123 -0
- restpki_ng_python_client/models/cades_signature_post_request_v1.py +137 -0
- restpki_ng_python_client/models/cades_signature_post_request_v2.py +152 -0
- restpki_ng_python_client/models/cades_signature_post_request_v3.py +149 -0
- restpki_ng_python_client/models/cades_signature_post_response.py +120 -0
- restpki_ng_python_client/models/cades_signature_post_signed_bytes_request.py +92 -0
- restpki_ng_python_client/models/cades_signature_post_signed_bytes_response.py +106 -0
- restpki_ng_python_client/models/cades_signer_model.py +159 -0
- restpki_ng_python_client/models/cades_timestamp_model.py +140 -0
- restpki_ng_python_client/models/certificate_model.py +197 -0
- restpki_ng_python_client/models/certificate_reference_model.py +99 -0
- restpki_ng_python_client/models/certificate_requirement.py +95 -0
- restpki_ng_python_client/models/certificate_requirement_types.py +45 -0
- restpki_ng_python_client/models/certificate_summary.py +142 -0
- restpki_ng_python_client/models/certified_attribute_model.py +94 -0
- restpki_ng_python_client/models/certified_attribute_types.py +44 -0
- restpki_ng_python_client/models/cms_content_types.py +50 -0
- restpki_ng_python_client/models/cms_signature_options.py +109 -0
- restpki_ng_python_client/models/color_model.py +98 -0
- restpki_ng_python_client/models/commitment_type_model.py +99 -0
- restpki_ng_python_client/models/complete_authentication_request.py +93 -0
- restpki_ng_python_client/models/complete_authentication_response.py +103 -0
- restpki_ng_python_client/models/complete_signature_request.py +95 -0
- restpki_ng_python_client/models/complete_signature_request_v2.py +91 -0
- restpki_ng_python_client/models/create_signature_session_request.py +161 -0
- restpki_ng_python_client/models/create_signature_session_response.py +95 -0
- restpki_ng_python_client/models/digest_algorithm_and_value_model.py +103 -0
- restpki_ng_python_client/models/digest_algorithms.py +49 -0
- restpki_ng_python_client/models/document_file_model.py +137 -0
- restpki_ng_python_client/models/document_key_model.py +100 -0
- restpki_ng_python_client/models/document_key_query_response.py +110 -0
- restpki_ng_python_client/models/document_key_summary.py +100 -0
- restpki_ng_python_client/models/document_model.py +150 -0
- restpki_ng_python_client/models/document_query_response.py +93 -0
- restpki_ng_python_client/models/document_status.py +47 -0
- restpki_ng_python_client/models/document_summary.py +128 -0
- restpki_ng_python_client/models/error_model_v2.py +120 -0
- restpki_ng_python_client/models/file_model.py +114 -0
- restpki_ng_python_client/models/file_reference_model.py +137 -0
- restpki_ng_python_client/models/full_xml_signature_post_request.py +136 -0
- restpki_ng_python_client/models/general_name_choices.py +52 -0
- restpki_ng_python_client/models/general_name_model.py +108 -0
- restpki_ng_python_client/models/holder_types.py +45 -0
- restpki_ng_python_client/models/inspect_signature_failures.py +44 -0
- restpki_ng_python_client/models/inspect_signature_request.py +127 -0
- restpki_ng_python_client/models/inspect_signature_response.py +131 -0
- restpki_ng_python_client/models/multipart_upload_begin_response.py +95 -0
- restpki_ng_python_client/models/multipart_upload_end_request.py +95 -0
- restpki_ng_python_client/models/name_model.py +205 -0
- restpki_ng_python_client/models/namespace_model.py +99 -0
- restpki_ng_python_client/models/open_cades_signature_request_model.py +147 -0
- restpki_ng_python_client/models/open_signature_request_model.py +145 -0
- restpki_ng_python_client/models/open_xml_signature_request_model.py +151 -0
- restpki_ng_python_client/models/other_name_model.py +107 -0
- restpki_ng_python_client/models/pades_certification_level.py +47 -0
- restpki_ng_python_client/models/pades_horizontal_align.py +46 -0
- restpki_ng_python_client/models/pades_measurement_units.py +45 -0
- restpki_ng_python_client/models/pades_page_optimization_model.py +98 -0
- restpki_ng_python_client/models/pades_signature_model.py +113 -0
- restpki_ng_python_client/models/pades_signature_post_request_v1.py +167 -0
- restpki_ng_python_client/models/pades_signature_post_request_v2.py +171 -0
- restpki_ng_python_client/models/pades_signature_post_response.py +120 -0
- restpki_ng_python_client/models/pades_signature_post_signed_bytes_request.py +92 -0
- restpki_ng_python_client/models/pades_signature_post_signed_bytes_response.py +106 -0
- restpki_ng_python_client/models/pades_signer_model.py +168 -0
- restpki_ng_python_client/models/pades_size_model.py +89 -0
- restpki_ng_python_client/models/pades_text_horizontal_align.py +45 -0
- restpki_ng_python_client/models/pades_vertical_align.py +46 -0
- restpki_ng_python_client/models/pades_visual_auto_positioning_model.py +106 -0
- restpki_ng_python_client/models/pades_visual_image_model.py +105 -0
- restpki_ng_python_client/models/pades_visual_positioning_model.py +109 -0
- restpki_ng_python_client/models/pades_visual_rectangle_model.py +127 -0
- restpki_ng_python_client/models/pades_visual_representation_model.py +103 -0
- restpki_ng_python_client/models/pades_visual_text_model.py +111 -0
- restpki_ng_python_client/models/page_orientations.py +46 -0
- restpki_ng_python_client/models/paper_sizes.py +56 -0
- restpki_ng_python_client/models/pdf_add_marks_request.py +117 -0
- restpki_ng_python_client/models/pdf_add_marks_response.py +91 -0
- restpki_ng_python_client/models/pdf_container_definition.py +208 -0
- restpki_ng_python_client/models/pdf_helper.py +43 -0
- restpki_ng_python_client/models/pdf_mark_element_model.py +230 -0
- restpki_ng_python_client/models/pdf_mark_element_type.py +46 -0
- restpki_ng_python_client/models/pdf_mark_image_model.py +98 -0
- restpki_ng_python_client/models/pdf_mark_model.py +168 -0
- restpki_ng_python_client/models/pdf_mark_page_options.py +47 -0
- restpki_ng_python_client/models/pdf_signature_options.py +101 -0
- restpki_ng_python_client/models/pdf_text_section_model.py +125 -0
- restpki_ng_python_client/models/pdf_text_style.py +46 -0
- restpki_ng_python_client/models/pki_brazil_certificate_model.py +159 -0
- restpki_ng_python_client/models/pki_brazil_certificate_types.py +54 -0
- restpki_ng_python_client/models/pki_italy_certificate_model.py +103 -0
- restpki_ng_python_client/models/pki_italy_certificate_types.py +46 -0
- restpki_ng_python_client/models/prepare_authentication_request.py +100 -0
- restpki_ng_python_client/models/prepare_authentication_response.py +99 -0
- restpki_ng_python_client/models/prepare_signature_failures.py +46 -0
- restpki_ng_python_client/models/prepare_signature_request.py +133 -0
- restpki_ng_python_client/models/prepare_signature_response.py +116 -0
- restpki_ng_python_client/models/resource_content_or_reference.py +107 -0
- restpki_ng_python_client/models/role_attribute_model.py +114 -0
- restpki_ng_python_client/models/session_completion_status.py +89 -0
- restpki_ng_python_client/models/signature_algorithm_and_value_model.py +106 -0
- restpki_ng_python_client/models/signature_algorithm_identifier.py +88 -0
- restpki_ng_python_client/models/signature_algorithms.py +48 -0
- restpki_ng_python_client/models/signature_b_stamp_model.py +135 -0
- restpki_ng_python_client/models/signature_policy_identifier_model.py +105 -0
- restpki_ng_python_client/models/signature_result_model.py +105 -0
- restpki_ng_python_client/models/signature_session_document_data.py +128 -0
- restpki_ng_python_client/models/signature_session_document_summary.py +138 -0
- restpki_ng_python_client/models/signature_session_model.py +126 -0
- restpki_ng_python_client/models/signature_session_status.py +49 -0
- restpki_ng_python_client/models/signature_types.py +46 -0
- restpki_ng_python_client/models/signer_b_stamp_model.py +132 -0
- restpki_ng_python_client/models/signer_model.py +187 -0
- restpki_ng_python_client/models/signer_summary.py +94 -0
- restpki_ng_python_client/models/timestamp_issue_response.py +99 -0
- restpki_ng_python_client/models/validation_item_model.py +111 -0
- restpki_ng_python_client/models/validation_item_types.py +91 -0
- restpki_ng_python_client/models/validation_results_model.py +131 -0
- restpki_ng_python_client/models/webhook_event_model.py +94 -0
- restpki_ng_python_client/models/webhook_event_types.py +44 -0
- restpki_ng_python_client/models/xml_attribute_model.py +107 -0
- restpki_ng_python_client/models/xml_element_location_model.py +111 -0
- restpki_ng_python_client/models/xml_element_model.py +115 -0
- restpki_ng_python_client/models/xml_element_signature_post_request.py +145 -0
- restpki_ng_python_client/models/xml_id_attribute_model.py +96 -0
- restpki_ng_python_client/models/xml_id_resolution_table_model.py +123 -0
- restpki_ng_python_client/models/xml_insertion_options.py +47 -0
- restpki_ng_python_client/models/xml_node_name_model.py +96 -0
- restpki_ng_python_client/models/xml_signature_model.py +154 -0
- restpki_ng_python_client/models/xml_signature_options.py +102 -0
- restpki_ng_python_client/models/xml_signature_post_response.py +120 -0
- restpki_ng_python_client/models/xml_signature_post_signed_bytes_request.py +92 -0
- restpki_ng_python_client/models/xml_signature_post_signed_bytes_response.py +106 -0
- restpki_ng_python_client/models/xml_signature_response_model.py +113 -0
- restpki_ng_python_client/models/xml_signature_types.py +47 -0
- restpki_ng_python_client/models/xml_signed_entity_types.py +46 -0
- restpki_ng_python_client/py.typed +0 -0
- restpki_ng_python_client/rest.py +231 -0
- restpki_ng_python_client/restpki_ng_client.py +458 -0
- restpki_ng_python_client/standard_signature_policies.py +24 -0
- restpki_ng_python_client/utils.py +80 -0
- restpki_ng_python_client-0.9.0.dist-info/METADATA +16 -0
- restpki_ng_python_client-0.9.0.dist-info/RECORD +181 -0
- restpki_ng_python_client-0.9.0.dist-info/WHEEL +5 -0
- restpki_ng_python_client-0.9.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
"""
|
|
2
|
+
User defined, this is not included in the openAPI generation package
|
|
3
|
+
This client intends to center all requests and provide a better name for some of the operations
|
|
4
|
+
To help the user to make a more informed decision
|
|
5
|
+
it is a facade class, which hides all the apis and other implementation problems
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
from io import BufferedReader, BytesIO
|
|
10
|
+
import io
|
|
11
|
+
import os
|
|
12
|
+
import ssl
|
|
13
|
+
from typing import Dict, List
|
|
14
|
+
from restpki_ng_python_client.rest import RESTResponse
|
|
15
|
+
from restpki_ng_python_client.configuration import Configuration
|
|
16
|
+
from restpki_ng_python_client.api_client import ApiClient
|
|
17
|
+
from restpki_ng_python_client.api import *
|
|
18
|
+
from restpki_ng_python_client.models import *
|
|
19
|
+
from restpki_ng_python_client.utils import Utils
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RestPkiClient:
|
|
23
|
+
|
|
24
|
+
def __init__(self, endpoint: str, api_key: str):
|
|
25
|
+
self.endpoint = endpoint
|
|
26
|
+
self.api_key = api_key
|
|
27
|
+
|
|
28
|
+
self._config = Configuration(
|
|
29
|
+
host=self.endpoint,
|
|
30
|
+
api_key=self.api_key,
|
|
31
|
+
username=None,
|
|
32
|
+
api_key_prefix=None,
|
|
33
|
+
password=None,
|
|
34
|
+
server_variables=None,
|
|
35
|
+
server_index=None,
|
|
36
|
+
server_operation_index=None,
|
|
37
|
+
server_operation_variables=None,
|
|
38
|
+
ssl_ca_cert=None)
|
|
39
|
+
self._config.verify_ssl = False
|
|
40
|
+
|
|
41
|
+
# api_key_dict = {'x-api-key': f'Bearer {self.api_key}'}
|
|
42
|
+
|
|
43
|
+
self._apiClient = ApiClient(configuration=self._config)
|
|
44
|
+
self._apiClient.user_agent = 'RestPkiClient/Python/Lib/Beta'
|
|
45
|
+
|
|
46
|
+
self._apiClient.default_headers['Authorization'] = "Bearer " + self.api_key
|
|
47
|
+
self._apiClient.default_headers['x-api-key'] = "Bearer " + self.api_key
|
|
48
|
+
|
|
49
|
+
# Upload stuff
|
|
50
|
+
self.__multipart_upload_threshold = 5 * 1024 * 1024 # 5 MB
|
|
51
|
+
|
|
52
|
+
# Todo: create one client with the endpoint and apikey for each of the routes
|
|
53
|
+
# AppKeys29 API
|
|
54
|
+
# self._app_keys_29_api = ApplicationKeysController29Api(api_client=self._apiClient)
|
|
55
|
+
# Applications API
|
|
56
|
+
# self._apps_api = ApplicationsApi(api_client=self._apiClient)
|
|
57
|
+
# Applications Controller 29 API
|
|
58
|
+
# self._app_ctrl_29_api = ApplicationsController29Api(api_client=self._apiClient)
|
|
59
|
+
# Authentication API
|
|
60
|
+
self._auth_api = AuthenticationApi(api_client=self._apiClient)
|
|
61
|
+
# Cades Signature API
|
|
62
|
+
self._cades_sig_api = CadesSignatureApi(api_client=self._apiClient)
|
|
63
|
+
# Certificates API
|
|
64
|
+
# self._certs_api = CertificatesApi(api_client=self._apiClient)
|
|
65
|
+
# DocumentKeys API
|
|
66
|
+
self._doc_keys_api = DocumentKeysApi(api_client=self._apiClient)
|
|
67
|
+
# Documents API
|
|
68
|
+
self._docs_api = DocumentsApi(api_client=self._apiClient)
|
|
69
|
+
# Pades Signature API
|
|
70
|
+
self._pades_sig_api = PadesSignatureApi(api_client=self._apiClient)
|
|
71
|
+
# Pades visual positioning presets API
|
|
72
|
+
self._pades_visual_pos_pres_api = PadesVisualPositioningPresetsApi(
|
|
73
|
+
api_client=self._apiClient)
|
|
74
|
+
# PDF API
|
|
75
|
+
self._pdf_api = PdfApi(api_client=self._apiClient)
|
|
76
|
+
# Pending Signatures API
|
|
77
|
+
# self._pending_sigs_api = PendingSignaturesApi(api_client=self._apiClient)
|
|
78
|
+
# Signature API
|
|
79
|
+
self._sig_api = SignatureApi(api_client=self._apiClient)
|
|
80
|
+
# Signature Inspection API
|
|
81
|
+
self._sig_insp_api = SignatureInspectionApi(api_client=self._apiClient)
|
|
82
|
+
# Signature Sessions API
|
|
83
|
+
self._sig_ses_api = SignatureSessionsApi(api_client=self._apiClient)
|
|
84
|
+
# Timestamp API
|
|
85
|
+
self._ts_api = TimestampApi(api_client=self._apiClient)
|
|
86
|
+
# Upload API
|
|
87
|
+
self._upload_api = UploadApi(api_client=self._apiClient)
|
|
88
|
+
# XML Signature API
|
|
89
|
+
self._xml_sig_api = XmlSignatureApi(api_client=self._apiClient)
|
|
90
|
+
|
|
91
|
+
# # ApplicationsController`29 Manage applications
|
|
92
|
+
# def get_application_controller(self, q, limit, offset, cursor, order, name) -> SubscriptionAccessModelRolesRootRolesApplicationModelPaginatedSearchResponse:
|
|
93
|
+
# self._app_ctrl_29_api.api_applications_get(q, limit, offset, cursor, order, name)
|
|
94
|
+
|
|
95
|
+
# def create_application_controller(self, request: AuthorizationDataRootAuthorizationDataRolesRootRolesApplicationData) -> SubscriptionAccessModelRolesRootRolesApplicationModel:
|
|
96
|
+
# self._app_ctrl_29_api.api_applications_post(request)
|
|
97
|
+
|
|
98
|
+
# def get_application_controller_by_id(self, id) -> SubscriptionAccessModelRolesRootRolesApplicationModel:
|
|
99
|
+
# self._app_ctrl_29_api.api_applications_id_get(id)
|
|
100
|
+
|
|
101
|
+
# def delete_application_controller_by_id(self, id):
|
|
102
|
+
# self._app_ctrl_29_api.api_applications_id_delete(id)
|
|
103
|
+
|
|
104
|
+
# def check_for_application_name_availability(self, name) -> bool:
|
|
105
|
+
# self._app_ctrl_29_api.api_applications_name_availability_get(name)
|
|
106
|
+
|
|
107
|
+
# ApplicationKeysController`29
|
|
108
|
+
|
|
109
|
+
# def create_application_keys(self, app_id, request: CreateApplicationApiKeyRequest) -> CreateApplicationApiKeyResponse:
|
|
110
|
+
# self._app_keys_29_api.api_applications_app_id_api_keys_post(app_id, request)
|
|
111
|
+
|
|
112
|
+
# Applications
|
|
113
|
+
|
|
114
|
+
# Configures a set of metadata values to be added to each document created by the application
|
|
115
|
+
|
|
116
|
+
def add_document_metadata_set(self, id, request: Dict[str, List]) -> Dict[str, List[str]]:
|
|
117
|
+
return self._apps_api.api_applications_id_default_document_metadata_put(id, request)
|
|
118
|
+
|
|
119
|
+
# Returns the set of metadata values that is currently added for documents created by a given application
|
|
120
|
+
def document_metadata_get(self, id) -> Dict[str, List[str]]:
|
|
121
|
+
return self._apps_api.api_applications_id_default_document_metadata_get(id)
|
|
122
|
+
|
|
123
|
+
# Applications
|
|
124
|
+
|
|
125
|
+
# Prepares for a certificate authentication
|
|
126
|
+
def start_authentication_v2(self, request: PrepareAuthenticationRequest) -> PrepareAuthenticationResponse:
|
|
127
|
+
return self._auth_api.api_v2_authentication_post(prepare_authentication_request=request)
|
|
128
|
+
|
|
129
|
+
# Completes a certificate authentication
|
|
130
|
+
def complete_authentication_v2(self, request: CompleteAuthenticationRequest) -> CompleteAuthenticationResponse:
|
|
131
|
+
return self._auth_api.api_v2_authentication_completion_post(complete_authentication_request=request)
|
|
132
|
+
|
|
133
|
+
def create_authentications(self, request: AuthenticationsPostRequest) -> AuthenticationsPostResponse:
|
|
134
|
+
return self._auth_api.api_authentications_post(authentications_post_request=request)
|
|
135
|
+
|
|
136
|
+
def finalize_authentication_token(self, token) -> AuthenticationPostResponse:
|
|
137
|
+
return self._auth_api.api_authentications_token_finalize_post(token=token)
|
|
138
|
+
|
|
139
|
+
def finalize_authentication_token(self, request: AuthenticationsPostSignedBytesRequest) -> AuthenticationsPostSignedBytesResponse:
|
|
140
|
+
return self._auth_api.api_authentications_token_signed_bytes_post(authentications_post_signed_bytes_request=request)
|
|
141
|
+
|
|
142
|
+
def authentication_get_nonce(self) -> AuthenticationGetResponse:
|
|
143
|
+
return self._auth_api.api_authentication_get()
|
|
144
|
+
|
|
145
|
+
def start_authentication(self, request: AuthenticationsPostRequest) -> AuthenticationPostResponse:
|
|
146
|
+
return self._auth_api.api_authentication_post(authentication_post_request=request)
|
|
147
|
+
|
|
148
|
+
# CadesSignature
|
|
149
|
+
|
|
150
|
+
def create_cades_signature_v2(self, request: CadesSignaturePostRequestV1) -> CadesSignaturePostResponse:
|
|
151
|
+
return self._cades_sig_api.api_cades_signatures_post(cades_signature_post_request_v1=request)
|
|
152
|
+
|
|
153
|
+
def create_cades_signature_v2(self, request: CadesSignaturePostRequestV2) -> CadesSignaturePostResponse:
|
|
154
|
+
return self._cades_sig_api.api_v2_cades_signatures_post(cades_signature_post_request_v2=request)
|
|
155
|
+
|
|
156
|
+
def create_cades_signature_v3(self, request: CadesSignaturePostRequestV3) -> CadesSignaturePostResponse:
|
|
157
|
+
return self._cades_sig_api.api_v3_cades_signatures_post(cades_signature_post_request_v3=request)
|
|
158
|
+
|
|
159
|
+
def create_cades_signatures_with_token_signed_bytes_v1(self, token, request: CadesSignaturePostSignedBytesRequest) -> CadesSignaturePostSignedBytesResponse:
|
|
160
|
+
return self._cades_sig_api.api_cades_signatures_token_signed_bytes_post(token=token, cades_signature_post_signed_bytes_request=request)
|
|
161
|
+
|
|
162
|
+
def finish_cades_signatures_with_token(self, token,) -> CadesSignaturePostSignedBytesResponse:
|
|
163
|
+
return self._cades_sig_api.api_cades_signatures_token_finalize_post(token=token)
|
|
164
|
+
|
|
165
|
+
def create_cades_signatures_with_token_signed_bytes_v2(self, token, request: CompleteSignatureRequest) -> SignatureResultModel:
|
|
166
|
+
return self._cades_sig_api.api_v2_cades_signatures_token_signed_bytes_post(token=token, complete_signature_request=request)
|
|
167
|
+
|
|
168
|
+
def create_cades_signature_required_hashes(self, request: FileModel) -> List[DigestAlgorithms]:
|
|
169
|
+
return self._cades_sig_api.api_cades_signatures_required_hashes_post(file_model=request)
|
|
170
|
+
|
|
171
|
+
def open_cades_signature(self, request: OpenCadesSignatureRequestModel) -> CadesSignatureModel:
|
|
172
|
+
return self._cades_sig_api.api_cades_signatures_open_post(open_cades_signature_request_model=request)
|
|
173
|
+
|
|
174
|
+
# Certificates
|
|
175
|
+
|
|
176
|
+
# Retrieves information about a X.509 certificate previously used to sign some document
|
|
177
|
+
# def retrieve_certificate_info(self, certificate_thumbprint_sha256: str, fill_pem_encoded: bool, fill_encoded: bool) -> CertificateFullModel:
|
|
178
|
+
# self._certs_api.api_certificates_thumbprint_sha256_get(certificate_thumbprint_sha256, fill_pem_encoded, fill_encoded)
|
|
179
|
+
|
|
180
|
+
# Document Keys
|
|
181
|
+
|
|
182
|
+
# Allocates a document key to be used later on a document signature
|
|
183
|
+
def allocate_document_key(self, request: AllocateDocumentKeyRequest) -> DocumentKeyModel:
|
|
184
|
+
return self._doc_keys_api.api_document_keys_post(allocate_document_key_request=request)
|
|
185
|
+
|
|
186
|
+
# Allocates a batch of document keys to be used later on document signatures
|
|
187
|
+
def allocate_batch_document_keys(self, request: AllocateDocumentKeyBatchRequest) -> List[DocumentKeyModel]:
|
|
188
|
+
return self._doc_keys_api.api_document_keys_batch_post(allocate_document_key_batch_request=request)
|
|
189
|
+
|
|
190
|
+
# Queries documents by key
|
|
191
|
+
def query_documents_by_key(self, key: str) -> DocumentKeyQueryResponse:
|
|
192
|
+
return self._doc_keys_api.api_document_keys_key_get(key=key)
|
|
193
|
+
|
|
194
|
+
# Queries unused document keys
|
|
195
|
+
def query_unused_document_keys(self, metadata_name: str, metadata_value: str) -> List[DocumentKeySummary]:
|
|
196
|
+
return self._doc_keys_api.api_document_keys_unused_get(metadata_name=metadata_name, metadata_value=metadata_value)
|
|
197
|
+
|
|
198
|
+
# Documents
|
|
199
|
+
|
|
200
|
+
# Retrieves document details
|
|
201
|
+
def retrieve_document_by_id(self, id: str) -> DocumentModel:
|
|
202
|
+
return self._docs_api.api_documents_id_get(id=id)
|
|
203
|
+
|
|
204
|
+
# Retrieves the full information about each of a document's signers
|
|
205
|
+
def retrieve_signers_info_in_document_by_id(self, id: str) -> List[SignerModel]:
|
|
206
|
+
return self._docs_api.api_documents_id_signers_get(id=id)
|
|
207
|
+
|
|
208
|
+
# Retrieves the full information about each of a document's signers
|
|
209
|
+
def retrieve_document_details_by_key(self, key: str) -> DocumentQueryResponse:
|
|
210
|
+
return self._docs_api.api_documents_keys_key_get(key=key)
|
|
211
|
+
|
|
212
|
+
# PadesSignature
|
|
213
|
+
|
|
214
|
+
def start_pades_signature(self, request: PadesSignaturePostRequestV1) -> PadesSignaturePostResponse:
|
|
215
|
+
return self._pades_sig_api.api_pades_signatures_post(pades_signature_post_request_v1=request)
|
|
216
|
+
|
|
217
|
+
def start_pades_signature_v2(self, request: PadesSignaturePostRequestV2) -> PadesSignaturePostResponse:
|
|
218
|
+
return self._pades_sig_api.api_v2_pades_signatures_post(pades_signature_post_request_v2=request)
|
|
219
|
+
|
|
220
|
+
def complete_pades_signature_with_token_and_signed_bytes(self, token: str, request: PadesSignaturePostSignedBytesRequest) -> PadesSignaturePostSignedBytesResponse:
|
|
221
|
+
return self._pades_sig_api.api_pades_signatures_token_signed_bytes_post(token=token, pades_signature_post_signed_bytes_request=request)
|
|
222
|
+
|
|
223
|
+
def complete_pades_signature_with_token(self, token) -> PadesSignaturePostSignedBytesResponse:
|
|
224
|
+
return self._pades_sig_api.api_pades_signatures_token_finalize_post(token=token)
|
|
225
|
+
|
|
226
|
+
def complete_pades_signature_with_token_and_signed_bytes_v2(self, token, request: CompleteSignatureRequest) -> SignatureResultModel:
|
|
227
|
+
return self._pades_sig_api.api_v2_pades_signatures_token_signed_bytes_post(complete_signature_request=request, token=token)
|
|
228
|
+
|
|
229
|
+
def open_pades_signature(self, request: OpenSignatureRequestModel) -> PadesSignatureModel:
|
|
230
|
+
return self._pades_sig_api.api_pades_signatures_open_post(open_signature_request_model=request)
|
|
231
|
+
|
|
232
|
+
# PadesVisualPositioningPresets
|
|
233
|
+
|
|
234
|
+
def get_footnotes_pades_visual_positioning_presets(self, page_number, rows) -> PadesVisualPositioningModel:
|
|
235
|
+
return self._pades_visual_pos_pres_api.api_pades_visual_positioning_presets_footnote_get(page_number=page_number, rows=rows)
|
|
236
|
+
|
|
237
|
+
def get_footnotes_pades_visual_positioning_presets_bottom_up(self, page_number, rows) -> PadesVisualPositioningModel:
|
|
238
|
+
return self._pades_visual_pos_pres_api.api_pades_visual_positioning_presets_footnote_bottom_up_get(page_number=page_number, rows=rows)
|
|
239
|
+
|
|
240
|
+
def get_footnotes_pades_visual_positioning_presets_new_page(self) -> PadesVisualPositioningModel:
|
|
241
|
+
return self._pades_visual_pos_pres_api.api_pades_visual_positioning_presets_new_page_get()
|
|
242
|
+
|
|
243
|
+
# Pdf
|
|
244
|
+
|
|
245
|
+
def pdf_add_marks(self, request: PdfAddMarksRequest) -> PdfAddMarksResponse:
|
|
246
|
+
return self._pdf_api.api_pdf_add_marks_post(pdf_add_marks_request=request)
|
|
247
|
+
|
|
248
|
+
# Signature
|
|
249
|
+
|
|
250
|
+
def start_signature(self, request: PrepareSignatureRequest) -> PrepareSignatureResponse:
|
|
251
|
+
return self._sig_api.api_signature_post(prepare_signature_request=request)
|
|
252
|
+
|
|
253
|
+
def complete_signature(self, request: CompleteSignatureRequestV2) -> DocumentModel:
|
|
254
|
+
return self._sig_api.api_signature_completion_post(complete_signature_request_v2=request)
|
|
255
|
+
|
|
256
|
+
# Signature Inspection
|
|
257
|
+
|
|
258
|
+
# Inspects a signed file, returning information about its signers and metadata about the corresponding document (if signed on this instance)
|
|
259
|
+
def inspect_signed_file(self, request: InspectSignatureRequest) -> InspectSignatureResponse:
|
|
260
|
+
return self._sig_insp_api.api_signature_inspection_put(inspect_signature_request=request)
|
|
261
|
+
|
|
262
|
+
# SignatureSessions
|
|
263
|
+
|
|
264
|
+
# Retrieves a signature session's details
|
|
265
|
+
def retrieve_signature_session_details_by_id(self, id) -> SignatureSessionModel:
|
|
266
|
+
return self._sig_ses_api.api_signature_sessions_id_get(id=id)
|
|
267
|
+
|
|
268
|
+
# Creates a signature session
|
|
269
|
+
def create_signature_session(self, request: CreateSignatureSessionRequest) -> CreateSignatureSessionResponse:
|
|
270
|
+
return self._sig_ses_api.api_signature_sessions_post(create_signature_session_request=request)
|
|
271
|
+
|
|
272
|
+
# Waits for the completion of a signature session
|
|
273
|
+
def wait_for_completion_signature_session_by_id(self, id):
|
|
274
|
+
return self._sig_ses_api.api_signature_sessions_id_when_completed_get(id=id)
|
|
275
|
+
|
|
276
|
+
# Timestamp
|
|
277
|
+
|
|
278
|
+
def issue_timestamp_plan_with_identifier(self, identifier, request: DigestAlgorithmAndValueModel) -> TimestampIssueResponse:
|
|
279
|
+
return self._ts_api.api_timestamp_plans_identifier_issue_post(identifier=identifier, digest_algorithm_and_value_model=request)
|
|
280
|
+
|
|
281
|
+
def create_timestamp_plan_with_identifier(self, identifier, request: DigestAlgorithmAndValueModel) -> TimestampIssueResponse:
|
|
282
|
+
return self._ts_api.api_timestamp_plans_identifier_issue_post(identifier=identifier, digest_algorithm_and_value_model=request)
|
|
283
|
+
|
|
284
|
+
# Upload
|
|
285
|
+
|
|
286
|
+
# public methods
|
|
287
|
+
def upload_file_multipart(self, file_desc: BufferedReader | BytesIO | str):
|
|
288
|
+
blob_token = self._upload_multipart(file_desc)
|
|
289
|
+
return blob_token
|
|
290
|
+
|
|
291
|
+
def upload_file_plain(self, file_path: str, file_desc: BufferedReader | BytesIO | str):
|
|
292
|
+
blob_token = self._perform_plain_uploads(file_path, file_desc)
|
|
293
|
+
return blob_token
|
|
294
|
+
|
|
295
|
+
def upload_file_from_path(self, path):
|
|
296
|
+
# Check if the file exists
|
|
297
|
+
if not os.path.exists(path):
|
|
298
|
+
print(f"Error: File not found at {path}")
|
|
299
|
+
return False
|
|
300
|
+
else:
|
|
301
|
+
with open(path, 'rb') as file_desc:
|
|
302
|
+
isMultipart = self._isBiggerThanThreshold(file_desc)
|
|
303
|
+
if isMultipart:
|
|
304
|
+
return self.upload_file_multipart(file_desc)
|
|
305
|
+
else:
|
|
306
|
+
return self.upload_file_plain(path, file_desc)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def upload_file_from_raw(self, content_raw):
|
|
310
|
+
stream = BytesIO()
|
|
311
|
+
stream.write(content_raw)
|
|
312
|
+
stream.seek(0, 0)
|
|
313
|
+
|
|
314
|
+
isMultipart = self._isBiggerThanThreshold(content_raw)
|
|
315
|
+
if isMultipart:
|
|
316
|
+
return self.upload_file_multipart(content_raw)
|
|
317
|
+
else:
|
|
318
|
+
return self.upload_file_plain(content_raw)
|
|
319
|
+
|
|
320
|
+
def get_file_from_url(self, url: str) -> RESTResponse:
|
|
321
|
+
return self._apiClient.rest_client.request('GET', url, self._apiClient.default_headers)
|
|
322
|
+
|
|
323
|
+
# END public methods
|
|
324
|
+
|
|
325
|
+
# private methods
|
|
326
|
+
def _upload_multipart(self, file_desc):
|
|
327
|
+
|
|
328
|
+
# Begin the upload
|
|
329
|
+
response = self._perform_multipart_uploads()
|
|
330
|
+
blob_token = response.blob_token
|
|
331
|
+
part_size = response.part_size
|
|
332
|
+
|
|
333
|
+
# begin_url = self.__endpoint_url + 'Api/MultipartUploads'
|
|
334
|
+
# begin_response = requests.post(begin_url,
|
|
335
|
+
# headers=self.get_request_headers())
|
|
336
|
+
# self._check_response('GET', begin_url, begin_response)
|
|
337
|
+
|
|
338
|
+
# blob_token = begin_response.json().get('blobToken')
|
|
339
|
+
# blob_uri = "Api/MultipartUploads/%s" % blob_token
|
|
340
|
+
# part_size = begin_response.json().get('partSize')
|
|
341
|
+
|
|
342
|
+
# Read the file part by part
|
|
343
|
+
|
|
344
|
+
part_e_tags = []
|
|
345
|
+
part_number = 0
|
|
346
|
+
|
|
347
|
+
# Return to the start of the stream.
|
|
348
|
+
file_desc.seek(0, 0)
|
|
349
|
+
while True:
|
|
350
|
+
buffer = file_desc.read(part_size)
|
|
351
|
+
if buffer is None or len(buffer) == 0:
|
|
352
|
+
# Reached end-of-file.
|
|
353
|
+
break
|
|
354
|
+
part_hash = hashlib.md5(buffer)
|
|
355
|
+
part_digest = Utils._base64_url_safe_encode_string(part_hash.digest())
|
|
356
|
+
# self._apiClient.default_headers['Content-MD5'] = Utils.encodeBase64(part_hash.digest())
|
|
357
|
+
# self._apiClient.default_headers['Content-Type'] = 'application/octet-stream'
|
|
358
|
+
# part_url = '%s/%s' % (blob_uri, part_number)
|
|
359
|
+
# response = requests.post(self.__endpoint_url + part_url,
|
|
360
|
+
# data=buffer,
|
|
361
|
+
# headers=headers)
|
|
362
|
+
response = self._perform_multipart_uploads_with_token_and_part_number(blob_token, part_number, part_digest)
|
|
363
|
+
# self._check_response('POST', part_url, response)
|
|
364
|
+
e_tag = response.headers['ETag']
|
|
365
|
+
part_e_tags.append(e_tag)
|
|
366
|
+
part_number += 1
|
|
367
|
+
|
|
368
|
+
# Finish upload
|
|
369
|
+
|
|
370
|
+
# end_request = {
|
|
371
|
+
# 'partETags': part_e_tags,
|
|
372
|
+
# 'completeMD5': None
|
|
373
|
+
# }
|
|
374
|
+
|
|
375
|
+
end_request = MultipartUploadEndRequest(
|
|
376
|
+
part_e_tags=part_e_tags,
|
|
377
|
+
complete_md5=None
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
if self.__multipart_upload_double_check:
|
|
381
|
+
file_desc.seek(0, 0)
|
|
382
|
+
md5 = hashlib.md5(file_desc.read())
|
|
383
|
+
digest = md5.digest()
|
|
384
|
+
end_request.complete_md5 = Utils._base64_encode_string(digest)
|
|
385
|
+
|
|
386
|
+
# finish_url = self.__endpoint_url + blob_uri
|
|
387
|
+
# finish_response = requests.post(finish_url,
|
|
388
|
+
# data=json.dumps(end_request),
|
|
389
|
+
# headers=self.get_request_headers())
|
|
390
|
+
response = self._perform_multipart_uploads_with_token(blob_token)
|
|
391
|
+
# self._check_response('POST', finish_url, finish_response)
|
|
392
|
+
|
|
393
|
+
return response
|
|
394
|
+
|
|
395
|
+
def _perform_plain_uploads(self, file_path, file) -> FileReferenceModel:
|
|
396
|
+
return self._upload_api.api_plain_uploads_post(file_path, file)
|
|
397
|
+
|
|
398
|
+
def _perform_multipart_uploads(self) -> MultipartUploadBeginResponse:
|
|
399
|
+
return self._upload_api.api_multipart_uploads_post()
|
|
400
|
+
|
|
401
|
+
def _perform_multipart_uploads_with_token_and_part_number(self, token, part_number, part_digest):
|
|
402
|
+
return self._upload_api.api_multipart_uploads_token_part_number_post(token, part_number, part_digest)
|
|
403
|
+
|
|
404
|
+
def _perform_multipart_uploads_with_token(self, token):
|
|
405
|
+
return self._upload_api.api_multipart_uploads_token_post(token=token)
|
|
406
|
+
|
|
407
|
+
def _isBiggerThanThreshold(self, file) -> bool:
|
|
408
|
+
if isinstance(file, str): # Check if file is a file path
|
|
409
|
+
return self._checkSizeForFilePath(file)
|
|
410
|
+
elif isinstance(file, io.BufferedReader): # Check if file is a ReadableBuffer
|
|
411
|
+
return self._checkSizeForRawContent(file)
|
|
412
|
+
else:
|
|
413
|
+
print(f"Error: Unsupported input type ({type(file)}).")
|
|
414
|
+
|
|
415
|
+
def _checkSizeForFilePath(self, file_path) -> bool:
|
|
416
|
+
# Get the file size in bytes
|
|
417
|
+
file_size_bytes = os.path.getsize(file_path)
|
|
418
|
+
|
|
419
|
+
# Check if the file size is below the limit
|
|
420
|
+
if file_size_bytes <= self.__multipart_upload_threshold:
|
|
421
|
+
return False
|
|
422
|
+
else:
|
|
423
|
+
return True
|
|
424
|
+
|
|
425
|
+
def _checkSizeForRawContent(self, buffer) -> bool:
|
|
426
|
+
# Get the file size in bytes
|
|
427
|
+
buffer.seek(0, io.SEEK_END)
|
|
428
|
+
content_size_bytes = buffer.tell()
|
|
429
|
+
buffer.seek(0, io.SEEK_SET)
|
|
430
|
+
|
|
431
|
+
# Check if the file size is below the limit
|
|
432
|
+
if content_size_bytes <= self.__multipart_upload_threshold:
|
|
433
|
+
return False
|
|
434
|
+
else:
|
|
435
|
+
return True
|
|
436
|
+
|
|
437
|
+
# END private methods
|
|
438
|
+
|
|
439
|
+
# END Upload
|
|
440
|
+
# XMLSignature
|
|
441
|
+
|
|
442
|
+
def create_full_xml_signature(self, request: FullXmlSignaturePostRequest) -> XmlSignaturePostResponse:
|
|
443
|
+
return self._xml_sig_api.api_xml_signatures_full_xml_signature_post(full_xml_signature_post_request=request)
|
|
444
|
+
|
|
445
|
+
def create_element_xml_signature(self, request: XmlElementSignaturePostRequest) -> XmlSignatureResponseModel:
|
|
446
|
+
return self._xml_sig_api.api_xml_signatures_xml_element_signature_post(xml_element_signature_post_request=request)
|
|
447
|
+
|
|
448
|
+
def complete_xml_signature_with_token_and_signed_bytes(self, token, request: XmlSignaturePostSignedBytesRequest) -> XmlSignaturePostSignedBytesResponse:
|
|
449
|
+
return self._xml_sig_api.api_xml_signatures_token_signed_bytes_post(token=token, xml_signature_post_signed_bytes_request=request)
|
|
450
|
+
|
|
451
|
+
def complete_xml_signature_with_token(self, token) -> XmlSignaturePostSignedBytesResponse:
|
|
452
|
+
return self._xml_sig_api.api_xml_signatures_token_finalize_post(token=token)
|
|
453
|
+
|
|
454
|
+
def open_xml_signature(self, request: OpenXmlSignatureRequestModel) -> List[XmlSignatureModel]:
|
|
455
|
+
return self._xml_sig_api.api_xml_signatures_open_post(open_xml_signature_request_model=request)
|
|
456
|
+
|
|
457
|
+
def open_xml_signature_v2(self, request: OpenXmlSignatureRequestModel) -> XmlSignatureResponseModel:
|
|
458
|
+
return self._xml_sig_api.api_v2_xml_signatures_open_post(open_xml_signature_request_model=request)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class StandardSignaturePolicies:
|
|
2
|
+
PADES_BASIC = '78d20b33-014d-440e-ad07-929f05d00cdf'
|
|
3
|
+
PADES_BASIC_WITH_PKI_BRAZIL_CERTS = '3fec800c-366c-49bf-82c5-2e72154e70f6'
|
|
4
|
+
PADES_T_WITH_PKI_BRAZIL_CERTS = '6a39aeea-a2d0-4754-bf8c-19da15296ddb'
|
|
5
|
+
PKI_BRAZIL_PADES_ADR_BASICA = '531d5012-4c0d-4b6f-89e8-ebdcc605d7c2'
|
|
6
|
+
PKI_BRAZIL_PADES_ADR_TEMPO = '10f0d9a5-a0a9-42e9-9523-e181ce05a25b'
|
|
7
|
+
|
|
8
|
+
CADES_BES = 'a4522485-c9e5-46c3-950b-0d6e951e17d1'
|
|
9
|
+
CADES_BES_WITH_SIGNING_TIME_AND_NO_CRLS =\
|
|
10
|
+
'8108539d-c137-4f45-a1f2-de5305bc0a37'
|
|
11
|
+
PKI_BRAZIL_CADES_ADR_BASICA = '3ddd8001-1672-4eb5-a4a2-6e32b17ddc46'
|
|
12
|
+
PKI_BRAZIL_CADES_ADR_TEMPO = 'a5332ad1-d105-447c-a4bb-b5d02177e439'
|
|
13
|
+
PKI_BRAZIL_CADES_ADR_COMPLETA = '30d881e7-924a-4a14-b5cc-d5a1717d92f6'
|
|
14
|
+
|
|
15
|
+
XML_DSIG_BASIC = '2bb5d8c9-49ba-4c62-8104-8141f6459d08'
|
|
16
|
+
XADES_BES = '1beba282-d1b6-4458-8e46-bd8ad6800b54'
|
|
17
|
+
PKI_BRAZIL_XADES_ADR_BASICA = '1cf5db62-58b6-40ba-88a3-d41bada9b621'
|
|
18
|
+
PKI_BRAZIL_XADES_ADR_TEMPO = '5aa2e0af-5269-43b0-8d45-f4ef52921f04'
|
|
19
|
+
NFE_PADRAO_NACIONAL = 'a3c24251-d43a-4ba4-b25d-ee8e2ab24f06'
|
|
20
|
+
|
|
21
|
+
def __init__(self):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
__all__ = ['StandardSignaturePolicies']
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import binascii
|
|
3
|
+
from io import BytesIO, FileIO
|
|
4
|
+
|
|
5
|
+
from restpki_ng_python_client.models.file_model import FileModel
|
|
6
|
+
|
|
7
|
+
class Utils:
|
|
8
|
+
def _base64_encode_string(value):
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
This method is just a wrapper that handle the incompatibility between the
|
|
12
|
+
standard_b64encode() method on versions 2 and 3 of Python. On Python 2, a
|
|
13
|
+
string is returned, but on Python 3, a bytes-class instance is returned.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
value_base64 = base64.standard_b64encode(value)
|
|
17
|
+
if type(value_base64) is str:
|
|
18
|
+
return value_base64
|
|
19
|
+
elif type(value_base64) is bytes or type(value_base64) is bytearray:
|
|
20
|
+
return value_base64.decode('ascii')
|
|
21
|
+
return None
|
|
22
|
+
def _base64_url_safe_encode_string(value):
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
This method is just a wrapper that handle the incompatibility between the
|
|
26
|
+
standard_b64encode() method on versions 2 and 3 of Python. On Python 2, a
|
|
27
|
+
string is returned, but on Python 3, a bytes-class instance is returned.
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
value_base64 = base64.urlsafe_b64encode(value)
|
|
31
|
+
if type(value_base64) is str:
|
|
32
|
+
return value_base64
|
|
33
|
+
elif type(value_base64) is bytes or type(value_base64) is bytearray:
|
|
34
|
+
return value_base64.decode('ascii')
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _base64_decode(value):
|
|
39
|
+
if value is None:
|
|
40
|
+
raise Exception('The provided value is not valid')
|
|
41
|
+
try:
|
|
42
|
+
raw = base64.standard_b64decode(value)
|
|
43
|
+
except (TypeError, binascii.Error):
|
|
44
|
+
raise Exception('The provided certificate is not Base64-encoded')
|
|
45
|
+
return raw
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _copy_stream(src, dst, offset=0, from_where=0, buff_size=4096):
|
|
49
|
+
# Position source ont he required position.
|
|
50
|
+
dst.seek(offset, from_where)
|
|
51
|
+
while True:
|
|
52
|
+
buff = src.read(buff_size)
|
|
53
|
+
if not buff:
|
|
54
|
+
break
|
|
55
|
+
dst.write(buff)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _get_raw_stream(content):
|
|
59
|
+
stream = BytesIO(content)
|
|
60
|
+
stream.seek(0, 0)
|
|
61
|
+
return stream
|
|
62
|
+
|
|
63
|
+
def write_to_file(file: FileModel, path: str,
|
|
64
|
+
client = None, offset=0, from_where=0,
|
|
65
|
+
buff_size=4096):
|
|
66
|
+
content_base64 = file.content if file.content != None else None
|
|
67
|
+
content_raw = Utils._base64_decode(content_base64)\
|
|
68
|
+
if content_base64 is not None else None
|
|
69
|
+
with open(path, 'wb') as f_out:
|
|
70
|
+
if content_raw is not None:
|
|
71
|
+
f_in = BytesIO(content_raw)
|
|
72
|
+
Utils._copy_stream(f_in, f_out, offset, from_where, buff_size)
|
|
73
|
+
f_in.close()
|
|
74
|
+
else:
|
|
75
|
+
if file.url != None or file.url != '' or client != None or client.endpoint != '':
|
|
76
|
+
req_url = '%s%s' % (client.endpoint, file.url)
|
|
77
|
+
res = client.get_file_from_url(req_url)
|
|
78
|
+
for chunk in res.data\
|
|
79
|
+
.iter_content(buff_size):
|
|
80
|
+
f_out.write(chunk)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: restpki_ng_python_client
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Rest PKI Core API
|
|
5
|
+
Home-page:
|
|
6
|
+
Author: OpenAPI Generator community
|
|
7
|
+
Author-email: team@openapitools.org
|
|
8
|
+
Keywords: OpenAPI,OpenAPI-Generator,Rest PKI Core API
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: urllib3 <2.1.0,>=1.24.3
|
|
11
|
+
Requires-Dist: python-dateutil
|
|
12
|
+
Requires-Dist: pydantic >=2
|
|
13
|
+
Requires-Dist: typing-extensions >=4.7.1
|
|
14
|
+
|
|
15
|
+
<b><i>Para Português, <a href=\"https://docs.lacunasoftware.com/pt-br/articles/rest-pki/core/integration/get-started\">clique aqui</a></i></b> <p> <a href=\"https://docs.lacunasoftware.com/en-us/articles/rest-pki/core/\">Rest PKI Core</a> is an upcoming version of <a href=\"https://docs.lacunasoftware.com/en-us/articles/rest-pki/\">Rest PKI</a> that will have extended compatibility with environments and databases. </p> <p> In addition to Windows Server (which is already supported by Rest PKI), Rest PKI Core will also run on <b>Linux</b> (Debian- and RedHat-based distributions) and on <b>Docker</b>. As for database servers, in addition to SQL Server, <b>PostgreSQL</b> will also be supported. </p> <p> <b>Before getting started, see the integration overview on the <a href=\"https://docs.lacunasoftware.com/en-us/articles/rest-pki/core/integration/\">Integration Guide</a></b> </p> <p> For questions regarding the usage of this API, please reach us at <a href=\"https://lacuna.help/\">lacuna.help</a> </p> <h2>Parameters</h2> <p> You will need the following parameters: </p> <ul> <li><b>Endpoint</b>: address of the Rest PKI Core instance that will be used</li> <li><b>API Key</b>: authorization key for using the API</li> </ul> <p> The <span class=\"model\">endpoint</span> must be prefixed to all relative URLs mentioned here. As for the <span class=\"model\">API Key</span>, see how to use it below. </p> <h2>Authentication</h2> <p> The API key must be sent on the <span class=\"model\">X-Api-Key</span> header on each request: </p> <!-- unfortunately, class \"example microlight\" doesn't seem to work here --> <pre style=\"font-size: 12px; padding: 10px; border-radius: 4px; background: #41444e; font-weight: 600; color: #fff;\"> X-Api-Key: yourapp|xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </pre> <h2>HTTP Codes</h2> <p> The APIs will return the following HTTP codes: </p> <table> <thead> <tr> <th>Code</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><strong class=\"model-title\">200 (OK)</strong></td> <td>Request processed successfully. The response is different for each API, please refer to the operation's documentation</td> </tr> <tr> <td><strong class=\"model-title\">400 (Bad Request)</strong></td> <td>Syntax error. For instance, when a required field was not provided</td> </tr> <tr> <td><strong class=\"model-title\">401 (Unauthorized)</strong></td> <td>API key not provided or invalid</td> </tr> <tr> <td><strong class=\"model-title\">403 (Forbidden)</strong></td> <td>API key is valid, but the application has insufficient permissions to complete the requested operation</td> </tr> <tr> <td><strong class=\"model-title\">422 (Unprocessable Entity)</strong></td> <td>API error. The response body is an <a href=\"#model-ErrorModelV2\" class=\"model\">ErrorModelV2</a> </tr> <tr> <td><strong class=\"model-title\">500 (Internal Server Error)</strong></td> <td>An unexpected error occurred. The <span class=\"model\">exceptionCode</span> contained on the response body may be of help for our support team during diagnostic.</td> </tr> </tbody> </table> <h3>Error Codes</h3> <p> Some of the error codes returned in the <span class=\"model\">code</span> field of an <a href=\"#model-ErrorModelV2\" class=\"model\">ErrorModelV2</a> (body of responses with HTTP status code 422) are provided below*: </p> <table> <thead> <tr> <th>Code</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td class=\"model\">DocumentNotFound</td> <td>A referenced document was not found (check the document ID)</td> </tr> <tr> <td class=\"model\">SecurityContextNotFound</td> <td>A referenced security context was not found (check the security context ID)</td> </tr> <tr> <td class=\"model\">SignatureSessionNotFound</td> <td>A referenced signature session was not found (check the signature session ID)</td> </tr> <tr> <td class=\"model\">BadSignatureSessionOperation</td> <td>The operation is invalid for the current signature session or document status. For instance, trying to await the session's completion if it is still <span class=\"model\">Pending</span> results in this error</td> </tr> <tr> <td class=\"model\">BackgroundProcessing</td> <td>The operation cannot be completed at this time because the resource is being processed in background</td> </tr> <tr> <td class=\"model\">SignatureSessionTokenRequired</td> <td>The signature session token was not passed on the <span class=\"model\">X-Signature-Session-Token</span> request header</td> </tr> <tr> <td class=\"model\">BadSignatureSessionToken</td> <td>An invalid signature session token was passed on the <span class=\"model\">X-Signature-Session-Token</span> request header. Check your application for possible corruption of the session token, which may contain characters <span class=\"code\">-</span> (hyphen) and <span class=\"code\">_</span> (underscore)</td> </tr> <tr> <td class=\"model\">ExpiredSignatureSessionToken</td> <td>An expired signature session token was passed on the <span class=\"model\">X-Signature-Session-Token</span> request header. Signature session tokens are normally valid for 4 hours.</td> </tr> </tbody> </table> <p style=\"font-size: 0.9em\"> *The codes shown above are the most common error codes. Nonetheless, this list is not comprehensive. New codes may be added anytime without previous warning. </p> <h2>Culture / Internationalization (i18n)</h2> <p>The <span class=\"model\">Accept-Language</span> request header is observed by this API. The following cultures are supported:</p> <ul> <li><span class=\"code\">en-US</span> (or simply <span class=\"code\">en</span>)</li> <li><span class=\"code\">pt-BR</span> (or simply <span class=\"code\">pt</span>)</li> </ul> <p><i>Notice: error messages are not affected by this header and therefore should not be displayed to users, being better suited for logging.</i></p>
|
|
16
|
+
|