|
2 | 2 | from typing import List, Dict, Any, Optional |
3 | 3 | from ..exception import AppwriteException |
4 | 4 | from appwrite.utils.deprecated import deprecated |
| 5 | +from ..enums.scopes import Scopes; |
5 | 6 | from ..enums.authenticator_type import AuthenticatorType; |
6 | 7 | from ..enums.authentication_factor import AuthenticationFactor; |
7 | 8 | from ..enums.o_auth_provider import OAuthProvider; |
@@ -215,6 +216,186 @@ def create_jwt(self, duration: Optional[float] = None) -> Dict[str, Any]: |
215 | 216 | 'content-type': 'application/json', |
216 | 217 | }, api_params) |
217 | 218 |
|
| 219 | + def list_keys(self, total: Optional[bool] = None) -> Dict[str, Any]: |
| 220 | + """ |
| 221 | + Get a list of all API keys from the current account. |
| 222 | +
|
| 223 | + Parameters |
| 224 | + ---------- |
| 225 | + total : Optional[bool] |
| 226 | + When set to false, the total count returned will be 0 and will not be calculated. |
| 227 | + |
| 228 | + Returns |
| 229 | + ------- |
| 230 | + Dict[str, Any] |
| 231 | + API response as a dictionary |
| 232 | + |
| 233 | + Raises |
| 234 | + ------ |
| 235 | + AppwriteException |
| 236 | + If API request fails |
| 237 | + """ |
| 238 | + |
| 239 | + api_path = '/account/keys' |
| 240 | + api_params = {} |
| 241 | + |
| 242 | + if total is not None: |
| 243 | + api_params['total'] = total |
| 244 | + |
| 245 | + return self.client.call('get', api_path, { |
| 246 | + }, api_params) |
| 247 | + |
| 248 | + def create_key(self, name: str, scopes: List[Scopes], expire: Optional[str] = None) -> Dict[str, Any]: |
| 249 | + """ |
| 250 | + Create a new account API key. |
| 251 | +
|
| 252 | + Parameters |
| 253 | + ---------- |
| 254 | + name : str |
| 255 | + Key name. Max length: 128 chars. |
| 256 | + scopes : List[Scopes] |
| 257 | + Key scopes list. Maximum of 100 scopes are allowed. |
| 258 | + expire : Optional[str] |
| 259 | + Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration. |
| 260 | + |
| 261 | + Returns |
| 262 | + ------- |
| 263 | + Dict[str, Any] |
| 264 | + API response as a dictionary |
| 265 | + |
| 266 | + Raises |
| 267 | + ------ |
| 268 | + AppwriteException |
| 269 | + If API request fails |
| 270 | + """ |
| 271 | + |
| 272 | + api_path = '/account/keys' |
| 273 | + api_params = {} |
| 274 | + if name is None: |
| 275 | + raise AppwriteException('Missing required parameter: "name"') |
| 276 | + |
| 277 | + if scopes is None: |
| 278 | + raise AppwriteException('Missing required parameter: "scopes"') |
| 279 | + |
| 280 | + |
| 281 | + api_params['name'] = name |
| 282 | + api_params['scopes'] = scopes |
| 283 | + api_params['expire'] = expire |
| 284 | + |
| 285 | + return self.client.call('post', api_path, { |
| 286 | + 'content-type': 'application/json', |
| 287 | + }, api_params) |
| 288 | + |
| 289 | + def get_key(self, key_id: str) -> Dict[str, Any]: |
| 290 | + """ |
| 291 | + Get a key by its unique ID. This endpoint returns details about a specific API key in your account including it's scopes. |
| 292 | +
|
| 293 | + Parameters |
| 294 | + ---------- |
| 295 | + key_id : str |
| 296 | + Key unique ID. |
| 297 | + |
| 298 | + Returns |
| 299 | + ------- |
| 300 | + Dict[str, Any] |
| 301 | + API response as a dictionary |
| 302 | + |
| 303 | + Raises |
| 304 | + ------ |
| 305 | + AppwriteException |
| 306 | + If API request fails |
| 307 | + """ |
| 308 | + |
| 309 | + api_path = '/account/keys/{keyId}' |
| 310 | + api_params = {} |
| 311 | + if key_id is None: |
| 312 | + raise AppwriteException('Missing required parameter: "key_id"') |
| 313 | + |
| 314 | + api_path = api_path.replace('{keyId}', key_id) |
| 315 | + |
| 316 | + |
| 317 | + return self.client.call('get', api_path, { |
| 318 | + }, api_params) |
| 319 | + |
| 320 | + def update_key(self, key_id: str, name: str, scopes: List[Scopes], expire: Optional[str] = None) -> Dict[str, Any]: |
| 321 | + """ |
| 322 | + Update a key by its unique ID. Use this endpoint to update the name, scopes, or expiration time of an API key. |
| 323 | +
|
| 324 | + Parameters |
| 325 | + ---------- |
| 326 | + key_id : str |
| 327 | + Key unique ID. |
| 328 | + name : str |
| 329 | + Key name. Max length: 128 chars. |
| 330 | + scopes : List[Scopes] |
| 331 | + Key scopes list. Maximum of 100 scopes are allowed. |
| 332 | + expire : Optional[str] |
| 333 | + Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration. |
| 334 | + |
| 335 | + Returns |
| 336 | + ------- |
| 337 | + Dict[str, Any] |
| 338 | + API response as a dictionary |
| 339 | + |
| 340 | + Raises |
| 341 | + ------ |
| 342 | + AppwriteException |
| 343 | + If API request fails |
| 344 | + """ |
| 345 | + |
| 346 | + api_path = '/account/keys/{keyId}' |
| 347 | + api_params = {} |
| 348 | + if key_id is None: |
| 349 | + raise AppwriteException('Missing required parameter: "key_id"') |
| 350 | + |
| 351 | + if name is None: |
| 352 | + raise AppwriteException('Missing required parameter: "name"') |
| 353 | + |
| 354 | + if scopes is None: |
| 355 | + raise AppwriteException('Missing required parameter: "scopes"') |
| 356 | + |
| 357 | + api_path = api_path.replace('{keyId}', key_id) |
| 358 | + |
| 359 | + api_params['name'] = name |
| 360 | + api_params['scopes'] = scopes |
| 361 | + api_params['expire'] = expire |
| 362 | + |
| 363 | + return self.client.call('put', api_path, { |
| 364 | + 'content-type': 'application/json', |
| 365 | + }, api_params) |
| 366 | + |
| 367 | + def delete_key(self, key_id: str) -> Dict[str, Any]: |
| 368 | + """ |
| 369 | + Delete a key by its unique ID. Once deleted, the key can no longer be used to authenticate API calls. |
| 370 | +
|
| 371 | + Parameters |
| 372 | + ---------- |
| 373 | + key_id : str |
| 374 | + Key unique ID. |
| 375 | + |
| 376 | + Returns |
| 377 | + ------- |
| 378 | + Dict[str, Any] |
| 379 | + API response as a dictionary |
| 380 | + |
| 381 | + Raises |
| 382 | + ------ |
| 383 | + AppwriteException |
| 384 | + If API request fails |
| 385 | + """ |
| 386 | + |
| 387 | + api_path = '/account/keys/{keyId}' |
| 388 | + api_params = {} |
| 389 | + if key_id is None: |
| 390 | + raise AppwriteException('Missing required parameter: "key_id"') |
| 391 | + |
| 392 | + api_path = api_path.replace('{keyId}', key_id) |
| 393 | + |
| 394 | + |
| 395 | + return self.client.call('delete', api_path, { |
| 396 | + 'content-type': 'application/json', |
| 397 | + }, api_params) |
| 398 | + |
218 | 399 | def list_logs(self, queries: Optional[List[str]] = None, total: Optional[bool] = None) -> Dict[str, Any]: |
219 | 400 | """ |
220 | 401 | Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log. |
@@ -1228,7 +1409,7 @@ def create_o_auth2_token(self, provider: OAuthProvider, success: Optional[str] = |
1228 | 1409 | Parameters |
1229 | 1410 | ---------- |
1230 | 1411 | provider : OAuthProvider |
1231 | | - OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom. |
| 1412 | + OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom, githubImagine, googleImagine. |
1232 | 1413 | success : Optional[str] |
1233 | 1414 | URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. |
1234 | 1415 | failure : Optional[str] |
|
0 commit comments