pangea-sdk 3.8.0b1__py3-none-any.whl → 5.3.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. pangea/__init__.py +1 -1
  2. pangea/asyncio/file_uploader.py +1 -1
  3. pangea/asyncio/request.py +49 -31
  4. pangea/asyncio/services/__init__.py +2 -0
  5. pangea/asyncio/services/audit.py +192 -31
  6. pangea/asyncio/services/authn.py +187 -109
  7. pangea/asyncio/services/authz.py +285 -0
  8. pangea/asyncio/services/base.py +21 -2
  9. pangea/asyncio/services/embargo.py +2 -2
  10. pangea/asyncio/services/file_scan.py +24 -9
  11. pangea/asyncio/services/intel.py +108 -34
  12. pangea/asyncio/services/redact.py +72 -4
  13. pangea/asyncio/services/sanitize.py +217 -0
  14. pangea/asyncio/services/share.py +246 -73
  15. pangea/asyncio/services/vault.py +1710 -750
  16. pangea/crypto/rsa.py +135 -0
  17. pangea/deep_verify.py +7 -1
  18. pangea/dump_audit.py +9 -8
  19. pangea/request.py +83 -59
  20. pangea/response.py +49 -31
  21. pangea/services/__init__.py +2 -0
  22. pangea/services/audit/audit.py +205 -42
  23. pangea/services/audit/models.py +56 -8
  24. pangea/services/audit/signing.py +6 -5
  25. pangea/services/audit/util.py +3 -3
  26. pangea/services/authn/authn.py +140 -70
  27. pangea/services/authn/models.py +167 -11
  28. pangea/services/authz.py +400 -0
  29. pangea/services/base.py +39 -8
  30. pangea/services/embargo.py +2 -2
  31. pangea/services/file_scan.py +32 -15
  32. pangea/services/intel.py +157 -32
  33. pangea/services/redact.py +152 -4
  34. pangea/services/sanitize.py +388 -0
  35. pangea/services/share/share.py +683 -107
  36. pangea/services/vault/models/asymmetric.py +120 -18
  37. pangea/services/vault/models/common.py +439 -141
  38. pangea/services/vault/models/keys.py +94 -0
  39. pangea/services/vault/models/secret.py +27 -3
  40. pangea/services/vault/models/symmetric.py +68 -22
  41. pangea/services/vault/vault.py +1690 -749
  42. pangea/tools.py +6 -7
  43. pangea/utils.py +16 -27
  44. pangea/verify_audit.py +270 -83
  45. {pangea_sdk-3.8.0b1.dist-info → pangea_sdk-5.3.0.dist-info}/METADATA +43 -35
  46. pangea_sdk-5.3.0.dist-info/RECORD +56 -0
  47. {pangea_sdk-3.8.0b1.dist-info → pangea_sdk-5.3.0.dist-info}/WHEEL +1 -1
  48. pangea_sdk-3.8.0b1.dist-info/RECORD +0 -50
