prelude-sdk-beta 1406__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.

Potentially problematic release.


This version of prelude-sdk-beta might be problematic. Click here for more details.

@@ -0,0 +1,278 @@
1
+ from prelude_sdk_beta.controllers.http_controller import HttpController
2
+ from prelude_sdk_beta.models.account import verify_credentials
3
+ from prelude_sdk_beta.models.codes import Mode, Permission
4
+
5
+
6
+ class IAMAccountController(HttpController):
7
+
8
+ def __init__(self, account):
9
+ super().__init__(account)
10
+
11
+ @verify_credentials
12
+ def get_account(self):
13
+ """Get account properties"""
14
+ res = self.get(
15
+ f"{self.account.hq}/iam/account", headers=self.account.headers, timeout=10
16
+ )
17
+ return res.json()
18
+
19
+ @verify_credentials
20
+ def purge_account(self):
21
+ """Delete an account and all things in it"""
22
+ res = self.delete(
23
+ f"{self.account.hq}/iam/account", headers=self.account.headers, timeout=10
24
+ )
25
+ return res.json()
26
+
27
+ @verify_credentials
28
+ def update_account(self, mode: Mode = None, company: str = None, slug: str = None):
29
+ """Update properties on an account"""
30
+ body = dict()
31
+ if mode is not None:
32
+ body["mode"] = mode.name
33
+ if company is not None:
34
+ body["company"] = company
35
+ if slug is not None:
36
+ body["slug"] = slug
37
+
38
+ res = self.put(
39
+ f"{self.account.hq}/iam/account",
40
+ headers=self.account.headers,
41
+ json=body,
42
+ timeout=10,
43
+ )
44
+ return res.json()
45
+
46
+ @verify_credentials
47
+ def attach_oidc(
48
+ self,
49
+ client_id: str,
50
+ client_secret: str,
51
+ issuer: str,
52
+ oidc_url: str,
53
+ ):
54
+ """Attach OIDC to an account"""
55
+ email_attr = "email"
56
+ if issuer == "azure":
57
+ email_attr = "upn"
58
+ body = dict(
59
+ client_id=client_id,
60
+ client_secret=client_secret,
61
+ email_attr=email_attr,
62
+ issuer=issuer,
63
+ oidc_url=oidc_url,
64
+ )
65
+
66
+ res = self.post(
67
+ f"{self.account.hq}/iam/account/oidc",
68
+ headers=self.account.headers,
69
+ json=body,
70
+ timeout=10,
71
+ )
72
+ return res.json()
73
+
74
+ @verify_credentials
75
+ def detach_oidc(self):
76
+ """Detach OIDC to an account"""
77
+ res = self.delete(
78
+ f"{self.account.hq}/iam/account/oidc",
79
+ headers=self.account.headers,
80
+ timeout=10,
81
+ )
82
+ return res.json()
83
+
84
+ @verify_credentials
85
+ def invite_user(
86
+ self,
87
+ email: str,
88
+ oidc: str | None,
89
+ permission: Permission,
90
+ name: str | None = None,
91
+ ):
92
+ """Invite a new user to the account"""
93
+ body = dict(permission=permission.name, handle=email, oidc=oidc)
94
+ if name:
95
+ body["name"] = name
96
+
97
+ res = self.post(
98
+ url=f"{self.account.hq}/iam/account/user",
99
+ json=body,
100
+ headers=self.account.headers,
101
+ timeout=10,
102
+ )
103
+ return res.json()
104
+
105
+ @verify_credentials
106
+ def create_service_user(self, name: str):
107
+ """Create a service user"""
108
+ body = dict(name=name)
109
+
110
+ res = self.post(
111
+ f"{self.account.hq}/iam/account/service_user",
112
+ json=body,
113
+ headers=self.account.headers,
114
+ timeout=10,
115
+ )
116
+ return res.json()
117
+
118
+ @verify_credentials
119
+ def delete_service_user(self, handle: str):
120
+ """Delete service user"""
121
+ body = dict(handle=handle)
122
+
123
+ res = self.delete(
124
+ f"{self.account.hq}/iam/account/service_user",
125
+ json=body,
126
+ headers=self.account.headers,
127
+ timeout=10,
128
+ )
129
+ return res.json()
130
+
131
+ @verify_credentials
132
+ def update_account_user(
133
+ self,
134
+ email: str,
135
+ oidc: str | None,
136
+ permission: Permission = None,
137
+ ):
138
+ """Update properties on an account user"""
139
+ body = dict(handle=email, oidc=oidc)
140
+ if permission is not None:
141
+ body["permission"] = permission.name
142
+
143
+ res = self.put(
144
+ f"{self.account.hq}/iam/account/user",
145
+ json=body,
146
+ headers=self.account.headers,
147
+ timeout=10,
148
+ )
149
+ return res.json()
150
+
151
+ @verify_credentials
152
+ def remove_user(self, email: str, oidc: str | None):
153
+ """Remove user from the account"""
154
+ params = dict(handle=email, oidc=oidc)
155
+
156
+ res = self.delete(
157
+ f"{self.account.hq}/iam/account/user",
158
+ params=params,
159
+ headers=self.account.headers,
160
+ timeout=10,
161
+ )
162
+ return res.json()
163
+
164
+ @verify_credentials
165
+ def audit_logs(self, days: int = 7, limit: int = 1000):
166
+ """Get audit logs from the last X days"""
167
+ params = dict(days=days, limit=limit)
168
+ res = self.get(
169
+ f"{self.account.hq}/iam/audit",
170
+ headers=self.account.headers,
171
+ params=params,
172
+ timeout=30,
173
+ )
174
+ return res.json()
175
+
176
+
177
+ def sign_up(self, company, email, name):
178
+ """(NOT AVAIABLE IN PRODUCTION) Create a new user and account"""
179
+ body = dict(company=company, email=email, name=name)
180
+
181
+ res = self._session.post(
182
+ f"{self.account.hq}/iam/new_user_and_account",
183
+ headers=self.account.headers,
184
+ json=body,
185
+ timeout=20,
186
+ )
187
+ data = res.json()
188
+ if self.account.profile:
189
+ self.account.keychain.configure_keychain(
190
+ account=data["account_id"],
191
+ handle=data["user_id"],
192
+ hq=self.account.hq,
193
+ profile=self.account.profile,
194
+ )
195
+ return data
196
+
197
+
198
+ class IAMUserController(HttpController):
199
+
200
+ def __init__(self, account):
201
+ super().__init__(account)
202
+
203
+ @verify_credentials
204
+ def list_accounts(self):
205
+ """List all accounts for your user"""
206
+ res = self.get(
207
+ f"{self.account.hq}/iam/user/account",
208
+ headers=self.account.headers,
209
+ timeout=10,
210
+ )
211
+ return res.json()
212
+
213
+ @verify_credentials
214
+ def purge_user(self):
215
+ """Delete your user"""
216
+ res = self.delete(
217
+ f"{self.account.hq}/iam/user", headers=self.account.headers, timeout=10
218
+ )
219
+ return res.json()
220
+
221
+ @verify_credentials
222
+ def update_user(
223
+ self,
224
+ name: str = None,
225
+ ):
226
+ """Update properties on a user"""
227
+ body = dict()
228
+ if name is not None:
229
+ body["name"] = name
230
+
231
+ res = self.put(
232
+ f"{self.account.hq}/iam/user",
233
+ json=body,
234
+ headers=self.account.headers,
235
+ timeout=10,
236
+ )
237
+ return res.json()
238
+
239
+ def forgot_password(self):
240
+ """Send a forgot password email"""
241
+ body = dict(handle=self.account.handle)
242
+
243
+ res = self.post(
244
+ f"{self.account.hq}/iam/user/forgot_password",
245
+ json=body,
246
+ headers=self.account.headers,
247
+ timeout=10,
248
+ )
249
+ return res.json()
250
+
251
+ def confirm_forgot_password(self, confirmation_code: str, new_password: str):
252
+ """Change a password using confirmation code"""
253
+ body = dict(
254
+ handle=self.account.handle,
255
+ confirmation_code=confirmation_code,
256
+ password=new_password,
257
+ )
258
+
259
+ res = self.post(
260
+ f"{self.account.hq}/iam/user/forgot_password",
261
+ json=body,
262
+ headers=self.account.headers,
263
+ timeout=10,
264
+ )
265
+ return res.json()
266
+
267
+ @verify_credentials
268
+ def change_password(self, current_password: str, new_password: str):
269
+ """Change your password"""
270
+ body = dict(current_password=current_password, new_password=new_password)
271
+
272
+ res = self.post(
273
+ f"{self.account.hq}/iam/user/change_password",
274
+ json=body,
275
+ headers=self.account.headers,
276
+ timeout=10,
277
+ )
278
+ return res.json()
@@ -0,0 +1,26 @@
1
+ from prelude_sdk_beta.controllers.http_controller import HttpController
2
+ from prelude_sdk_beta.models.account import verify_credentials
3
+
4
+
5
+ class JobsController(HttpController):
6
+
7
+ def __init__(self, account):
8
+ super().__init__(account)
9
+
10
+ @verify_credentials
11
+ def job_statuses(self):
12
+ """Get job statuses"""
13
+ res = self.get(
14
+ f"{self.account.hq}/jobs/statuses", headers=self.account.headers, timeout=30
15
+ )
16
+ return res.json()
17
+
18
+ @verify_credentials
19
+ def job_status(self, job_id: str):
20
+ """Get job status given job ID"""
21
+ res = self.get(
22
+ f"{self.account.hq}/jobs/statuses/{job_id}",
23
+ headers=self.account.headers,
24
+ timeout=30,
25
+ )
26
+ return res.json()
@@ -0,0 +1,166 @@
1
+ from datetime import datetime, timezone
2
+
3
+ from prelude_sdk_beta.controllers.http_controller import HttpController
4
+ from prelude_sdk_beta.models.account import verify_credentials
5
+ from prelude_sdk_beta.models.codes import Control
6
+
7
+
8
+ class PartnerController(HttpController):
9
+
10
+ def __init__(self, account):
11
+ super().__init__(account)
12
+
13
+ @verify_credentials
14
+ def attach(
15
+ self,
16
+ partner: Control,
17
+ api: str,
18
+ user: str,
19
+ secret: str,
20
+ name: str | None = None,
21
+ instance_id: str | None = None,
22
+ ):
23
+ """Attach a partner to your account"""
24
+ params = dict()
25
+ if name:
26
+ params["name"] = name
27
+ if api:
28
+ params["api"] = api
29
+ if user:
30
+ params["user"] = user
31
+ if secret:
32
+ params["secret"] = secret
33
+ extra = f"/{instance_id}" if instance_id else ""
34
+ res = self.post(
35
+ f"{self.account.hq}/partner/{partner.name}{extra}",
36
+ headers=self.account.headers,
37
+ json=params,
38
+ timeout=10,
39
+ )
40
+ return res.json()
41
+
42
+ @verify_credentials
43
+ def detach(self, partner: Control, instance_id: str):
44
+ """Detach a partner from your Detect account"""
45
+ res = self.delete(
46
+ f"{self.account.hq}/partner/{partner.name}/{instance_id}",
47
+ headers=self.account.headers,
48
+ timeout=10,
49
+ )
50
+ return res.json()
51
+
52
+ @verify_credentials
53
+ def block(self, partner: Control, test_id: str):
54
+ """Report to a partner to block a test"""
55
+ params = dict(test_id=test_id)
56
+ res = self.post(
57
+ f"{self.account.hq}/partner/block/{partner.name}",
58
+ headers=self.account.headers,
59
+ json=params,
60
+ timeout=30,
61
+ )
62
+ return res.json()
63
+
64
+ @verify_credentials
65
+ def endpoints(
66
+ self,
67
+ partner: Control,
68
+ platform: str,
69
+ hostname: str = "",
70
+ offset: int = 0,
71
+ count: int = 100,
72
+ ):
73
+ """Get a list of endpoints from a partner"""
74
+ params = dict(platform=platform, hostname=hostname, offset=offset, count=count)
75
+ res = self.get(
76
+ f"{self.account.hq}/partner/endpoints/{partner.name}",
77
+ headers=self.account.headers,
78
+ params=params,
79
+ timeout=30,
80
+ )
81
+ return res.json()
82
+
83
+ @verify_credentials
84
+ def deploy(self, partner: Control, host_ids: list):
85
+ """Deploy probes on all specified partner endpoints"""
86
+ params = dict(host_ids=host_ids)
87
+ res = self.post(
88
+ f"{self.account.hq}/partner/deploy/{partner.name}",
89
+ headers=self.account.headers,
90
+ json=params,
91
+ timeout=30,
92
+ )
93
+ return res.json()
94
+
95
+ @verify_credentials
96
+ def list_reports(self, partner: Control, test_id: str | None):
97
+ """Get reports to a partner for a test"""
98
+ params = dict(test_id=test_id) if test_id else dict()
99
+ res = self.get(
100
+ f"{self.account.hq}/partner/reports/{partner.name}",
101
+ headers=self.account.headers,
102
+ json=params,
103
+ timeout=30,
104
+ )
105
+ return res.json()
106
+
107
+ @verify_credentials
108
+ def ioa_stats(self, test_id: str | None = None):
109
+ """Get IOA stats"""
110
+ params = dict(test_id=test_id) if test_id else dict()
111
+ res = self.get(
112
+ f"{self.account.hq}/partner/ioa_stats",
113
+ headers=self.account.headers,
114
+ json=params,
115
+ timeout=30,
116
+ )
117
+ return res.json()
118
+
119
+ @verify_credentials
120
+ def observed_detected(self, test_id: str | None = None, hours: int | None = None):
121
+ """Get observed_detected stats"""
122
+ params = dict()
123
+ if test_id:
124
+ params["test_id"] = test_id
125
+ if hours:
126
+ params["start_epoch_ms"] = (
127
+ datetime.now(timezone.utc).timestamp() - hours * 60 * 60
128
+ ) * 1000
129
+
130
+ res = self.get(
131
+ f"{self.account.hq}/partner/observed_detected",
132
+ headers=self.account.headers,
133
+ json=params,
134
+ timeout=30,
135
+ )
136
+ return res.json()
137
+
138
+ @verify_credentials
139
+ def list_advisories(
140
+ self, partner: Control, start: str = None, limit: int = None, offset: int = None
141
+ ):
142
+ """Get advisory reports provided by a partner"""
143
+ params = dict()
144
+ if start:
145
+ params["start"] = start
146
+ if limit:
147
+ params["limit"] = limit
148
+ if offset:
149
+ params["offset"] = offset
150
+ res = self.get(
151
+ f"{self.account.hq}/partner/advisories/{partner.name}",
152
+ headers=self.account.headers,
153
+ params=params,
154
+ timeout=30,
155
+ )
156
+ return res.json()
157
+
158
+ @verify_credentials
159
+ def partner_groups(self, partner: Control, instance_id: str):
160
+ """Get a list of partner groups"""
161
+ res = self.get(
162
+ f"{self.account.hq}/partner/groups/{partner.name}/{instance_id}",
163
+ headers=self.account.headers,
164
+ timeout=30,
165
+ )
166
+ return res.json()
@@ -0,0 +1,14 @@
1
+ from prelude_sdk_beta.controllers.http_controller import HttpController
2
+
3
+
4
+ class ProbeController(HttpController):
5
+
6
+ def __init__(self, account):
7
+ super().__init__(account)
8
+
9
+ def download(self, name: str, dos: str):
10
+ """Download a probe executable"""
11
+ res = self.get(
12
+ f"{self.account.hq}/download/{name}", headers=dict(dos=dos), timeout=10
13
+ )
14
+ return res.text