pangea-sdk 3.8.0__py3-none-any.whl → 3.8.0b2__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.
- pangea/__init__.py +2 -1
- pangea/asyncio/__init__.py +1 -0
- pangea/asyncio/file_uploader.py +39 -0
- pangea/asyncio/request.py +19 -14
- pangea/asyncio/services/__init__.py +2 -1
- pangea/asyncio/services/audit.py +14 -149
- pangea/asyncio/services/authn.py +48 -64
- pangea/asyncio/services/intel.py +4 -4
- pangea/asyncio/services/redact.py +1 -20
- pangea/asyncio/services/sanitize.py +185 -0
- pangea/asyncio/services/share.py +573 -0
- pangea/asyncio/services/vault.py +4 -21
- pangea/file_uploader.py +35 -0
- pangea/request.py +21 -24
- pangea/response.py +28 -27
- pangea/services/__init__.py +2 -1
- pangea/services/audit/audit.py +16 -151
- pangea/services/audit/models.py +5 -44
- pangea/services/authn/authn.py +4 -20
- pangea/services/base.py +6 -23
- pangea/services/file_scan.py +0 -1
- pangea/services/intel.py +2 -2
- pangea/services/redact.py +1 -20
- pangea/services/sanitize.py +275 -0
- pangea/services/share/file_format.py +170 -0
- pangea/services/share/share.py +877 -0
- pangea/services/vault/vault.py +6 -23
- pangea/utils.py +91 -19
- {pangea_sdk-3.8.0.dist-info → pangea_sdk-3.8.0b2.dist-info}/METADATA +15 -31
- pangea_sdk-3.8.0b2.dist-info/RECORD +52 -0
- pangea/asyncio/services/authz.py +0 -259
- pangea/services/authz.py +0 -377
- pangea_sdk-3.8.0.dist-info/RECORD +0 -46
- {pangea_sdk-3.8.0.dist-info → pangea_sdk-3.8.0b2.dist-info}/WHEEL +0 -0
pangea/services/vault/vault.py
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
# Copyright 2022 Pangea Cyber Corporation
|
2
2
|
# Author: Pangea Cyber Corporation
|
3
|
-
from __future__ import annotations
|
4
|
-
|
5
3
|
import datetime
|
6
4
|
from typing import Dict, Optional, Union
|
7
5
|
|
8
|
-
from pangea.config import PangeaConfig
|
9
6
|
from pangea.response import PangeaResponse
|
10
7
|
from pangea.services.base import ServiceBase
|
11
8
|
from pangea.services.vault.models.asymmetric import (
|
@@ -101,24 +98,10 @@ class Vault(ServiceBase):
|
|
101
98
|
|
102
99
|
def __init__(
|
103
100
|
self,
|
104
|
-
token
|
105
|
-
config
|
106
|
-
logger_name
|
107
|
-
)
|
108
|
-
"""
|
109
|
-
Vault client
|
110
|
-
|
111
|
-
Initializes a new Vault client.
|
112
|
-
|
113
|
-
Args:
|
114
|
-
token: Pangea API token.
|
115
|
-
config: Configuration.
|
116
|
-
logger_name: Logger name.
|
117
|
-
|
118
|
-
Examples:
|
119
|
-
config = PangeaConfig(domain="pangea_domain")
|
120
|
-
vault = Vault(token="pangea_token", config=config)
|
121
|
-
"""
|
101
|
+
token,
|
102
|
+
config=None,
|
103
|
+
logger_name="pangea",
|
104
|
+
):
|
122
105
|
super().__init__(token, config, logger_name)
|
123
106
|
|
124
107
|
# Delete endpoint
|
@@ -1233,7 +1216,7 @@ class Vault(ServiceBase):
|
|
1233
1216
|
Args:
|
1234
1217
|
id (str): The item ID.
|
1235
1218
|
structured_data (dict): Structured data for applying bulk operations.
|
1236
|
-
filter (str): A filter expression for applying bulk operations to the data field.
|
1219
|
+
filter (str, optional): A filter expression for applying bulk operations to the data field.
|
1237
1220
|
version (int, optional): The item version. Defaults to the current version.
|
1238
1221
|
additional_data (str, optional): User provided authentication data.
|
1239
1222
|
|
@@ -1282,7 +1265,7 @@ class Vault(ServiceBase):
|
|
1282
1265
|
Args:
|
1283
1266
|
id (str): The item ID.
|
1284
1267
|
structured_data (dict): Structured data to decrypt.
|
1285
|
-
filter (str): A filter expression for applying bulk operations to the data field.
|
1268
|
+
filter (str, optional): A filter expression for applying bulk operations to the data field.
|
1286
1269
|
version (int, optional): The item version. Defaults to the current version.
|
1287
1270
|
additional_data (str, optional): User provided authentication data.
|
1288
1271
|
|
pangea/utils.py
CHANGED
@@ -4,7 +4,8 @@ import datetime
|
|
4
4
|
import io
|
5
5
|
import json
|
6
6
|
from collections import OrderedDict
|
7
|
-
from hashlib import new, sha1, sha256, sha512
|
7
|
+
from hashlib import md5, new, sha1, sha256, sha512
|
8
|
+
from typing import Union
|
8
9
|
|
9
10
|
from google_crc32c import Checksum as CRC32C # type: ignore[import]
|
10
11
|
from pydantic import BaseModel
|
@@ -30,8 +31,8 @@ def default_encoder(obj) -> str:
|
|
30
31
|
return str(obj)
|
31
32
|
|
32
33
|
|
33
|
-
def str2str_b64(data: str
|
34
|
-
return base64.b64encode(data.encode(
|
34
|
+
def str2str_b64(data: str):
|
35
|
+
return base64.b64encode(data.encode("ascii")).decode("ascii")
|
35
36
|
|
36
37
|
|
37
38
|
def dict_order_keys(data: dict) -> OrderedDict:
|
@@ -76,33 +77,97 @@ def canonicalize(data: dict) -> str:
|
|
76
77
|
return str(data)
|
77
78
|
|
78
79
|
|
79
|
-
def hash_sha256(
|
80
|
-
# Return
|
81
|
-
|
80
|
+
def hash_sha256(input: Union[str, io.BufferedReader]) -> str:
|
81
|
+
# Return SHA256 hash in hex format
|
82
|
+
hash = sha256()
|
83
|
+
if isinstance(input, io.BufferedReader):
|
84
|
+
input.seek(0) # restart reading
|
85
|
+
while True:
|
86
|
+
chunk = input.read(1024 * 1024)
|
87
|
+
if not chunk:
|
88
|
+
break
|
89
|
+
hash.update(chunk)
|
82
90
|
|
91
|
+
input.seek(0) # restart reading
|
92
|
+
else:
|
93
|
+
hash.update(input) # type: ignore
|
83
94
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
95
|
+
return hash.hexdigest()
|
96
|
+
|
97
|
+
|
98
|
+
def hash_sha1(input: Union[str, io.BufferedReader]) -> str:
|
99
|
+
# Return SHA1 hash in hex format
|
100
|
+
hash = sha1()
|
101
|
+
if isinstance(input, io.BufferedReader):
|
102
|
+
input.seek(0) # restart reading
|
103
|
+
while True:
|
104
|
+
chunk = input.read(1024 * 1024)
|
105
|
+
if not chunk:
|
106
|
+
break
|
107
|
+
hash.update(chunk)
|
89
108
|
|
109
|
+
input.seek(0) # restart reading
|
110
|
+
else:
|
111
|
+
hash.update(input) # type: ignore
|
112
|
+
|
113
|
+
return hash.hexdigest()
|
90
114
|
|
91
|
-
def hash_sha1(data: str) -> str:
|
92
|
-
# Return sha1 hash in hex format
|
93
|
-
return sha1(data.encode("ascii")).hexdigest()
|
94
115
|
|
116
|
+
def hash_sha512(input: Union[str, io.BufferedReader]) -> str:
|
117
|
+
# Return SHA512 hash in hex format
|
118
|
+
hash = sha512()
|
119
|
+
if isinstance(input, io.BufferedReader):
|
120
|
+
input.seek(0) # restart reading
|
121
|
+
while True:
|
122
|
+
chunk = input.read(1024 * 1024)
|
123
|
+
if not chunk:
|
124
|
+
break
|
125
|
+
hash.update(chunk)
|
126
|
+
|
127
|
+
input.seek(0) # restart reading
|
128
|
+
else:
|
129
|
+
hash.update(input) # type: ignore
|
95
130
|
|
96
|
-
|
97
|
-
# Return sha512 hash in hex format
|
98
|
-
return sha512(data.encode("ascii")).hexdigest()
|
131
|
+
return hash.hexdigest()
|
99
132
|
|
100
133
|
|
101
|
-
def hash_ntlm(data: str):
|
102
|
-
#
|
134
|
+
def hash_ntlm(data: str) -> str:
|
135
|
+
# Return NTLM hash in hex format
|
103
136
|
return new("md4", data.encode("utf-16le")).hexdigest()
|
104
137
|
|
105
138
|
|
139
|
+
def hash_md5(input: Union[str, io.BufferedReader]) -> str:
|
140
|
+
# Return MD5 hash in hex format
|
141
|
+
hash = md5()
|
142
|
+
if isinstance(input, io.BufferedReader):
|
143
|
+
input.seek(0) # restart reading
|
144
|
+
|
145
|
+
while True:
|
146
|
+
chunk = input.read(1024 * 1024)
|
147
|
+
if not chunk:
|
148
|
+
break
|
149
|
+
hash.update(chunk)
|
150
|
+
|
151
|
+
input.seek(0) # restart reading
|
152
|
+
else:
|
153
|
+
hash.update(input) # type: ignore
|
154
|
+
|
155
|
+
return hash.hexdigest()
|
156
|
+
|
157
|
+
|
158
|
+
def get_crc32c(data: str) -> str:
|
159
|
+
crc = CRC32C()
|
160
|
+
crc.update(data)
|
161
|
+
return crc.hexdigest().decode("utf-8")
|
162
|
+
|
163
|
+
|
164
|
+
def hash_256_filepath(filepath: str) -> str:
|
165
|
+
data = open(filepath, "rb")
|
166
|
+
hash = sha256(data.read()).hexdigest()
|
167
|
+
data.close()
|
168
|
+
return hash
|
169
|
+
|
170
|
+
|
106
171
|
def get_prefix(hash: str, len: int = 5):
|
107
172
|
return hash[0:len]
|
108
173
|
|
@@ -132,3 +197,10 @@ def get_file_upload_params(file: io.BufferedReader) -> FileUploadParams:
|
|
132
197
|
|
133
198
|
file.seek(0) # restart reading
|
134
199
|
return FileUploadParams(crc_hex=crc.hexdigest().decode("utf-8"), sha256_hex=sha.hexdigest(), size=size)
|
200
|
+
|
201
|
+
|
202
|
+
def get_file_size(file: io.BufferedReader) -> int:
|
203
|
+
file.seek(0, io.SEEK_END)
|
204
|
+
size = file.tell()
|
205
|
+
file.seek(0) # restart reading
|
206
|
+
return size
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pangea-sdk
|
3
|
-
Version: 3.8.
|
3
|
+
Version: 3.8.0b2
|
4
4
|
Summary: Pangea API SDK
|
5
5
|
Home-page: https://pangea.cloud/docs/sdk/python/
|
6
6
|
License: MIT
|
@@ -18,14 +18,13 @@ Classifier: Topic :: Software Development
|
|
18
18
|
Classifier: Topic :: Software Development :: Libraries
|
19
19
|
Requires-Dist: aiohttp (>=3.8.6,<4.0.0)
|
20
20
|
Requires-Dist: asyncio (>=3.4.3,<4.0.0)
|
21
|
-
Requires-Dist: cryptography (>=42.0.
|
21
|
+
Requires-Dist: cryptography (>=42.0.5,<43.0.0)
|
22
22
|
Requires-Dist: deprecated (>=1.2.14,<2.0.0)
|
23
23
|
Requires-Dist: google-crc32c (>=1.5.0,<2.0.0)
|
24
|
-
Requires-Dist: pydantic (>=1.10.
|
24
|
+
Requires-Dist: pydantic (>=1.10.14,<2.0.0)
|
25
25
|
Requires-Dist: python-dateutil (>=2.9.0,<3.0.0)
|
26
26
|
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
27
27
|
Requires-Dist: requests-toolbelt (>=1.0.0,<2.0.0)
|
28
|
-
Requires-Dist: typing-extensions (>=4.7.1,<5.0.0)
|
29
28
|
Project-URL: Repository, https://github.com/pangeacyber/pangea-python/tree/main/packages/pangea-sdk
|
30
29
|
Description-Content-Type: text/markdown
|
31
30
|
|
@@ -45,8 +44,6 @@ above.
|
|
45
44
|
|
46
45
|
## Installation
|
47
46
|
|
48
|
-
#### GA releases
|
49
|
-
|
50
47
|
Via pip:
|
51
48
|
|
52
49
|
```bash
|
@@ -59,32 +56,10 @@ Via poetry:
|
|
59
56
|
$ poetry add pangea-sdk
|
60
57
|
```
|
61
58
|
|
62
|
-
<a name="beta-releases"></a>
|
63
|
-
|
64
|
-
#### Beta releases
|
65
|
-
|
66
|
-
Pre-release versions may be available with the `b` (beta) denotation in the
|
67
|
-
version number. These releases serve to preview beta services and APIs. Per
|
68
|
-
Semantic Versioning, they are considered unstable and do not carry the same
|
69
|
-
compatibility guarantees as stable releases. [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
|
70
|
-
|
71
|
-
Via pip:
|
72
|
-
|
73
|
-
```bash
|
74
|
-
$ pip3 install pangea-sdk==3.8.0b2
|
75
|
-
```
|
76
|
-
|
77
|
-
Via poetry:
|
78
|
-
|
79
|
-
```bash
|
80
|
-
$ poetry add pangea-sdk==3.8.0b2
|
81
|
-
```
|
82
|
-
|
83
59
|
## Usage
|
84
60
|
|
85
61
|
- [Documentation][]
|
86
|
-
- [
|
87
|
-
- [Beta Examples][]
|
62
|
+
- [Examples][]
|
88
63
|
|
89
64
|
General usage would be to create a token for a service through the
|
90
65
|
[Pangea Console][] and then construct an API client for that respective service.
|
@@ -143,6 +118,16 @@ if __name__ == "__main__":
|
|
143
118
|
asyncio.run(main())
|
144
119
|
```
|
145
120
|
|
121
|
+
|
122
|
+
<a name="beta-releases"></a>
|
123
|
+
|
124
|
+
## Beta releases
|
125
|
+
|
126
|
+
Pre-release versions may be available with the `beta` denotation in the version
|
127
|
+
number. These releases serve to preview beta services and APIs. Per Semantic
|
128
|
+
Versioning, they are considered unstable and do not carry the same compatibility
|
129
|
+
guarantees as stable releases.
|
130
|
+
|
146
131
|
## Secure Audit Log - Integrity Tools
|
147
132
|
|
148
133
|
The Python Pangea SDK also includes some extra features to validate Audit Service log's integrity. Here we explain how to run them.
|
@@ -228,8 +213,7 @@ It accepts multiple file formats:
|
|
228
213
|
|
229
214
|
|
230
215
|
[Documentation]: https://pangea.cloud/docs/sdk/python/
|
231
|
-
[
|
232
|
-
[Beta Examples]: https://github.com/pangeacyber/pangea-python/tree/beta/examples
|
216
|
+
[Examples]: https://github.com/pangeacyber/pangea-python/tree/main/examples
|
233
217
|
[Pangea Console]: https://console.pangea.cloud/
|
234
218
|
[Slack]: https://pangea.cloud/join-slack/
|
235
219
|
[Secure Audit Log]: https://pangea.cloud/docs/audit
|
@@ -0,0 +1,52 @@
|
|
1
|
+
pangea/__init__.py,sha256=frHRs4xf9u9kfWJlrcNwltqXeWYjDCjJ3uDZaT12Fx0,251
|
2
|
+
pangea/asyncio/__init__.py,sha256=kjEMkqMQ521LlMSu5jn3_WgweyArwVZ2C-s3x7mR6Pk,45
|
3
|
+
pangea/asyncio/file_uploader.py,sha256=nIBDNvZPwl-iA95OdwgEPeqUizvaBVsOc66Wkfux_6A,1462
|
4
|
+
pangea/asyncio/request.py,sha256=ceFLWZ9MONt40PETarh1DSSDhA2rrDGgLrVz7u4xduQ,17272
|
5
|
+
pangea/asyncio/services/__init__.py,sha256=XZyaFnvcA9fmYuKXXZi3ksjad6fssUa-8zqszW7ZZaY,356
|
6
|
+
pangea/asyncio/services/audit.py,sha256=FJzSQSRhzQ0MNuhvMvziGyfGhcFb_HHeJ11NkPS_DBU,19594
|
7
|
+
pangea/asyncio/services/authn.py,sha256=njuhg0SMLkke4Bmqe0C75BybjnmsC1ruAv6ariNbFwY,43812
|
8
|
+
pangea/asyncio/services/base.py,sha256=4FtKtlq74NmE9myrgIt9HMA6JDnP4mPZ6krafWr286o,2663
|
9
|
+
pangea/asyncio/services/embargo.py,sha256=8WguyWZUaGVwGpNzic5h8QzLueirA9WpBBik4mpCTeA,3056
|
10
|
+
pangea/asyncio/services/file_scan.py,sha256=WIKYjUNCIx6jF0vQ-KnsKYBcZh53Q5rmccTlsTPP_rY,6301
|
11
|
+
pangea/asyncio/services/intel.py,sha256=SSOBkD1vE0laQ2qWIDi5tHuYphQ8gFM_ikxr6VyoEp4,37665
|
12
|
+
pangea/asyncio/services/redact.py,sha256=Crs8fpPG3gMgxR5uRT22qaS85yorUzec-PY1lYK4FzI,5174
|
13
|
+
pangea/asyncio/services/sanitize.py,sha256=FaT2Zp9vMSs61poyMFPxduO4DwIdVl2pOl0BZnlsi34,7528
|
14
|
+
pangea/asyncio/services/share.py,sha256=qB2yBS_66iSgBFsYMTrNcrTWu-UfRDZFQ3Os8KjmFVo,24447
|
15
|
+
pangea/asyncio/services/vault.py,sha256=i8LGfZT5MQ_PFcOSA-zM3aRqlwkGHOu1WJ8U0VJaekc,47360
|
16
|
+
pangea/audit_logger.py,sha256=gRkCfUUT5LDNaycwxkhZUySgY47jDfn1ZeKOul4XCQI,3842
|
17
|
+
pangea/config.py,sha256=mQUu8GX_6weIuv3vjNdG5plppXskXYASmxMWtFQh-hc,1662
|
18
|
+
pangea/deep_verify.py,sha256=mocaGbC6XLbMTVWxTpMv4oJtXGPWpT-SbFqT3obpiZs,8443
|
19
|
+
pangea/deprecated.py,sha256=IjFYEVvY1E0ld0SMkEYC1o62MAleX3nnT1If2dFVbHo,608
|
20
|
+
pangea/dump_audit.py,sha256=8KrTOP64D28RFv1mvOOxe0fxlRZi8PtwnEZfvabglNA,7019
|
21
|
+
pangea/exceptions.py,sha256=OBtzUECpNa6vNp8ySkHC-tm4QjFRCOAHBkMHqzAlOu8,5656
|
22
|
+
pangea/file_uploader.py,sha256=4RQ44xt-faApC61nn2PlwHT7XYrJ4GeQA8Ug4tySEAg,1227
|
23
|
+
pangea/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
+
pangea/request.py,sha256=eJBojjqVkIweNgf-MeHU9JqmuRXAZ-jFx2Rk25vKgIA,24346
|
25
|
+
pangea/response.py,sha256=wKHFCZBkv27PvMG5Z5pa4FYqzmMl_Pp8e_nfmNeed3k,7042
|
26
|
+
pangea/services/__init__.py,sha256=F6mTQ0oU2g21GUIJeNBFXWuye8SWxl2Z5FFEv6fyWsc,315
|
27
|
+
pangea/services/audit/audit.py,sha256=NFpAz_a8JoI89HqGsBTqJgjSbTP0yflNQYY6McU6rek,32834
|
28
|
+
pangea/services/audit/exceptions.py,sha256=bhVuYe4ammacOVxwg98CChxvwZf5FKgR2DcgqILOcwc,471
|
29
|
+
pangea/services/audit/models.py,sha256=zKx-CozUSv0dem4sWxqUs_By0CcQQtNUFtXYg6IAwtI,12644
|
30
|
+
pangea/services/audit/signing.py,sha256=pOjw60BIYDcg3_5YKDCMWZUaapsEZpCHaFhyFu7TEgc,5567
|
31
|
+
pangea/services/audit/util.py,sha256=C6KAdu6qhValmNrIMUPLdAW0SCiLwcDd5euXti_63Og,7596
|
32
|
+
pangea/services/authn/authn.py,sha256=pjx8CybKhkf0Q9jNpcYUwAPL0KYr1ULg-mhdb0TbQbE,43280
|
33
|
+
pangea/services/authn/models.py,sha256=FZ5kRBZQ-Pr2YD3jFZ4HvJI22ObbXaBb6HStjcN7-D0,18104
|
34
|
+
pangea/services/base.py,sha256=60FuZkACFGDDQFZfx9vzspPTtZU0pFqNKM_ViatXejc,3012
|
35
|
+
pangea/services/embargo.py,sha256=WFqBreGU1FPgOSabIIkWCrXBvquYN958Un7h9P1aHSI,3885
|
36
|
+
pangea/services/file_scan.py,sha256=loceEPhHTG4fKxUXk0Qut-ztGm4N-FaSMl2QBy2x20U,6923
|
37
|
+
pangea/services/intel.py,sha256=r-MRWuyo5wPNi69M2PGb3G2TlA4e77ZR2RlSVSmT8as,51637
|
38
|
+
pangea/services/redact.py,sha256=9LSVDyQsL_RBWioMXVq6-6Hf7Tr2bqBZo3ydbDw92Bg,7772
|
39
|
+
pangea/services/sanitize.py,sha256=8Y0Wnmt3qHCc3jCIa2dryDagmAPKduJNGygsW1Fb-H4,10044
|
40
|
+
pangea/services/share/file_format.py,sha256=1svO1ee_aenA9zoO_AaU-Rk5Ulp7kcPOc_KwNoluyQE,2797
|
41
|
+
pangea/services/share/share.py,sha256=WOqthaDSx1GAbjqJ2y-7kHXIl0-jFLWK2HQ7qjfOHio,32185
|
42
|
+
pangea/services/vault/models/asymmetric.py,sha256=ac2Exc66elXxO-HxBqtvLPQWNI7y_00kb6SVqBPKecA,1450
|
43
|
+
pangea/services/vault/models/common.py,sha256=Ks6reIlWx3PU1lD0UlorcAlZV8U9T3j711iOsb6qp3o,11120
|
44
|
+
pangea/services/vault/models/secret.py,sha256=cLgEj-_BeGkB4-pmSeTkWVyasFbaJwcEltIEcOyf1U8,481
|
45
|
+
pangea/services/vault/models/symmetric.py,sha256=5N2n6FDStB1CLPfpd4p-6Ig__Nt-EyurhjCWfEyws2k,1330
|
46
|
+
pangea/services/vault/vault.py,sha256=5islfGG4QLXHaZDwv7dEIPxpmpV8swFIYwCMz6-iBwE,47168
|
47
|
+
pangea/tools.py,sha256=sa2pSz-L8tB6GcZg6lghsmm8w0qMQAIkzqcv7dilU6Q,6429
|
48
|
+
pangea/utils.py,sha256=LTWkm7AZO95PITY1w7zbt6N3jWK1OPgzwy69FOKljCY,5289
|
49
|
+
pangea/verify_audit.py,sha256=QthhKzFlIQwoEyjBLojcX4uHGaN3EEGomx-IC5e3L0E,10756
|
50
|
+
pangea_sdk-3.8.0b2.dist-info/METADATA,sha256=7D25G-WgyaP5HQUc88Vo9To2sx66y8sl41YpoVr1Yn8,7079
|
51
|
+
pangea_sdk-3.8.0b2.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
52
|
+
pangea_sdk-3.8.0b2.dist-info/RECORD,,
|
pangea/asyncio/services/authz.py
DELETED
@@ -1,259 +0,0 @@
|
|
1
|
-
# Copyright 2022 Pangea Cyber Corporation
|
2
|
-
# Author: Pangea Cyber Corporation
|
3
|
-
|
4
|
-
from typing import Dict, List, Optional, Union
|
5
|
-
|
6
|
-
from pangea.asyncio.services.base import ServiceBaseAsync
|
7
|
-
from pangea.response import PangeaResponse
|
8
|
-
from pangea.services.authz import (
|
9
|
-
CheckRequest,
|
10
|
-
CheckResult,
|
11
|
-
ItemOrder,
|
12
|
-
ListResourcesRequest,
|
13
|
-
ListResourcesResult,
|
14
|
-
ListSubjectsRequest,
|
15
|
-
ListSubjectsResult,
|
16
|
-
Resource,
|
17
|
-
Subject,
|
18
|
-
Tuple,
|
19
|
-
TupleCreateRequest,
|
20
|
-
TupleCreateResult,
|
21
|
-
TupleDeleteRequest,
|
22
|
-
TupleDeleteResult,
|
23
|
-
TupleListFilter,
|
24
|
-
TupleListRequest,
|
25
|
-
TupleListResult,
|
26
|
-
TupleOrderBy,
|
27
|
-
)
|
28
|
-
|
29
|
-
|
30
|
-
class AuthZAsync(ServiceBaseAsync):
|
31
|
-
"""AuthZ service client. (Beta)
|
32
|
-
|
33
|
-
Provides methods to interact with the Pangea AuthZ Service.
|
34
|
-
Documentation for the AuthZ Service API can be found at
|
35
|
-
<https://pangea.cloud/docs/api/authz>. Note that this service is in Beta and
|
36
|
-
is subject to change.
|
37
|
-
|
38
|
-
Examples:
|
39
|
-
import os
|
40
|
-
from pangea.config import PangeaConfig
|
41
|
-
from pangea.services import AuthZ
|
42
|
-
|
43
|
-
PANGEA_TOKEN = os.getenv("PANGEA_AUTHZ_TOKEN")
|
44
|
-
|
45
|
-
authz_config = PangeaConfig(domain="aws.us.pangea.cloud")
|
46
|
-
|
47
|
-
# Setup Pangea AuthZ service client
|
48
|
-
authz = AuthZAsync(token=PANGEA_TOKEN, config=authz_config)
|
49
|
-
"""
|
50
|
-
|
51
|
-
service_name = "authz"
|
52
|
-
|
53
|
-
def __init__(self, token: str, config=None, logger_name="pangea", config_id: Optional[str] = None):
|
54
|
-
super().__init__(token, config, logger_name, config_id=config_id)
|
55
|
-
|
56
|
-
async def tuple_create(self, tuples: List[Tuple]) -> PangeaResponse[TupleCreateResult]:
|
57
|
-
"""Create tuples. (Beta)
|
58
|
-
|
59
|
-
Create tuples in the AuthZ Service. The request will fail if there is no schema
|
60
|
-
or the tuples do not validate against the schema.
|
61
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
62
|
-
|
63
|
-
Args:
|
64
|
-
tuples (List[Tuple]): List of tuples to be created.
|
65
|
-
|
66
|
-
Raises:
|
67
|
-
PangeaAPIException: If an API Error happens.
|
68
|
-
|
69
|
-
Returns:
|
70
|
-
Pangea Response with empty result.
|
71
|
-
Available response fields can be found in our
|
72
|
-
[API Documentation](https://pangea.cloud/docs/api/authz#/v1/tuple/create).
|
73
|
-
|
74
|
-
Examples:
|
75
|
-
await authz.tuple_create(
|
76
|
-
tuples=[
|
77
|
-
Tuple(
|
78
|
-
resource=Resource(type="file", id="file_1"),
|
79
|
-
relation="owner",
|
80
|
-
subject=Subject(type="user", id="user_1"),
|
81
|
-
)
|
82
|
-
]
|
83
|
-
)
|
84
|
-
"""
|
85
|
-
|
86
|
-
input_data = TupleCreateRequest(tuples=tuples)
|
87
|
-
return await self.request.post("v1/tuple/create", TupleCreateResult, data=input_data.dict(exclude_none=True))
|
88
|
-
|
89
|
-
async def tuple_list(
|
90
|
-
self,
|
91
|
-
filter: TupleListFilter,
|
92
|
-
size: Optional[int] = None,
|
93
|
-
last: Optional[str] = None,
|
94
|
-
order: Optional[ItemOrder] = None,
|
95
|
-
order_by: Optional[TupleOrderBy] = None,
|
96
|
-
) -> PangeaResponse[TupleListResult]:
|
97
|
-
"""List tuples. (Beta)
|
98
|
-
|
99
|
-
Return a paginated list of filtered tuples. The filter is given in terms
|
100
|
-
of a tuple. Fill out the fields that you want to filter. If the filter
|
101
|
-
is empty it will return all the tuples.
|
102
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
103
|
-
|
104
|
-
Args:
|
105
|
-
filter (TupleListFilter): The filter for listing tuples.
|
106
|
-
size (Optional[int]): The size of the result set. Default is None.
|
107
|
-
last (Optional[str]): The last token from a previous response. Default is None.
|
108
|
-
order (Optional[ItemOrder]): Order results asc(ending) or desc(ending).
|
109
|
-
order_by (Optional[TupleOrderBy]): Which field to order results by.
|
110
|
-
|
111
|
-
Raises:
|
112
|
-
PangeaAPIException: If an API Error happens.
|
113
|
-
|
114
|
-
Returns:
|
115
|
-
Pangea Response with a list of tuples and the last token.
|
116
|
-
Available response fields can be found in our
|
117
|
-
[API Documentation](https://pangea.cloud/docs/api/authz#/v1/tuple/list).
|
118
|
-
|
119
|
-
Examples:
|
120
|
-
await authz.tuple_list(TupleListFilter(subject_type="user", subject_id="user_1"))
|
121
|
-
"""
|
122
|
-
input_data = TupleListRequest(
|
123
|
-
filter=filter.dict(exclude_none=True), size=size, last=last, order=order, order_by=order_by
|
124
|
-
)
|
125
|
-
return await self.request.post("v1/tuple/list", TupleListResult, data=input_data.dict(exclude_none=True))
|
126
|
-
|
127
|
-
async def tuple_delete(self, tuples: List[Tuple]) -> PangeaResponse[TupleDeleteResult]:
|
128
|
-
"""Delete tuples. (Beta)
|
129
|
-
|
130
|
-
Delete tuples in the AuthZ Service.
|
131
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
132
|
-
|
133
|
-
Args:
|
134
|
-
tuples (List[Tuple]): List of tuples to be deleted.
|
135
|
-
|
136
|
-
Raises:
|
137
|
-
PangeaAPIException: If an API Error happens.
|
138
|
-
|
139
|
-
Returns:
|
140
|
-
Pangea Response with empty result.
|
141
|
-
Available response fields can be found in our
|
142
|
-
[API Documentation](https://pangea.cloud/docs/api/authz#/v1/tuple/delete).
|
143
|
-
|
144
|
-
Examples:
|
145
|
-
await authz.tuple_delete(
|
146
|
-
tuples=[
|
147
|
-
Tuple(
|
148
|
-
resource=Resource(type="file", id="file_1"),
|
149
|
-
relation="owner",
|
150
|
-
subject=Subject(type="user", id="user_1"),
|
151
|
-
)
|
152
|
-
]
|
153
|
-
)
|
154
|
-
"""
|
155
|
-
|
156
|
-
input_data = TupleDeleteRequest(tuples=tuples)
|
157
|
-
return await self.request.post("v1/tuple/delete", TupleDeleteResult, data=input_data.dict(exclude_none=True))
|
158
|
-
|
159
|
-
async def check(
|
160
|
-
self,
|
161
|
-
resource: Resource,
|
162
|
-
action: str,
|
163
|
-
subject: Subject,
|
164
|
-
debug: Optional[bool] = None,
|
165
|
-
attributes: Optional[Dict[str, Union[int, str]]] = None,
|
166
|
-
) -> PangeaResponse[CheckResult]:
|
167
|
-
"""Perform a check request. (Beta)
|
168
|
-
|
169
|
-
Check if a subject has permission to perform an action on the resource.
|
170
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
171
|
-
|
172
|
-
Args:
|
173
|
-
resource (Resource): The resource to check.
|
174
|
-
action (str): The action to check.
|
175
|
-
subject (Subject): The subject to check.
|
176
|
-
debug (Optional[bool]): Setting this value to True will provide a detailed analysis of the check.
|
177
|
-
attributes (Optional[Dict[str, Union[int, str]]]): Additional attributes for the check.
|
178
|
-
|
179
|
-
Raises:
|
180
|
-
PangeaAPIException: If an API Error happens.
|
181
|
-
|
182
|
-
Returns:
|
183
|
-
Pangea Response with the result of the check.
|
184
|
-
Available response fields can be found in our
|
185
|
-
[API Documentation](https://pangea.cloud/docs/api/authz#/v1/check).
|
186
|
-
|
187
|
-
Examples:
|
188
|
-
await authz.check(
|
189
|
-
resource=Resource(type="file", id="file_1"),
|
190
|
-
action="update",
|
191
|
-
subject=Subject(type="user", id="user_1"),
|
192
|
-
debug=True,
|
193
|
-
)
|
194
|
-
"""
|
195
|
-
|
196
|
-
input_data = CheckRequest(resource=resource, action=action, subject=subject, debug=debug, attributes=attributes)
|
197
|
-
return await self.request.post("v1/check", CheckResult, data=input_data.dict(exclude_none=True))
|
198
|
-
|
199
|
-
async def list_resources(self, type: str, action: str, subject: Subject) -> PangeaResponse[ListResourcesResult]:
|
200
|
-
"""List resources. (Beta)
|
201
|
-
|
202
|
-
Given a type, action, and subject, list all the resources in the
|
203
|
-
type that the subject has access to the action with.
|
204
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
205
|
-
|
206
|
-
Args:
|
207
|
-
type (str): The type to filter resources.
|
208
|
-
action (str): The action to filter resources.
|
209
|
-
subject (Subject): The subject to filter resources.
|
210
|
-
|
211
|
-
Raises:
|
212
|
-
PangeaAPIException: If an API Error happens.
|
213
|
-
|
214
|
-
Returns:
|
215
|
-
Pangea Response with a list of resource IDs.
|
216
|
-
Available response fields can be found in our
|
217
|
-
[API Documentation](https://pangea.cloud/docs/api/authz#/v1/list-resources).
|
218
|
-
|
219
|
-
Examples:
|
220
|
-
await authz.list_resources(
|
221
|
-
type="file",
|
222
|
-
action="update",
|
223
|
-
subject=Subject(type="user", id="user_1"),
|
224
|
-
)
|
225
|
-
"""
|
226
|
-
|
227
|
-
input_data = ListResourcesRequest(type=type, action=action, subject=subject)
|
228
|
-
return await self.request.post(
|
229
|
-
"v1/list-resources", ListResourcesResult, data=input_data.dict(exclude_none=True)
|
230
|
-
)
|
231
|
-
|
232
|
-
async def list_subjects(self, resource: Resource, action: str) -> PangeaResponse[ListSubjectsResult]:
|
233
|
-
"""List subjects. (Beta)
|
234
|
-
|
235
|
-
Given a resource and an action, return the list of subjects who have
|
236
|
-
access to the action for the given resource.
|
237
|
-
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
238
|
-
|
239
|
-
Args:
|
240
|
-
resource (Resource): The resource to filter subjects.
|
241
|
-
action (str): The action to filter subjects.
|
242
|
-
|
243
|
-
Raises:
|
244
|
-
PangeaAPIException: If an API Error happens.
|
245
|
-
|
246
|
-
Returns:
|
247
|
-
Pangea Response with a list of subjects.
|
248
|
-
Available response fields can be found in our
|
249
|
-
[API Documentation](https://pangea.cloud/docs/api/authz#/v1/list-subjects).
|
250
|
-
|
251
|
-
Examples:
|
252
|
-
await authz.list_subjects(
|
253
|
-
resource=Resource(type="file", id="file_1"),
|
254
|
-
action="update",
|
255
|
-
)
|
256
|
-
"""
|
257
|
-
|
258
|
-
input_data = ListSubjectsRequest(resource=resource, action=action)
|
259
|
-
return await self.request.post("v1/list-subjects", ListSubjectsResult, data=input_data.dict(exclude_none=True))
|