pangea-sdk 3.8.0b4__py3-none-any.whl → 4.0.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.
Files changed (43) hide show
  1. pangea/__init__.py +1 -2
  2. pangea/asyncio/request.py +17 -22
  3. pangea/asyncio/services/__init__.py +0 -2
  4. pangea/asyncio/services/audit.py +188 -23
  5. pangea/asyncio/services/authn.py +167 -108
  6. pangea/asyncio/services/authz.py +36 -45
  7. pangea/asyncio/services/embargo.py +2 -2
  8. pangea/asyncio/services/file_scan.py +3 -3
  9. pangea/asyncio/services/intel.py +44 -26
  10. pangea/asyncio/services/redact.py +60 -4
  11. pangea/asyncio/services/vault.py +145 -30
  12. pangea/dump_audit.py +1 -1
  13. pangea/request.py +30 -24
  14. pangea/response.py +34 -42
  15. pangea/services/__init__.py +0 -2
  16. pangea/services/audit/audit.py +202 -34
  17. pangea/services/audit/models.py +56 -8
  18. pangea/services/audit/util.py +3 -3
  19. pangea/services/authn/authn.py +116 -65
  20. pangea/services/authn/models.py +88 -4
  21. pangea/services/authz.py +51 -56
  22. pangea/services/base.py +23 -6
  23. pangea/services/embargo.py +2 -2
  24. pangea/services/file_scan.py +3 -2
  25. pangea/services/intel.py +25 -23
  26. pangea/services/redact.py +124 -4
  27. pangea/services/vault/models/common.py +121 -6
  28. pangea/services/vault/models/symmetric.py +2 -2
  29. pangea/services/vault/vault.py +143 -32
  30. pangea/utils.py +20 -109
  31. pangea/verify_audit.py +267 -83
  32. {pangea_sdk-3.8.0b4.dist-info → pangea_sdk-4.0.0.dist-info}/METADATA +12 -20
  33. pangea_sdk-4.0.0.dist-info/RECORD +46 -0
  34. {pangea_sdk-3.8.0b4.dist-info → pangea_sdk-4.0.0.dist-info}/WHEEL +1 -1
  35. pangea/asyncio/__init__.py +0 -1
  36. pangea/asyncio/file_uploader.py +0 -39
  37. pangea/asyncio/services/sanitize.py +0 -185
  38. pangea/asyncio/services/share.py +0 -573
  39. pangea/file_uploader.py +0 -35
  40. pangea/services/sanitize.py +0 -275
  41. pangea/services/share/file_format.py +0 -170
  42. pangea/services/share/share.py +0 -877
  43. pangea_sdk-3.8.0b4.dist-info/RECORD +0 -54
