pangea-sdk 3.8.0b1__tar.gz → 3.8.0b3__tar.gz
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_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/PKG-INFO +28 -3
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/README.md +27 -2
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/__init__.py +1 -1
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/__init__.py +2 -0
- pangea_sdk-3.8.0b3/pangea/asyncio/services/authz.py +267 -0
- pangea_sdk-3.8.0b3/pangea/asyncio/services/sanitize.py +185 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/share.py +39 -26
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/__init__.py +2 -0
- pangea_sdk-3.8.0b3/pangea/services/authz.py +377 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/file_scan.py +0 -1
- pangea_sdk-3.8.0b3/pangea/services/sanitize.py +275 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/share/share.py +39 -26
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pyproject.toml +1 -1
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/__init__.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/file_uploader.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/request.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/audit.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/authn.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/base.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/embargo.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/file_scan.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/intel.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/redact.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/asyncio/services/vault.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/audit_logger.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/config.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/deep_verify.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/deprecated.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/dump_audit.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/exceptions.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/file_uploader.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/py.typed +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/request.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/response.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/audit/audit.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/audit/exceptions.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/audit/models.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/audit/signing.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/audit/util.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/authn/authn.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/authn/models.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/base.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/embargo.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/intel.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/redact.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/share/file_format.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/vault/models/asymmetric.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/vault/models/common.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/vault/models/secret.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/vault/models/symmetric.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/services/vault/vault.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/tools.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/utils.py +0 -0
- {pangea_sdk-3.8.0b1 → pangea_sdk-3.8.0b3}/pangea/verify_audit.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: pangea-sdk
|
3
|
-
Version: 3.8.
|
3
|
+
Version: 3.8.0b3
|
4
4
|
Summary: Pangea API SDK
|
5
5
|
Home-page: https://pangea.cloud/docs/sdk/python/
|
6
6
|
License: MIT
|
@@ -44,6 +44,8 @@ above.
|
|
44
44
|
|
45
45
|
## Installation
|
46
46
|
|
47
|
+
#### GA releases
|
48
|
+
|
47
49
|
Via pip:
|
48
50
|
|
49
51
|
```bash
|
@@ -56,10 +58,32 @@ Via poetry:
|
|
56
58
|
$ poetry add pangea-sdk
|
57
59
|
```
|
58
60
|
|
61
|
+
<a name="beta-releases"></a>
|
62
|
+
|
63
|
+
#### Beta releases
|
64
|
+
|
65
|
+
Pre-release versions may be available with the `b` (beta) denotation in the
|
66
|
+
version number. These releases serve to preview beta services and APIs. Per
|
67
|
+
Semantic Versioning, they are considered unstable and do not carry the same
|
68
|
+
compatibility guarantees as stable releases. [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
|
69
|
+
|
70
|
+
Via pip:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
$ pip3 install pangea-sdk==3.8.0b3
|
74
|
+
```
|
75
|
+
|
76
|
+
Via poetry:
|
77
|
+
|
78
|
+
```bash
|
79
|
+
$ poetry add pangea-sdk==3.8.0b3
|
80
|
+
```
|
81
|
+
|
59
82
|
## Usage
|
60
83
|
|
61
84
|
- [Documentation][]
|
62
|
-
- [Examples][]
|
85
|
+
- [GA Examples][]
|
86
|
+
- [Beta Examples][]
|
63
87
|
|
64
88
|
General usage would be to create a token for a service through the
|
65
89
|
[Pangea Console][] and then construct an API client for that respective service.
|
@@ -213,7 +237,8 @@ It accepts multiple file formats:
|
|
213
237
|
|
214
238
|
|
215
239
|
[Documentation]: https://pangea.cloud/docs/sdk/python/
|
216
|
-
[Examples]: https://github.com/pangeacyber/pangea-python/tree/main/examples
|
240
|
+
[GA Examples]: https://github.com/pangeacyber/pangea-python/tree/main/examples
|
241
|
+
[Beta Examples]: https://github.com/pangeacyber/pangea-python/tree/beta/examples
|
217
242
|
[Pangea Console]: https://console.pangea.cloud/
|
218
243
|
[Slack]: https://pangea.cloud/join-slack/
|
219
244
|
[Secure Audit Log]: https://pangea.cloud/docs/audit
|
@@ -14,6 +14,8 @@ above.
|
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
|
+
#### GA releases
|
18
|
+
|
17
19
|
Via pip:
|
18
20
|
|
19
21
|
```bash
|
@@ -26,10 +28,32 @@ Via poetry:
|
|
26
28
|
$ poetry add pangea-sdk
|
27
29
|
```
|
28
30
|
|
31
|
+
<a name="beta-releases"></a>
|
32
|
+
|
33
|
+
#### Beta releases
|
34
|
+
|
35
|
+
Pre-release versions may be available with the `b` (beta) denotation in the
|
36
|
+
version number. These releases serve to preview beta services and APIs. Per
|
37
|
+
Semantic Versioning, they are considered unstable and do not carry the same
|
38
|
+
compatibility guarantees as stable releases. [Beta changelog](https://github.com/pangeacyber/pangea-python/blob/beta/CHANGELOG.md).
|
39
|
+
|
40
|
+
Via pip:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
$ pip3 install pangea-sdk==3.8.0b3
|
44
|
+
```
|
45
|
+
|
46
|
+
Via poetry:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
$ poetry add pangea-sdk==3.8.0b3
|
50
|
+
```
|
51
|
+
|
29
52
|
## Usage
|
30
53
|
|
31
54
|
- [Documentation][]
|
32
|
-
- [Examples][]
|
55
|
+
- [GA Examples][]
|
56
|
+
- [Beta Examples][]
|
33
57
|
|
34
58
|
General usage would be to create a token for a service through the
|
35
59
|
[Pangea Console][] and then construct an API client for that respective service.
|
@@ -183,7 +207,8 @@ It accepts multiple file formats:
|
|
183
207
|
|
184
208
|
|
185
209
|
[Documentation]: https://pangea.cloud/docs/sdk/python/
|
186
|
-
[Examples]: https://github.com/pangeacyber/pangea-python/tree/main/examples
|
210
|
+
[GA Examples]: https://github.com/pangeacyber/pangea-python/tree/main/examples
|
211
|
+
[Beta Examples]: https://github.com/pangeacyber/pangea-python/tree/beta/examples
|
187
212
|
[Pangea Console]: https://console.pangea.cloud/
|
188
213
|
[Slack]: https://pangea.cloud/join-slack/
|
189
214
|
[Secure Audit Log]: https://pangea.cloud/docs/audit
|
@@ -1,8 +1,10 @@
|
|
1
1
|
from .audit import AuditAsync
|
2
2
|
from .authn import AuthNAsync
|
3
|
+
from .authz import AuthZAsync
|
3
4
|
from .embargo import EmbargoAsync
|
4
5
|
from .file_scan import FileScanAsync
|
5
6
|
from .intel import DomainIntelAsync, FileIntelAsync, IpIntelAsync, UrlIntelAsync, UserIntelAsync
|
6
7
|
from .redact import RedactAsync
|
8
|
+
from .sanitize import SanitizeAsync
|
7
9
|
from .share import ShareAsync
|
8
10
|
from .vault import VaultAsync
|
@@ -0,0 +1,267 @@
|
|
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#/v1beta/tuple/create).
|
73
|
+
|
74
|
+
Examples:
|
75
|
+
await authz.tuple_create(
|
76
|
+
tuples=[
|
77
|
+
Tuple(
|
78
|
+
resource=Resource(namespace="file", id="file_1"),
|
79
|
+
relation="owner",
|
80
|
+
subject=Subject(namespace="user", id="user_1"),
|
81
|
+
)
|
82
|
+
]
|
83
|
+
)
|
84
|
+
"""
|
85
|
+
|
86
|
+
input_data = TupleCreateRequest(tuples=tuples)
|
87
|
+
return await self.request.post(
|
88
|
+
"v1beta/tuple/create", TupleCreateResult, data=input_data.dict(exclude_none=True)
|
89
|
+
)
|
90
|
+
|
91
|
+
async def tuple_list(
|
92
|
+
self,
|
93
|
+
filter: TupleListFilter,
|
94
|
+
size: Optional[int] = None,
|
95
|
+
last: Optional[str] = None,
|
96
|
+
order: Optional[ItemOrder] = None,
|
97
|
+
order_by: Optional[TupleOrderBy] = None,
|
98
|
+
) -> PangeaResponse[TupleListResult]:
|
99
|
+
"""List tuples. (Beta)
|
100
|
+
|
101
|
+
Return a paginated list of filtered tuples. The filter is given in terms
|
102
|
+
of a tuple. Fill out the fields that you want to filter. If the filter
|
103
|
+
is empty it will return all the tuples.
|
104
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
105
|
+
|
106
|
+
Args:
|
107
|
+
filter (TupleListFilter): The filter for listing tuples.
|
108
|
+
size (Optional[int]): The size of the result set. Default is None.
|
109
|
+
last (Optional[str]): The last token from a previous response. Default is None.
|
110
|
+
order (Optional[ItemOrder]): Order results asc(ending) or desc(ending).
|
111
|
+
order_by (Optional[TupleOrderBy]): Which field to order results by.
|
112
|
+
|
113
|
+
Raises:
|
114
|
+
PangeaAPIException: If an API Error happens.
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
Pangea Response with a list of tuples and the last token.
|
118
|
+
Available response fields can be found in our
|
119
|
+
[API Documentation](https://pangea.cloud/docs/api/authz#/v1beta/tuple/list).
|
120
|
+
|
121
|
+
Examples:
|
122
|
+
await authz.tuple_list(TupleListFilter(subject_namespace="user", subject_id="user_1"))
|
123
|
+
"""
|
124
|
+
input_data = TupleListRequest(
|
125
|
+
filter=filter.dict(exclude_none=True), size=size, last=last, order=order, order_by=order_by
|
126
|
+
)
|
127
|
+
return await self.request.post("v1beta/tuple/list", TupleListResult, data=input_data.dict(exclude_none=True))
|
128
|
+
|
129
|
+
async def tuple_delete(self, tuples: List[Tuple]) -> PangeaResponse[TupleDeleteResult]:
|
130
|
+
"""Delete tuples. (Beta)
|
131
|
+
|
132
|
+
Delete tuples in the AuthZ Service.
|
133
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
134
|
+
|
135
|
+
Args:
|
136
|
+
tuples (List[Tuple]): List of tuples to be deleted.
|
137
|
+
|
138
|
+
Raises:
|
139
|
+
PangeaAPIException: If an API Error happens.
|
140
|
+
|
141
|
+
Returns:
|
142
|
+
Pangea Response with empty result.
|
143
|
+
Available response fields can be found in our
|
144
|
+
[API Documentation](https://pangea.cloud/docs/api/authz#/v1beta/tuple/delete).
|
145
|
+
|
146
|
+
Examples:
|
147
|
+
await authz.tuple_delete(
|
148
|
+
tuples=[
|
149
|
+
Tuple(
|
150
|
+
resource=Resource(namespace="file", id="file_1"),
|
151
|
+
relation="owner",
|
152
|
+
subject=Subject(namespace="user", id="user_1"),
|
153
|
+
)
|
154
|
+
]
|
155
|
+
)
|
156
|
+
"""
|
157
|
+
|
158
|
+
input_data = TupleDeleteRequest(tuples=tuples)
|
159
|
+
return await self.request.post(
|
160
|
+
"v1beta/tuple/delete", TupleDeleteResult, data=input_data.dict(exclude_none=True)
|
161
|
+
)
|
162
|
+
|
163
|
+
async def check(
|
164
|
+
self,
|
165
|
+
resource: Resource,
|
166
|
+
action: str,
|
167
|
+
subject: Subject,
|
168
|
+
debug: Optional[bool] = None,
|
169
|
+
attributes: Optional[Dict[str, Union[int, str]]] = None,
|
170
|
+
) -> PangeaResponse[CheckResult]:
|
171
|
+
"""Perform a check request. (Beta)
|
172
|
+
|
173
|
+
Check if a subject has permission to perform an action on the resource.
|
174
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
175
|
+
|
176
|
+
Args:
|
177
|
+
resource (Resource): The resource to check.
|
178
|
+
action (str): The action to check.
|
179
|
+
subject (Subject): The subject to check.
|
180
|
+
debug (Optional[bool]): Setting this value to True will provide a detailed analysis of the check.
|
181
|
+
attributes (Optional[Dict[str, Union[int, str]]]): Additional attributes for the check.
|
182
|
+
|
183
|
+
Raises:
|
184
|
+
PangeaAPIException: If an API Error happens.
|
185
|
+
|
186
|
+
Returns:
|
187
|
+
Pangea Response with the result of the check.
|
188
|
+
Available response fields can be found in our
|
189
|
+
[API Documentation](https://pangea.cloud/docs/api/authz#/v1beta/check).
|
190
|
+
|
191
|
+
Examples:
|
192
|
+
await authz.check(
|
193
|
+
resource=Resource(namespace="file", id="file_1"),
|
194
|
+
action="update",
|
195
|
+
subject=Subject(namespace="user", id="user_1"),
|
196
|
+
debug=True,
|
197
|
+
)
|
198
|
+
"""
|
199
|
+
|
200
|
+
input_data = CheckRequest(resource=resource, action=action, subject=subject, debug=debug, attributes=attributes)
|
201
|
+
return await self.request.post("v1beta/check", CheckResult, data=input_data.dict(exclude_none=True))
|
202
|
+
|
203
|
+
async def list_resources(
|
204
|
+
self, namespace: str, action: str, subject: Subject
|
205
|
+
) -> PangeaResponse[ListResourcesResult]:
|
206
|
+
"""List resources. (Beta)
|
207
|
+
|
208
|
+
Given a namespace, action, and subject, list all the resources in the
|
209
|
+
namespace that the subject has access to the action with.
|
210
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
211
|
+
|
212
|
+
Args:
|
213
|
+
namespace (str): The namespace to filter resources.
|
214
|
+
action (str): The action to filter resources.
|
215
|
+
subject (Subject): The subject to filter resources.
|
216
|
+
|
217
|
+
Raises:
|
218
|
+
PangeaAPIException: If an API Error happens.
|
219
|
+
|
220
|
+
Returns:
|
221
|
+
Pangea Response with a list of resource IDs.
|
222
|
+
Available response fields can be found in our
|
223
|
+
[API Documentation](https://pangea.cloud/docs/api/authz#/v1beta/list-resources).
|
224
|
+
|
225
|
+
Examples:
|
226
|
+
await authz.list_resources(
|
227
|
+
namespace="file",
|
228
|
+
action="update",
|
229
|
+
subject=Subject(namespace="user", id="user_1"),
|
230
|
+
)
|
231
|
+
"""
|
232
|
+
|
233
|
+
input_data = ListResourcesRequest(namespace=namespace, action=action, subject=subject)
|
234
|
+
return await self.request.post(
|
235
|
+
"v1beta/list-resources", ListResourcesResult, data=input_data.dict(exclude_none=True)
|
236
|
+
)
|
237
|
+
|
238
|
+
async def list_subjects(self, resource: Resource, action: str) -> PangeaResponse[ListSubjectsResult]:
|
239
|
+
"""List subjects. (Beta)
|
240
|
+
|
241
|
+
Given a resource and an action, return the list of subjects who have
|
242
|
+
access to the action for the given resource.
|
243
|
+
How to install a [Beta release](https://pangea.cloud/docs/sdk/python/#beta-releases).
|
244
|
+
|
245
|
+
Args:
|
246
|
+
resource (Resource): The resource to filter subjects.
|
247
|
+
action (str): The action to filter subjects.
|
248
|
+
|
249
|
+
Raises:
|
250
|
+
PangeaAPIException: If an API Error happens.
|
251
|
+
|
252
|
+
Returns:
|
253
|
+
Pangea Response with a list of subjects.
|
254
|
+
Available response fields can be found in our
|
255
|
+
[API Documentation](https://pangea.cloud/docs/api/authz#/v1beta/list-subjects).
|
256
|
+
|
257
|
+
Examples:
|
258
|
+
await authz.list_subjects(
|
259
|
+
resource=Resource(namespace="file", id="file_1"),
|
260
|
+
action="update",
|
261
|
+
)
|
262
|
+
"""
|
263
|
+
|
264
|
+
input_data = ListSubjectsRequest(resource=resource, action=action)
|
265
|
+
return await self.request.post(
|
266
|
+
"v1beta/list-subjects", ListSubjectsResult, data=input_data.dict(exclude_none=True)
|
267
|
+
)
|
@@ -0,0 +1,185 @@
|
|
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)
|