@@ -0,0 +1,217 @@
1
+ # Copyright 2022 Pangea Cyber Corporation
2
+ # Author: Pangea Cyber Corporation
3
+ from __future__ import annotations
4
+
5
+ import io
6
+ from typing import List, Optional, Tuple
7
+
8
+ import pangea.services.sanitize as m
9
+ from pangea.asyncio.services.base import ServiceBaseAsync
10
+ from pangea.config import PangeaConfig
11
+ from pangea.response import PangeaResponse, TransferMethod
12
+ from pangea.utils import FileUploadParams, get_file_upload_params
13
+
14
+
15
+ class SanitizeAsync(ServiceBaseAsync):
16
+ """Sanitize service client.
17
+
18
+ Examples:
19
+ import os
20
+
21
+ # Pangea SDK
22
+ from pangea.asyncio.services import SanitizeAsync
23
+ from pangea.config import PangeaConfig
24
+
25
+ PANGEA_SANITIZE_TOKEN = os.getenv("PANGEA_SANITIZE_TOKEN")
26
+ config = PangeaConfig(domain="pangea.cloud")
27
+
28
+ sanitize = SanitizeAsync(token=PANGEA_SANITIZE_TOKEN, config=config)
29
+ """
30
+
31
+ service_name = "sanitize"
32
+
33
+ def __init__(
34
+ self, token: str, config: PangeaConfig | None = None, logger_name: str = "pangea", config_id: str | None = None
35
+ ) -> None:
36
+ """
37
+ Sanitize client
38
+
39
+ Initializes a new Sanitize client.
40
+
41
+ Args:
42
+ token: Pangea API token.
43
+ config: Configuration.
44
+ logger_name: Logger name.
45
+ config_id: Configuration ID.
46
+
47
+ Examples:
48
+ config = PangeaConfig(domain="aws.us.pangea.cloud")
49
+ authz = SanitizeAsync(token="pangea_token", config=config)
50
+ """
51
+
52
+ super().__init__(token, config, logger_name, config_id=config_id)
53
+
54
+ async def sanitize(
55
+ self,
56
+ transfer_method: TransferMethod = TransferMethod.POST_URL,
57
+ file_path: Optional[str] = None,
58
+ file: Optional[io.BufferedReader] = None,
59
+ source_url: Optional[str] = None,
60
+ share_id: Optional[str] = None,
61
+ file_scan: Optional[m.SanitizeFile] = None,
62
+ content: Optional[m.SanitizeContent] = None,
63
+ share_output: Optional[m.SanitizeShareOutput] = None,
64
+ size: Optional[int] = None,
65
+ crc32c: Optional[str] = None,
66
+ sha256: Optional[str] = None,
67
+ uploaded_file_name: Optional[str] = None,
68
+ sync_call: bool = True,
69
+ ) -> PangeaResponse[m.SanitizeResult]:
70
+ """
71
+ Sanitize
72
+
73
+ Apply file sanitization actions according to specified rules.
74
+
75
+ OperationId: sanitize_post_v1_sanitize
76
+
77
+ Args:
78
+ transfer_method: The transfer method used to upload the file data.
79
+ file_path: Path to file to sanitize.
80
+ file: File to sanitize.
81
+ source_url: A URL where the file to be sanitized can be downloaded.
82
+ share_id: A Pangea Secure Share ID where the file to be sanitized is stored.
83
+ file_scan: Options for File Scan.
84
+ content: Options for how the file should be sanitized.
85
+ share_output: Integration with Secure Share.
86
+ size: The size (in bytes) of the file. If the upload doesn't match, the call will fail.
87
+ crc32c: The CRC32C hash of the file data, which will be verified by the server if provided.
88
+ sha256: The hexadecimal-encoded SHA256 hash of the file data, which will be verified by the server if provided.
89
+ uploaded_file_name: Name of the user-uploaded file, required for `TransferMethod.PUT_URL` and `TransferMethod.POST_URL`.
90
+ sync_call: Whether or not to poll on HTTP/202.
91
+
92
+ Raises:
93
+ PangeaAPIException: If an API error happens.
94
+
95
+ Returns:
96
+ The sanitized file and information on the sanitization that was
97
+ performed.
98
+
99
+ Examples:
100
+ with open("/path/to/file.pdf", "rb") as f:
101
+ response = await sanitize.sanitize(
102
+ file=f,
103
+ transfer_method=TransferMethod.POST_URL,
104
+ uploaded_file_name="uploaded_file",
105
+ )
106
+ """
107
+
108
+ if transfer_method == TransferMethod.SOURCE_URL and source_url is None:
109
+ raise ValueError("`source_url` argument is required when using `TransferMethod.SOURCE_URL`.")
110
+
111
+ if source_url is not None and transfer_method != TransferMethod.SOURCE_URL:
112
+ raise ValueError(
113
+ "`transfer_method` should be `TransferMethod.SOURCE_URL` when using the `source_url` argument."
114
+ )
115
+
116
+ files: Optional[List[Tuple]] = None
117
+ if file or file_path:
118
+ if file_path:
119
+ file = open(file_path, "rb")
120
+ if transfer_method == TransferMethod.POST_URL and (sha256 is None or crc32c is None or size is None):
121
+ params = get_file_upload_params(file) # type: ignore[arg-type]
122
+ crc32c = params.crc_hex if crc32c is None else crc32c
123
+ sha256 = params.sha256_hex if sha256 is None else sha256
124
+ size = params.size if size is None else size
125
+ else:
126
+ crc32c, sha256, size = None, None, None
127
+ files = [("upload", ("filename", file, "application/octet-stream"))]
128
+ elif source_url is None:
129
+ raise ValueError("Need to set one of `file_path`, `file`, or `source_url` arguments.")
130
+
131
+ input = m.SanitizeRequest(
132
+ transfer_method=transfer_method,
133
+ source_url=source_url,
134
+ share_id=share_id,
135
+ file=file_scan,
136
+ content=content,
137
+ share_output=share_output,
138
+ crc32c=crc32c,
139
+ sha256=sha256,
140
+ size=size,
141
+ uploaded_file_name=uploaded_file_name,
142
+ )
143
+ data = input.model_dump(exclude_none=True)
144
+ try:
145
+ return await self.request.post(
146
+ "v1/sanitize", m.SanitizeResult, data=data, files=files, poll_result=sync_call
147
+ )
148
+ finally:
149
+ if file_path and file is not None:
150
+ file.close()
151
+
152
+ async def request_upload_url(
153
+ self,
154
+ transfer_method: TransferMethod = TransferMethod.PUT_URL,
155
+ params: Optional[FileUploadParams] = None,
156
+ file_scan: Optional[m.SanitizeFile] = None,
157
+ content: Optional[m.SanitizeContent] = None,
158
+ share_output: Optional[m.SanitizeShareOutput] = None,
159
+ size: Optional[int] = None,
160
+ crc32c: Optional[str] = None,
161
+ sha256: Optional[str] = None,
162
+ uploaded_file_name: Optional[str] = None,
163
+ ) -> PangeaResponse[m.SanitizeResult]:
164
+ """
165
+ Sanitize via presigned URL
166
+
167
+ Apply file sanitization actions according to specified rules via a
168
+ [presigned URL](https://pangea.cloud/docs/api/transfer-methods).
169
+
170
+ OperationId: sanitize_post_v1_sanitize 2
171
+
172
+ Args:
173
+ transfer_method: The transfer method used to upload the file data.
174
+ params: File upload parameters.
175
+ file_scan: Options for File Scan.
176
+ content: Options for how the file should be sanitized.
177
+ share_output: Integration with Secure Share.
178
+ size: The size (in bytes) of the file. If the upload doesn't match, the call will fail.
179
+ crc32c: The CRC32C hash of the file data, which will be verified by the server if provided.
180
+ sha256: The hexadecimal-encoded SHA256 hash of the file data, which will be verified by the server if provided.
181
+ uploaded_file_name: Name of the user-uploaded file, required for `TransferMethod.PUT_URL` and `TransferMethod.POST_URL`.
182
+
183
+ Raises:
184
+ PangeaAPIException: If an API error happens.
185
+
186
+ Returns:
187
+ A presigned URL.
188
+
189
+ Examples:
190
+ presignedUrl = await sanitize.request_upload_url(
191
+ transfer_method=TransferMethod.PUT_URL,
192
+ uploaded_file_name="uploaded_file",
193
+ )
194
+
195
+ # Upload file to `presignedUrl.accepted_result.put_url`.
196
+
197
+ # Poll for Sanitize's result.
198
+ response: PangeaResponse[SanitizeResult] = await sanitize.poll_result(response=presignedUrl)
199
+ """
200
+
201
+ input = m.SanitizeRequest(
202
+ transfer_method=transfer_method,
203
+ file=file_scan,
204
+ content=content,
205
+ share_output=share_output,
206
+ crc32c=crc32c,
207
+ sha256=sha256,
208
+ size=size,
209
+ uploaded_file_name=uploaded_file_name,
210
+ )
211
+ if params is not None and (transfer_method == TransferMethod.POST_URL):
212
+ input.crc32c = params.crc_hex
213
+ input.sha256 = params.sha256_hex
214
+ input.size = params.size
215
+
216
+ data = input.model_dump(exclude_none=True)
217
+ return await self.request.request_presigned_url("v1/sanitize", m.SanitizeResult, data=data)