@@ -1,39 +0,0 @@
1
- # Copyright 2022 Pangea Cyber Corporation
2
- # Author: Pangea Cyber Corporation
3
- import io
4
- import logging
5
- from typing import Dict, Optional
6
-
7
- from pangea.asyncio.request import PangeaRequestAsync
8
- from pangea.request import PangeaConfig
9
- from pangea.response import TransferMethod
10
-
11
-
12
- class FileUploaderAsync:
13
- def __init__(self) -> None:
14
- self.logger = logging.getLogger("pangea")
15
- self._request: PangeaRequestAsync = PangeaRequestAsync(
16
- config=PangeaConfig(),
17
- token="",
18
- service="FileUploader",
19
- logger=self.logger,
20
- )
21
-
22
- async def upload_file(
23
- self,
24
- url: str,
25
- file: io.BufferedReader,
26
- transfer_method: TransferMethod = TransferMethod.PUT_URL,
27
- file_details: Optional[Dict] = None,
28
- ) -> None:
29
- if transfer_method == TransferMethod.PUT_URL:
30
- files = [("file", ("filename", file, "application/octet-stream"))]
31
- await self._request.put_presigned_url(url=url, files=files) # type: ignore[arg-type]
32
- elif transfer_method == TransferMethod.POST_URL:
33
- files = [("file", ("filename", file, "application/octet-stream"))]
34
- await self._request.post_presigned_url(url=url, data=file_details, files=files) # type: ignore[arg-type]
35
- else:
36
- raise ValueError(f"Transfer method not supported: {transfer_method}")
37
-
38
- async def close(self) -> None:
39
- await self._request.session.close()
@@ -1,185 +0,0 @@
1
- # Copyright 2022 Pangea Cyber Corporation
2
- # Author: Pangea Cyber Corporation
3
- import io
4
- from typing import List, Optional, Tuple
5
-
6
- import pangea.services.sanitize as m
7
- from pangea.asyncio.services.base import ServiceBaseAsync
8
- from pangea.response import PangeaResponse, TransferMethod
9
- from pangea.utils import FileUploadParams, get_file_upload_params
10
-
11
-
12
- class SanitizeAsync(ServiceBaseAsync):
13
- """Sanitize service client.
14
-
15
- Examples:
16
- import os
17
-
18
- # Pangea SDK
19
- from pangea.config import PangeaConfig
20
- from pangea.asyncio.services import Sanitize
21
-
22
- PANGEA_SANITIZE_TOKEN = os.getenv("PANGEA_SANITIZE_TOKEN")
23
- config = PangeaConfig(domain="pangea.cloud")
24
-
25
- sanitize = Sanitize(token=PANGEA_SANITIZE_TOKEN, config=config)
26
- """
27
-
28
- service_name = "sanitize"
29
-
30
- async def sanitize(
31
- self,
32
- transfer_method: TransferMethod = TransferMethod.POST_URL,
33
- file_path: Optional[str] = None,
34
- file: Optional[io.BufferedReader] = None,
35
- source_url: Optional[str] = None,
36
- share_id: Optional[str] = None,
37
- file_scan: Optional[m.SanitizeFile] = None,
38
- content: Optional[m.SanitizeContent] = None,
39
- share_output: Optional[m.SanitizeShareOutput] = None,
40
- size: Optional[int] = None,
41
- crc32c: Optional[str] = None,
42
- sha256: Optional[str] = None,
43
- uploaded_file_name: Optional[str] = None,
44
- sync_call: bool = True,
45
- ) -> PangeaResponse[m.SanitizeResult]:
46
- """
47
- Sanitize (Beta)
48
-
49
- Apply file sanitization actions according to specified rules.
50
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
51
-
52
- OperationId: sanitize_post_v1beta_sanitize
53
-
54
- Args:
55
- transfer_method: The transfer method used to upload the file data.
56
- file_path: Path to file to sanitize.
57
- file: File to sanitize.
58
- source_url: A URL where the file to be sanitized can be downloaded.
59
- share_id: A Pangea Secure Share ID where the file to be sanitized is stored.
60
- file_scan: Options for File Scan.
61
- content: Options for how the file should be sanitized.
62
- share_output: Integration with Secure Share.
63
- size: The size (in bytes) of the file. If the upload doesn't match, the call will fail.
64
- crc32c: The CRC32C hash of the file data, which will be verified by the server if provided.
65
- sha256: The hexadecimal-encoded SHA256 hash of the file data, which will be verified by the server if provided.
66
- uploaded_file_name: Name of the user-uploaded file, required for `TransferMethod.PUT_URL` and `TransferMethod.POST_URL`.
67
- sync_call: Whether or not to poll on HTTP/202.
68
-
69
- Raises:
70
- PangeaAPIException: If an API error happens.
71
-
72
- Returns:
73
- The sanitized file and information on the sanitization that was
74
- performed.
75
-
76
- Examples:
77
- with open("/path/to/file.pdf", "rb") as f:
78
- response = await sanitize.sanitize(
79
- file=f,
80
- transfer_method=TransferMethod.POST_URL,
81
- uploaded_file_name="uploaded_file",
82
- )
83
- """
84
-
85
- if file or file_path:
86
- if file_path:
87
- file = open(file_path, "rb")
88
- if transfer_method == TransferMethod.POST_URL and (sha256 is None or crc32c is None or size is None):
89
- params = get_file_upload_params(file) # type: ignore[arg-type]
90
- crc32c = params.crc_hex if crc32c is None else crc32c
91
- sha256 = params.sha256_hex if sha256 is None else sha256
92
- size = params.size if size is None else size
93
- else:
94
- crc32c, sha256, size = None, None, None
95
- files: List[Tuple] = [("upload", ("filename", file, "application/octet-stream"))]
96
- else:
97
- raise ValueError("Need to set file_path or file arguments")
98
-
99
- input = m.SanitizeRequest(
100
- transfer_method=transfer_method,
101
- source_url=source_url,
102
- share_id=share_id,
103
- file=file_scan,
104
- content=content,
105
- share_output=share_output,
106
- crc32c=crc32c,
107
- sha256=sha256,
108
- size=size,
109
- uploaded_file_name=uploaded_file_name,
110
- )
111
- data = input.dict(exclude_none=True)
112
- response = await self.request.post(
113
- "v1beta/sanitize", m.SanitizeResult, data=data, files=files, poll_result=sync_call
114
- )
115
- if file_path and file is not None:
116
- file.close()
117
- return response
118
-
119
- async def request_upload_url(
120
- self,
121
- transfer_method: TransferMethod = TransferMethod.PUT_URL,
122
- params: Optional[FileUploadParams] = None,
123
- file_scan: Optional[m.SanitizeFile] = None,
124
- content: Optional[m.SanitizeContent] = None,
125
- share_output: Optional[m.SanitizeShareOutput] = None,
126
- size: Optional[int] = None,
127
- crc32c: Optional[str] = None,
128
- sha256: Optional[str] = None,
129
- uploaded_file_name: Optional[str] = None,
130
- ) -> PangeaResponse[m.SanitizeResult]:
131
- """
132
- Sanitize via presigned URL (Beta)
133
-
134
- Apply file sanitization actions according to specified rules via a
135
- [presigned URL](https://pangea.cloud/docs/api/presigned-urls).
136
- How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
137
-
138
- OperationId: sanitize_post_v1beta_sanitize 2
139
-
140
- Args:
141
- transfer_method: The transfer method used to upload the file data.
142
- params: File upload parameters.
143
- file_scan: Options for File Scan.
144
- content: Options for how the file should be sanitized.
145
- share_output: Integration with Secure Share.
146
- size: The size (in bytes) of the file. If the upload doesn't match, the call will fail.
147
- crc32c: The CRC32C hash of the file data, which will be verified by the server if provided.
148
- sha256: The hexadecimal-encoded SHA256 hash of the file data, which will be verified by the server if provided.
149
- uploaded_file_name: Name of the user-uploaded file, required for `TransferMethod.PUT_URL` and `TransferMethod.POST_URL`.
150
-
151
- Raises:
152
- PangeaAPIException: If an API error happens.
153
-
154
- Returns:
155
- A presigned URL.
156
-
157
- Examples:
158
- presignedUrl = await sanitize.request_upload_url(
159
- transfer_method=TransferMethod.PUT_URL,
160
- uploaded_file_name="uploaded_file",
161
- )
162
-
163
- # Upload file to `presignedUrl.accepted_result.put_url`.
164
-
165
- # Poll for Sanitize's result.
166
- response: PangeaResponse[SanitizeResult] = await sanitize.poll_result(response=presignedUrl)
167
- """
168
-
169
- input = m.SanitizeRequest(
170
- transfer_method=transfer_method,
171
- file=file_scan,
172
- content=content,
173
- share_output=share_output,
174
- crc32c=crc32c,
175
- sha256=sha256,
176
- size=size,
177
- uploaded_file_name=uploaded_file_name,
178
- )
179
- if params is not None and (transfer_method == TransferMethod.POST_URL):
180
- input.crc32c = params.crc_hex
181
- input.sha256 = params.sha256_hex
182
- input.size = params.size
183
-
184
- data = input.dict(exclude_none=True)
185
- return await self.request.request_presigned_url("v1beta/sanitize", m.SanitizeResult, data=data)