protegrity-ai-developer-python 1.2.1__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.
- appython/__init__.py +12 -0
- appython/protector.py +554 -0
- appython/service/auth_provider.py +273 -0
- appython/service/auth_token_provider.py +45 -0
- appython/service/config.py +209 -0
- appython/service/payload_builder.py +141 -0
- appython/service/request_handler.py +115 -0
- appython/service/response_handler.py +78 -0
- appython/stats/__init__.py +3 -0
- appython/stats/collector.py +90 -0
- appython/stats/writer.py +185 -0
- appython/utils/codec_helper.py +86 -0
- appython/utils/constants.py +246 -0
- appython/utils/exceptions.py +141 -0
- appython/utils/input_preprocessor.py +325 -0
- appython/utils/output_postprocessor.py +99 -0
- protegrity_ai_developer_python-1.2.1.dist-info/METADATA +428 -0
- protegrity_ai_developer_python-1.2.1.dist-info/RECORD +53 -0
- protegrity_ai_developer_python-1.2.1.dist-info/WHEEL +5 -0
- protegrity_ai_developer_python-1.2.1.dist-info/entry_points.txt +2 -0
- protegrity_ai_developer_python-1.2.1.dist-info/licenses/LICENSE +21 -0
- protegrity_ai_developer_python-1.2.1.dist-info/top_level.txt +3 -0
- protegrity_developer_python/__init__.py +4 -0
- protegrity_developer_python/scan.py +37 -0
- protegrity_developer_python/securefind.py +83 -0
- protegrity_developer_python/utils/ccn_processing.py +59 -0
- protegrity_developer_python/utils/config.py +60 -0
- protegrity_developer_python/utils/constants.py +123 -0
- protegrity_developer_python/utils/discover.py +49 -0
- protegrity_developer_python/utils/logger.py +23 -0
- protegrity_developer_python/utils/pii_processing.py +291 -0
- protegrity_developer_python/utils/protector.py +23 -0
- protegrity_developer_python/utils/semantic_guardrails.py +240 -0
- protegrity_developer_python/utils/transform.py +66 -0
- pty_migrate/__init__.py +1 -0
- pty_migrate/check_cmd.py +871 -0
- pty_migrate/cli.py +93 -0
- pty_migrate/config.py +127 -0
- pty_migrate/create_policy_cmd.py +795 -0
- pty_migrate/payloads/__init__.py +51 -0
- pty_migrate/payloads/alphabets.json +42 -0
- pty_migrate/payloads/dataelements.json +342 -0
- pty_migrate/payloads/datastores.json +7 -0
- pty_migrate/payloads/deploy_policy_ta.json +1 -0
- pty_migrate/payloads/masks.json +18 -0
- pty_migrate/payloads/members.json +62 -0
- pty_migrate/payloads/policies.json +13 -0
- pty_migrate/payloads/roles.json +32 -0
- pty_migrate/payloads/rules.json +1639 -0
- pty_migrate/payloads/sources.json +10 -0
- pty_migrate/payloads/trusted_apps.json +8 -0
- pty_migrate/ppc_client.py +371 -0
- pty_migrate/stats_cmd.py +87 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module defines constants and enumerations used throughout the application,
|
|
3
|
+
including data types, operation types, argument mappings, character sets, access types,
|
|
4
|
+
and standardized error messages.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from datetime import date
|
|
8
|
+
from enum import Enum
|
|
9
|
+
|
|
10
|
+
DATATYPES = {
|
|
11
|
+
str: 1,
|
|
12
|
+
int: 2,
|
|
13
|
+
float: 3,
|
|
14
|
+
date: 4,
|
|
15
|
+
bytes: 5,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
HOST = "api.developer-edition.protegrity.com"
|
|
19
|
+
VERSION = "1"
|
|
20
|
+
|
|
21
|
+
OP_TYPE = {"protect": "PROTECT", "unprotect": "UNPROTECT", "reprotect": "REPROTECT"}
|
|
22
|
+
|
|
23
|
+
RETURN_CODE = {"protect": 6, "unprotect": 8, "reprotect": 50}
|
|
24
|
+
|
|
25
|
+
ARGS_PROTECT = {"external_iv": 1, "external_tweak": 2, "encrypt_to": 3, "charset": 4}
|
|
26
|
+
|
|
27
|
+
ARGS_UNPROTECT = {"external_iv": 1, "external_tweak": 2, "decrypt_to": 3, "charset": 4}
|
|
28
|
+
|
|
29
|
+
ARGS_REPROTECT = {
|
|
30
|
+
"old_external_iv": 1,
|
|
31
|
+
"new_external_iv": 2,
|
|
32
|
+
"old_external_tweak": 3,
|
|
33
|
+
"new_external_tweak": 4,
|
|
34
|
+
"encrypt_to": 5,
|
|
35
|
+
"charset": 6,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Charset(Enum):
|
|
40
|
+
UTF8 = 2
|
|
41
|
+
UTF16LE = 4
|
|
42
|
+
UTF16BE = 5
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class CheckAccessType(Enum):
|
|
46
|
+
PROTECT = 6
|
|
47
|
+
UNPROTECT = 7
|
|
48
|
+
REPROTECT = 8
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ErrorMessage(Enum):
|
|
52
|
+
DATA_ELEMENT_NONE_EMPTY = "-1, Data element cannot be none or empty"
|
|
53
|
+
DATA_ELEMENT_NOT_STR = "-1, Data element parameter should be of String type."
|
|
54
|
+
NEW_DATA_ELEMENT_NONE_EMPTY = "-1, New Data element cannot be none or empty"
|
|
55
|
+
NEW_DATA_ELEMENT_NOT_STR = (
|
|
56
|
+
"-1, New Data element parameter should be of String type."
|
|
57
|
+
)
|
|
58
|
+
INVALID_KEYWORD_EXTERNAL_IV = "-1, Invalid Keyword Type for keyword: external_iv!!"
|
|
59
|
+
INVALID_KEYWORD_EXTERNAL_TWEAK = (
|
|
60
|
+
"-1, Invalid Keyword Type for keyword: external_tweak!!"
|
|
61
|
+
)
|
|
62
|
+
INVALID_KEYWORD_OLD_EXTERNAL_IV = (
|
|
63
|
+
"-1, Invalid Keyword Type for keyword: old_external_iv!!"
|
|
64
|
+
)
|
|
65
|
+
INVALID_KEYWORD_NEW_EXTERNAL_IV = (
|
|
66
|
+
"-1, Invalid Keyword Type for keyword: new_external_iv!!"
|
|
67
|
+
)
|
|
68
|
+
INVALID_KEYWORD_OLD_EXTERNAL_TWEAK = (
|
|
69
|
+
"-1, Invalid Keyword Type for keyword: old_external_tweak!!"
|
|
70
|
+
)
|
|
71
|
+
INVALID_KEYWORD_NEW_EXTERNAL_TWEAK = (
|
|
72
|
+
"-1, Invalid Keyword Type for keyword: new_external_tweak!!"
|
|
73
|
+
)
|
|
74
|
+
MISSING_OLD_EIV_OR_NEW_EIV = "-1, old_external_iv and new_external_iv both are required for reprotect operation !"
|
|
75
|
+
MISSING_OLD_TWEAK_OR_NEW_TWEAK = "-1, old_external_tweak and new_external_tweak both are required for reprotect operation !"
|
|
76
|
+
INVALID_ENC_TYPE = "-1, Invalid encryption output type!"
|
|
77
|
+
INVALID_DEC_TYPE = "-1, Invalid decryption output type!"
|
|
78
|
+
INVALID_CHARSET_TYPE = "-1, Charset is only supported with byte input data type"
|
|
79
|
+
PROTECT_KEYWORD_EXP = "Expecting one of these: ['external_iv', 'external_tweak', 'charset', 'int_size', 'encrypt_to']"
|
|
80
|
+
UNPROTECT_KEYWORD_EXP = "Expecting one of these: ['external_iv', 'external_tweak', 'charset', 'int_size', 'decrypt_to']"
|
|
81
|
+
REPROTECT_KEYWORD_EXP = "Expecting one of these: ['old_external_iv', 'new_external_iv','old_external_tweak', 'new_external_tweak', 'charset', 'int_size', 'encrypt_to']"
|
|
82
|
+
INVALID_BULK_INPUT = "-1, Bulk input data cannot have different data types!"
|
|
83
|
+
UNSUPPORTED_CHARSET = "-1, Unsupported Charset Passed.Use the Charset enum to pass utf-8,utf-16le or utf-16be charset!"
|
|
84
|
+
INVALID_USER_NAME = "-1, User name parameter should be of String type."
|
|
85
|
+
ERROR_SETTING_DATA = "-1, Could not set data !"
|
|
86
|
+
ERROR_SETTING_OUT_DATA = "-1, Could not set output !"
|
|
87
|
+
UNSUPPORTED_OPS_TYPE = "-1,Operation type received is invalid!"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
LOG_RETURN_CODE_SUCCESS = {
|
|
91
|
+
6: "Data protection was successful.",
|
|
92
|
+
8: "Data unprotect operation was successful.",
|
|
93
|
+
50: "Data reprotect operation was successful.",
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
LOG_RETURN_CODE_UNSUPPORTED = {
|
|
97
|
+
26: "Unsupported algorithm or unsupported action for the specific data element."
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
ERROR_MAPPING = {
|
|
101
|
+
"Access Key security groups not found": "ACCESSKEY_NOT_FOUND",
|
|
102
|
+
"Alphabet was not found": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
103
|
+
"Application has been authorized.": "27, Application has been authorized.",
|
|
104
|
+
"Application has not been authorized.": "28, Application has not been authorized.",
|
|
105
|
+
"Bulk re-protect is not supported": "51, Failed to send logs, connection refused !",
|
|
106
|
+
"Card type must be invalid input": "44, The content of the input data is not valid.",
|
|
107
|
+
"Card type must be valid input": "44, The content of the input data is not valid.",
|
|
108
|
+
"Create operation failed.": "35, Create operation failed.",
|
|
109
|
+
"Create operation was successful.": "34, Create operation was successful.",
|
|
110
|
+
"Crypto operation failed": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
111
|
+
"Data is too long to be protected/unprotected": "23, Data is too long to be protected/unprotected.",
|
|
112
|
+
"Data is too long to be protected/unprotected.": "23, Data is too long to be protected/unprotected.",
|
|
113
|
+
"Data is too short to be protected/unprotected.": "22, Data is too short to be protected/unprotected.",
|
|
114
|
+
"Data protect operation failed.": "7, Data protection failed.",
|
|
115
|
+
"Data protect operation was successful.": "6, Data protection was successful.",
|
|
116
|
+
"Data reprotect operation was successful.": "50, Data protection was successful.",
|
|
117
|
+
"Data unprotect operation failed.": "9, Data unprotect operation failed.",
|
|
118
|
+
"Data unprotect operation was successful with use of an inactive keyid.": "11, Data unprotect operation was successful with use of an inactive keyid.",
|
|
119
|
+
"Data unprotect operation was successful.": "8, Data unprotect operation was successful.",
|
|
120
|
+
"Delete operation failed.": "33, Delete operation failed.",
|
|
121
|
+
"Delete operation was successful.": "32, Delete operation was successful.",
|
|
122
|
+
"Encoding must be provided": "12, Input is null or not within allowed limits.",
|
|
123
|
+
"Encoding not supported": "UNSUPPORTED_ENCODING",
|
|
124
|
+
"External IV is not supported in this version": "16, External IV is not supported in this version.",
|
|
125
|
+
"FPE value identification position is bigger than the data": "12, Input is null or not within allowed limits.",
|
|
126
|
+
"FPE value identification position is invalid": "44, The content of the input data is not valid.",
|
|
127
|
+
"Failed to acquire policy mutex": "17, Failed to initialize the PEP - This is a fatal error",
|
|
128
|
+
"Failed to allocate memory.": "20, Failed to allocate memory.",
|
|
129
|
+
"Failed to calculate policy hash": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
130
|
+
"Failed to check for first call": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
131
|
+
"Failed to clear key context": "10, The user has the appropriate permissions to perform the requested operation. This is just a policy check and no data has been protected nor unprotected.",
|
|
132
|
+
"Failed to convert input data": "21, Input or output buffer is too small.",
|
|
133
|
+
"Failed to convert output data": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
134
|
+
"Failed to convert padded input data": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
135
|
+
"Failed to create Alphabet mutex": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
136
|
+
"Failed to create event for flush thread": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
137
|
+
"Failed to create key context": "10, The user has the appropriate permissions to perform the requested operation. This is just a policy check and no data has been protected nor unprotected.",
|
|
138
|
+
"Failed to create log mutex": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
139
|
+
"Failed to create policy Mutex": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
140
|
+
"Failed to get binary alphabet": "21, Input or output buffer is too small.",
|
|
141
|
+
"Failed to get session from cache": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
142
|
+
"Failed to initialize crypto library": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
143
|
+
"Failed to initialize the PEP - This is a fatal error": "17, Failed to initialize the PEP - This is a fatal error",
|
|
144
|
+
"Failed to load Alphabet from Shmem": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
145
|
+
"Failed to load FPE Properties from Shmem": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
146
|
+
"Failed to load FPE prop - Internal error": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
147
|
+
"Failed to load FPE prop - No such element": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
148
|
+
"Failed to load data encryption key": "14, Failed to load data encryption key",
|
|
149
|
+
"Failed to load data encryption key - Cache is full": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
150
|
+
"Failed to load data encryption key - Internal error": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
151
|
+
"Failed to load data encryption key - No such key": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
152
|
+
"Failed to mask output data": "9, Data unprotect operation failed.",
|
|
153
|
+
"Failed to reset policy": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
154
|
+
"Failed to send logs, connection refused !": "51, Failed to send logs, connection refused !",
|
|
155
|
+
"Failed to set authorization": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
156
|
+
"Failed to set first call in cache": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
157
|
+
"Failed to strip date": "21, Input or output buffer is too small.",
|
|
158
|
+
"Failed to unstrip date": "44, The content of the input data is not valid.",
|
|
159
|
+
"Hash operation failed": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
160
|
+
"IV can't be used with this token element": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
161
|
+
"IV is not supported with used encoding": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
162
|
+
"Input is null or not within allowed limits.": "12, Input is null or not within allowed limits.",
|
|
163
|
+
"Input or output buffer is too small.": "21, Input or output buffer is too small.",
|
|
164
|
+
"Integrity check failed": "21, Input or output buffer is too small.",
|
|
165
|
+
"Integrity check failed.": "5, Integrity check failed.",
|
|
166
|
+
"Internal error": "12, Input is null or not within allowed limits.",
|
|
167
|
+
"Internal error occurring in a function call after the Pep Provider has been opened.": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
168
|
+
"Invalid CT header format": "7, Data protection failed.",
|
|
169
|
+
"Invalid UNICODE input data": "44, The content of the input data is not valid.",
|
|
170
|
+
"Invalid date format": "44, The content of the input data is not valid.",
|
|
171
|
+
"Invalid date input": "44, The content of the input data is not valid.",
|
|
172
|
+
"Invalid email address": "44, The content of the input data is not valid.",
|
|
173
|
+
"Invalid email address, domain length > 254": "23, Data is too long to be protected/unprotected.",
|
|
174
|
+
"Invalid email address, total length > 256": "23, Data is too long to be protected/unprotected.",
|
|
175
|
+
"Invalid email address, wrong domain length": "23, Data is too long to be protected/unprotected.",
|
|
176
|
+
"Invalid email address, wrong local length": "44, The content of the input data is not valid.",
|
|
177
|
+
"Invalid input data": "44, The content of the input data is not valid.",
|
|
178
|
+
"Invalid input data for FPE creditcard": "44, The content of the input data is not valid.",
|
|
179
|
+
"Invalid input for the creditcard FPE type": "44, The content of the input data is not valid.",
|
|
180
|
+
"Invalid input for the creditcard token type": "44, The content of the input data is not valid.",
|
|
181
|
+
"Invalid input for the decimal token type": "44, The content of the input data is not valid.",
|
|
182
|
+
"Invalid input parameter": "44, The content of the input data is not valid.",
|
|
183
|
+
"Invalid license or time is before licensestart.": "42, Invalid license or time is before licensestart.",
|
|
184
|
+
"Invalid parameter": "21, Input or output buffer is too small.",
|
|
185
|
+
"Invalid shared memory contents": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
186
|
+
"Invalid time format": "44, The content of the input data is not valid.",
|
|
187
|
+
"Invalid tokenproc": "12, Input is null or not within allowed limits.",
|
|
188
|
+
"Invalid use of Hmac Data Element": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
189
|
+
"Luhn value must be invalid": "44, The content of the input data is not valid.",
|
|
190
|
+
"Luhn value must be valid": "44, The content of the input data is not valid.",
|
|
191
|
+
"Malloc for the JSON type failed.": "30, Malloc for the JSON type failed.",
|
|
192
|
+
"Manage protection operation failed.": "37, Manage protection operation failed.",
|
|
193
|
+
"Manage protection operation was successful.": "36, Manage protection operation was successful.",
|
|
194
|
+
"No such token element": "UNSUPPORTED_ENCODING",
|
|
195
|
+
"No token elements available": "2, The data element could not be found in the policy.",
|
|
196
|
+
"No valid license or current date is beyond the license expiration date.": "40, No valid license or current date is beyond the license expiration date.",
|
|
197
|
+
"Out buffer size is too small": "12, Input is null or not within allowed limits.",
|
|
198
|
+
"Output buffer is to small": "23, Data is too long to be protected/unprotected.",
|
|
199
|
+
"Output buffer is too small": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
200
|
+
"Output encoding is not supported for Masking": "12, Input is null or not within allowed limits.",
|
|
201
|
+
"Permission denied": "33, Delete operation failed.",
|
|
202
|
+
"Pointer to the policy shared memory is null": "12, Input is null or not within allowed limits.",
|
|
203
|
+
"Policy not available": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
204
|
+
"Protected value can't be returned for this type of algorithm": "10, The user has the appropriate permissions to perform the requested operation. This is just a policy check and no data has been protected nor unprotected.",
|
|
205
|
+
"Provider not initialized": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
206
|
+
"Rule Set not found": "RULESET_NOT_FOUND",
|
|
207
|
+
"The IV value is too long": "12, Input is null or not within allowed limits.",
|
|
208
|
+
"The IV value is too short": "12, Input is null or not within allowed limits.",
|
|
209
|
+
"The JSON type is not serializable.": "29, The JSON type is not serializable.",
|
|
210
|
+
"The User has appropriate permissions to perform the requested operation but no data has been protected/unprotected.": "10, The user has the appropriate permissions to perform the requested operation. This is just a policy check and no data has been protected nor unprotected.",
|
|
211
|
+
"The content of the input data is not valid.": "44, The content of the input data is not valid.",
|
|
212
|
+
"The data element could not be found in the policy in shared memory.": "2, The data element could not be found in the policy.",
|
|
213
|
+
"The data element is not using key id": "0, ",
|
|
214
|
+
"The input is too long": "23, Data is too long to be protected/unprotected.",
|
|
215
|
+
"The input is too short": "22, Data is too short to be protected/unprotected.",
|
|
216
|
+
"The policy in shared memory is empty.": "31, Policy not available",
|
|
217
|
+
"The policy in shared memory is locked. This can be caused by a disk full alert.": "39, The policy in memory is locked. This can be caused by a disk full alert.",
|
|
218
|
+
"The requested action is not supported for tokenization": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
219
|
+
"The tokenized email became too long": "21, Input or output buffer is too small.",
|
|
220
|
+
"The use of the protection method is restricted by license.": "41, The use of the protection method is restricted by license.",
|
|
221
|
+
"The user does not have the appropriate permissions to perform the requested operation.": "3, The user does not have the appropriate permissions to perform the requested operation.",
|
|
222
|
+
"The username could not be found in the policy in shared memory.": "1, The username could not be found in the policy.",
|
|
223
|
+
"Token value identification position is bigger than the data": "12, Input is null or not within allowed limits.",
|
|
224
|
+
"Token value identification position is invalid": "44, The content of the input data is not valid.",
|
|
225
|
+
"Tokenization is disabled": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
226
|
+
"Tweak generation is failed": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
227
|
+
"Tweak input is too long": "15, Tweak input is too long.",
|
|
228
|
+
"Tweak is null.": "4, Tweak is null.",
|
|
229
|
+
"Unsupported algorithm or unsupported action for the specific data element.": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
230
|
+
"Unsupported input encoding for the specific data element.": "UNSUPPORTED_ENCODING",
|
|
231
|
+
"Unsupported operation for that datatype": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
232
|
+
"Unsupported tokenizer type.": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
233
|
+
"Unsupported tweak action for the specified fpe dataelement": "19, Unsupported tweak action for the specified fpe dataelement",
|
|
234
|
+
"Unsupported version": "26, Unsupported algorithm or unsupported action for the specific data element.",
|
|
235
|
+
"Used for z/OS Query Default Data element when policy name is not found": "46, Used for z/OS Query Default Data element when policy name is not found.",
|
|
236
|
+
"Username too long.": "9, Data unprotect operation failed.",
|
|
237
|
+
"iconv failed - 8859-15 to system": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
238
|
+
"iconv failed - system to 8859-15": "13, Internal error occurring in a function call after the Core Provider has been opened.",
|
|
239
|
+
"User not authorized. Refer to audit log for details.": "3, The user does not have the appropriate permissions to perform the requested operation.",
|
|
240
|
+
"Data element not found. Refer to audit log for details.": "2, The data element could not be found in the policy.",
|
|
241
|
+
"Integer input error. Only digits allowed":"44, The content of the input data is not valid.",
|
|
242
|
+
"Integer input out of range. Valid values are -2147483648 to 2147483647":"44, The content of the input data is not valid.",
|
|
243
|
+
"Invalid data length":"44, The content of the input data is not valid.",
|
|
244
|
+
"Integer input out of range. Valid values are -2147483648 to 2147483647":"44, The content of the input data is not valid.",
|
|
245
|
+
"Invalid base64-encoded data, character out of range":"26, Unsupported algorithm or unsupported action for the specific data element."
|
|
246
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module contains all the exceptions raised by AP Python.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from appython.utils.constants import ERROR_MAPPING as error_mapping
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PythonSDKException:
|
|
10
|
+
"""Base exception for all AP Python SDK errors."""
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def map_error_message(error_msg: str) -> str:
|
|
14
|
+
"""
|
|
15
|
+
Map error message to standardized format using regex patterns to extract the actual error message.
|
|
16
|
+
|
|
17
|
+
This function processes error messages from API responses by:
|
|
18
|
+
1. Using regex patterns to identify and extract the core error message
|
|
19
|
+
2. Looking up the extracted message in the error_mapping dictionary
|
|
20
|
+
3. Returning the mapped error code and description, or the original message if not found
|
|
21
|
+
|
|
22
|
+
Supported patterns:
|
|
23
|
+
- "(*) failed. IP:Message" -> extracts "Message"
|
|
24
|
+
- "(*) failed. Message" -> extracts "Message"
|
|
25
|
+
- "Message" -> extracts "Message" (direct message)
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
error_msg (str): Original error message from the operation response.
|
|
29
|
+
Examples:
|
|
30
|
+
- "Unprotect failed. 169.254.17.189:The content of the input data is not valid."
|
|
31
|
+
- "Protect failed. Invalid email address"
|
|
32
|
+
- "(*) failed. Something:Error message"
|
|
33
|
+
- "The content of the input data is not valid."
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
str: Mapped error message in "code, description" format if found in mapping,
|
|
37
|
+
otherwise returns the original error message unchanged.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
>>> map_error_message("Unprotect failed. 169.254.17.189:The content of the input data is not valid.")
|
|
41
|
+
"44, The content of the input data is not valid."
|
|
42
|
+
|
|
43
|
+
>>> map_error_message("Protect failed. Invalid email address")
|
|
44
|
+
"44, The content of the input data is not valid."
|
|
45
|
+
|
|
46
|
+
>>> map_error_message("The content of the input data is not valid.")
|
|
47
|
+
"44, The content of the input data is not valid."
|
|
48
|
+
"""
|
|
49
|
+
if not error_msg:
|
|
50
|
+
return error_msg
|
|
51
|
+
|
|
52
|
+
# Define regex patterns to extract the actual error message
|
|
53
|
+
patterns = [
|
|
54
|
+
# Pattern 1: "Anything failed. IP/Server:Message" -> extract "Message"
|
|
55
|
+
r'.*\s+failed\.\s+[^:]+:(.+)$',
|
|
56
|
+
|
|
57
|
+
# Pattern 2: "Anything failed. Message" -> extract "Message"
|
|
58
|
+
r'.*\s+failed\.\s+(.+)$',
|
|
59
|
+
|
|
60
|
+
# Pattern 3: Direct message (no "failed" prefix) -> extract whole message
|
|
61
|
+
r'^(.+)$'
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
extracted_message = None
|
|
65
|
+
|
|
66
|
+
# Try each pattern until we find a match
|
|
67
|
+
for pattern in patterns:
|
|
68
|
+
match = re.match(pattern, error_msg.strip(), re.IGNORECASE)
|
|
69
|
+
if match:
|
|
70
|
+
extracted_message = match.group(1).strip()
|
|
71
|
+
break
|
|
72
|
+
|
|
73
|
+
# If no pattern matched, use the original message
|
|
74
|
+
if not extracted_message:
|
|
75
|
+
extracted_message = error_msg
|
|
76
|
+
|
|
77
|
+
# Look up the extracted message in error_mapping dictionary
|
|
78
|
+
if extracted_message in error_mapping:
|
|
79
|
+
return error_mapping[extracted_message]
|
|
80
|
+
|
|
81
|
+
# Try partial matching for cases where the extracted message might have extra content
|
|
82
|
+
for key in error_mapping:
|
|
83
|
+
if extracted_message.startswith(key):
|
|
84
|
+
return error_mapping[key]
|
|
85
|
+
# Also try reverse - if the key starts with our extracted message
|
|
86
|
+
if key.startswith(extracted_message):
|
|
87
|
+
return error_mapping[key]
|
|
88
|
+
|
|
89
|
+
# If no match found, return original message
|
|
90
|
+
return error_msg
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class ProtectorError(Exception):
|
|
94
|
+
"""An error occurred during the tokenization or encryption operation."""
|
|
95
|
+
|
|
96
|
+
def __init__(self, wrapped_exc=None, err_msg=None):
|
|
97
|
+
"""Initialize Protector error with appropriate exception or error msg.
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
wrapped_exc (PepProviderError): Exception containing error code
|
|
101
|
+
and message.
|
|
102
|
+
err_msg (str): Exception message.
|
|
103
|
+
"""
|
|
104
|
+
if wrapped_exc is not None:
|
|
105
|
+
msg = wrapped_exc.err_msg
|
|
106
|
+
code = wrapped_exc.err_code
|
|
107
|
+
if code is not None:
|
|
108
|
+
msg = "%s, %s" % (str(code), wrapped_exc.err_msg)
|
|
109
|
+
else:
|
|
110
|
+
msg = err_msg
|
|
111
|
+
super(ProtectorError, self).__init__(msg)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class InitializationError(ProtectorError):
|
|
115
|
+
"""Protector object could not be initialized.
|
|
116
|
+
|
|
117
|
+
This could be due to one of the following reasons:
|
|
118
|
+
- Pepserver is down
|
|
119
|
+
- Application calling AP Python is not trusted one
|
|
120
|
+
- Native module is missing
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class ProtectError(ProtectorError):
|
|
125
|
+
"""A Protect operation failed."""
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class UnprotectError(ProtectorError):
|
|
129
|
+
"""An Un-protect operation failed."""
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class ReprotectError(ProtectorError):
|
|
133
|
+
"""A Re-protec operation failed."""
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class InvalidSessionError(ProtectorError):
|
|
137
|
+
"""Session used for the protection operation is invalid.
|
|
138
|
+
|
|
139
|
+
This could be due to invalid parameters passed while creating session.
|
|
140
|
+
Or if a session has timed out.
|
|
141
|
+
"""
|