python-vaultwarden2 0.1.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.
vaultwarden2/models.py ADDED
@@ -0,0 +1,842 @@
1
+ """Data models: decrypted vault items, folders, organizations, accounts and their enums.
2
+
3
+ All models are frozen dataclasses: change them with ``dataclasses.replace``. Enum-typed attributes hold the enum
4
+ member when the server value is known and the plain int otherwise, so new server-side values never break reading.
5
+ Secrets (passwords, card numbers, private keys, TOTP seeds, hidden fields) are left out of ``repr()``.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass, field
11
+ from enum import IntEnum
12
+ from typing import TYPE_CHECKING, Any, TypeAlias
13
+
14
+ from vaultwarden2.errors import TotpError
15
+ from vaultwarden2.totp import totp_code
16
+
17
+ if TYPE_CHECKING:
18
+ from datetime import datetime
19
+
20
+ from vaultwarden2.totp import TotpCode
21
+
22
+
23
+ class CipherType(IntEnum):
24
+ """Type of a vault item.
25
+
26
+ Attributes:
27
+ LOGIN: Username, password, URIs, TOTP seed and passkeys (``Cipher.login``).
28
+ SECURE_NOTE: Free text in ``Cipher.notes``.
29
+ CARD: Payment card (``Cipher.card``).
30
+ IDENTITY: Personal details (``Cipher.identity``).
31
+ SSH_KEY: SSH key pair (``Cipher.ssh_key``).
32
+ BANK_ACCOUNT: Bank account; its fields are in ``Cipher.data``.
33
+ DRIVERS_LICENSE: Driver's license; its fields are in ``Cipher.data``.
34
+ PASSPORT: Passport; its fields are in ``Cipher.data``.
35
+ """
36
+
37
+ LOGIN = 1
38
+ SECURE_NOTE = 2
39
+ CARD = 3
40
+ IDENTITY = 4
41
+ SSH_KEY = 5
42
+ BANK_ACCOUNT = 6
43
+ DRIVERS_LICENSE = 7
44
+ PASSPORT = 8
45
+
46
+
47
+ class FieldType(IntEnum):
48
+ """Type of a custom field.
49
+
50
+ Attributes:
51
+ TEXT: Plain text, shown openly.
52
+ HIDDEN: Secret text, masked in the clients.
53
+ BOOLEAN: A checkbox (``'true'`` / ``'false'``).
54
+ LINKED: Linked to a built-in field of the item (see ``CustomField.linked_id``).
55
+ """
56
+
57
+ TEXT = 0
58
+ HIDDEN = 1
59
+ BOOLEAN = 2
60
+ LINKED = 3
61
+
62
+
63
+ class UriMatch(IntEnum):
64
+ """How a login URI is matched against a website (autofill rules of the official apps).
65
+
66
+ Attributes:
67
+ DOMAIN: Same base domain (``login.example.com`` matches ``example.com``). The default when unset.
68
+ HOST: Same host name and port.
69
+ STARTS_WITH: The website URL starts with the stored URI.
70
+ EXACT: The website URL equals the stored URI.
71
+ REGEX: The stored URI is a regular expression matched against the website URL.
72
+ NEVER: Never matched (excluded from autofill).
73
+ """
74
+
75
+ DOMAIN = 0
76
+ HOST = 1
77
+ STARTS_WITH = 2
78
+ EXACT = 3
79
+ REGEX = 4
80
+ NEVER = 5
81
+
82
+
83
+ class RepromptType(IntEnum):
84
+ """Whether the official apps ask for the master password again before showing an item's secrets.
85
+
86
+ Attributes:
87
+ NONE: No re-prompt.
88
+ PASSWORD: Ask for the master password.
89
+ """
90
+
91
+ NONE = 0
92
+ PASSWORD = 1
93
+
94
+
95
+ class OrganizationUserType(IntEnum):
96
+ """Role of a user in an organization.
97
+
98
+ Attributes:
99
+ OWNER: Full control, including billing, deleting the organization and managing owners.
100
+ ADMIN: Manages members, collections, groups and policies; sees all collections.
101
+ USER: Uses the collections assigned to them.
102
+ MANAGER: Manages the collections assigned to them.
103
+ CUSTOM: Custom permissions. vaultwarden stores this role as ``MANAGER`` (only "manage all collections" is
104
+ kept, as access to all collections) and reports every manager as ``CUSTOM``.
105
+ """
106
+
107
+ OWNER = 0
108
+ ADMIN = 1
109
+ USER = 2
110
+ MANAGER = 3
111
+ CUSTOM = 4
112
+
113
+
114
+ class PolicyType(IntEnum):
115
+ """Organization policies supported by vaultwarden.
116
+
117
+ Attributes:
118
+ TWO_FACTOR_AUTHENTICATION: Requires members to have two-step login enabled; vaultwarden revokes members
119
+ without it.
120
+ MASTER_PASSWORD: Sets minimum requirements for members' master passwords.
121
+ PASSWORD_GENERATOR: Sets minimum requirements for the password generator.
122
+ SINGLE_ORG: Restricts members to being part of a single organization.
123
+ PERSONAL_OWNERSHIP: Forces newly added or cloned items to be owned by the organization rather than the
124
+ member's personal vault.
125
+ DISABLE_SEND: Members may not create Sends.
126
+ SEND_OPTIONS: Sets options for Sends.
127
+ RESET_PASSWORD: Allows administrators to recover member accounts.
128
+ REMOVE_UNLOCK_WITH_PIN: Prevents members from unlocking the app with a PIN.
129
+ RESTRICTED_ITEM_TYPES: Restricts the item types members can create.
130
+ URI_MATCH_DEFAULTS: Sets the default URI match detection for autofill.
131
+ AUTOTYPE_DEFAULT_SETTING: Sets the default behaviour of the autotype feature.
132
+ ORGANIZATION_USER_NOTIFICATION: Displays an organization-configured banner message to members in their vault.
133
+ FILL_ASSIST: Enables the Fill Assist autofill engine as default for members; vaultwarden requires the single
134
+ organization policy first.
135
+ """
136
+
137
+ TWO_FACTOR_AUTHENTICATION = 0
138
+ MASTER_PASSWORD = 1
139
+ PASSWORD_GENERATOR = 2
140
+ SINGLE_ORG = 3
141
+ PERSONAL_OWNERSHIP = 5
142
+ DISABLE_SEND = 6
143
+ SEND_OPTIONS = 7
144
+ RESET_PASSWORD = 8
145
+ REMOVE_UNLOCK_WITH_PIN = 14
146
+ RESTRICTED_ITEM_TYPES = 15
147
+ URI_MATCH_DEFAULTS = 16
148
+ AUTOTYPE_DEFAULT_SETTING = 17
149
+ ORGANIZATION_USER_NOTIFICATION = 20
150
+ FILL_ASSIST = 22
151
+
152
+
153
+ class TwoFactorProvider(IntEnum):
154
+ """Two-step login methods.
155
+
156
+ Attributes:
157
+ AUTHENTICATOR: An authenticator app (TOTP).
158
+ EMAIL: Codes sent by email.
159
+ DUO: Duo Security.
160
+ YUBIKEY: YubiKey OTP.
161
+ U2F: Legacy U2F security keys.
162
+ REMEMBER: A "remember me" token for a device that passed two-step login before.
163
+ ORGANIZATION_DUO: Duo configured by an organization.
164
+ WEBAUTHN: FIDO2 / WebAuthn security keys.
165
+ RECOVERY_CODE: The recovery code; using it turns two-step login off.
166
+ """
167
+
168
+ AUTHENTICATOR = 0
169
+ EMAIL = 1
170
+ DUO = 2
171
+ YUBIKEY = 3
172
+ U2F = 4
173
+ REMEMBER = 5
174
+ ORGANIZATION_DUO = 6
175
+ WEBAUTHN = 7
176
+ RECOVERY_CODE = 8
177
+
178
+
179
+ class MemberStatus(IntEnum):
180
+ """State of an organization membership.
181
+
182
+ Attributes:
183
+ REVOKED: Access revoked by an admin; the membership is kept and can be restored.
184
+ INVITED: Invited, the user has not accepted yet.
185
+ ACCEPTED: Accepted, waiting for an admin to confirm (and share the organization key).
186
+ CONFIRMED: Full member with access to the organization key.
187
+ """
188
+
189
+ REVOKED = -1
190
+ INVITED = 0
191
+ ACCEPTED = 1
192
+ CONFIRMED = 2
193
+
194
+
195
+ def _raw() -> Any:
196
+ """A dataclass field for the original server JSON: not part of ``repr()``, equality or hashing.
197
+
198
+ Returns:
199
+ The field definition.
200
+ """
201
+ return field(default_factory=dict, repr=False, compare=False, hash=False)
202
+
203
+
204
+ @dataclass(frozen=True, slots=True, kw_only=True)
205
+ class LoginUri:
206
+ """A website or app a login belongs to.
207
+
208
+ Attributes:
209
+ uri: The address, for example ``https://github.com/login`` (decrypted).
210
+ match: The match rule; None means the default (base domain).
211
+ """
212
+
213
+ uri: str | None
214
+ match: UriMatch | int | None = None
215
+
216
+
217
+ @dataclass(frozen=True, slots=True, kw_only=True)
218
+ class Login:
219
+ """The login part of an item.
220
+
221
+ Attributes:
222
+ username: The username.
223
+ password: The password.
224
+ totp: The TOTP seed (base32 secret, ``otpauth://totp/...`` or ``steam://...``). See ``has_totp`` and
225
+ ``totp_code``.
226
+ uris: The websites or apps the login belongs to.
227
+ password_revision_date: When the password last changed.
228
+ fido2_credentials: Passkeys, decrypted, with the keys as the server stores them (camelCase). Kept
229
+ byte for byte on updates unless changed.
230
+ """
231
+
232
+ username: str | None = None
233
+ password: str | None = field(default=None, repr=False)
234
+ totp: str | None = field(default=None, repr=False)
235
+ uris: tuple[LoginUri, ...] = ()
236
+ password_revision_date: datetime | None = None
237
+ fido2_credentials: tuple[dict[str, Any], ...] = field(default=(), repr=False, compare=False, hash=False)
238
+
239
+ @property
240
+ def has_totp(self) -> bool:
241
+ """Whether a TOTP seed is stored.
242
+
243
+ Returns:
244
+ True if ``totp`` holds a non-empty seed.
245
+ """
246
+ return bool(self.totp and self.totp.strip())
247
+
248
+ def totp_code(self, at: datetime | float | None = None) -> TotpCode:
249
+ """The one-time code for the stored TOTP seed, computed locally.
250
+
251
+ Args:
252
+ at: The moment to compute the code for: a timezone-aware datetime or a Unix timestamp. Defaults to now.
253
+
254
+ Returns:
255
+ The code with its remaining validity; ``str(result)`` is the code itself.
256
+
257
+ Raises:
258
+ TotpError: No seed is stored, or the seed is malformed or unsupported (counter-based HOTP).
259
+
260
+ Example:
261
+ ```python
262
+ if item.login.has_totp:
263
+ code = item.login.totp_code()
264
+ print(code.code, f'{code.remaining}s left')
265
+ ```
266
+ """
267
+ if not self.totp or not self.totp.strip():
268
+ raise TotpError('this login has no TOTP seed')
269
+ return totp_code(self.totp, at)
270
+
271
+
272
+ @dataclass(frozen=True, slots=True, kw_only=True)
273
+ class Card:
274
+ """The payment card part of an item. All values are strings, as the official apps store them.
275
+
276
+ Attributes:
277
+ cardholder_name: The name on the card.
278
+ brand: The card brand, for example ``Visa``.
279
+ number: The card number.
280
+ exp_month: The expiry month, for example ``12``.
281
+ exp_year: The expiry year, for example ``2030``.
282
+ code: The security code (CVV).
283
+ """
284
+
285
+ cardholder_name: str | None = None
286
+ brand: str | None = None
287
+ number: str | None = field(default=None, repr=False)
288
+ exp_month: str | None = None
289
+ exp_year: str | None = None
290
+ code: str | None = field(default=None, repr=False)
291
+
292
+
293
+ @dataclass(frozen=True, slots=True, kw_only=True)
294
+ class Identity:
295
+ """The identity part of an item.
296
+
297
+ Attributes:
298
+ title: Title, for example ``Dr``.
299
+ first_name: First name.
300
+ middle_name: Middle name.
301
+ last_name: Last name.
302
+ address1: First address line.
303
+ address2: Second address line.
304
+ address3: Third address line.
305
+ city: City.
306
+ state: State or province.
307
+ postal_code: Postal code.
308
+ country: Country.
309
+ company: Company.
310
+ email: Email address.
311
+ phone: Phone number.
312
+ ssn: Social security number.
313
+ username: Username.
314
+ passport_number: Passport number.
315
+ license_number: Driver's license number.
316
+ """
317
+
318
+ title: str | None = None
319
+ first_name: str | None = None
320
+ middle_name: str | None = None
321
+ last_name: str | None = None
322
+ address1: str | None = None
323
+ address2: str | None = None
324
+ address3: str | None = None
325
+ city: str | None = None
326
+ state: str | None = None
327
+ postal_code: str | None = None
328
+ country: str | None = None
329
+ company: str | None = None
330
+ email: str | None = None
331
+ phone: str | None = None
332
+ ssn: str | None = field(default=None, repr=False)
333
+ username: str | None = None
334
+ passport_number: str | None = field(default=None, repr=False)
335
+ license_number: str | None = field(default=None, repr=False)
336
+
337
+
338
+ @dataclass(frozen=True, slots=True, kw_only=True)
339
+ class SshKey:
340
+ """The SSH key part of an item.
341
+
342
+ Attributes:
343
+ private_key: The private key (OpenSSH or PEM format).
344
+ public_key: The public key in OpenSSH format.
345
+ key_fingerprint: The ``SHA256:...`` fingerprint.
346
+ """
347
+
348
+ private_key: str | None = field(default=None, repr=False)
349
+ public_key: str | None = None
350
+ key_fingerprint: str | None = None
351
+
352
+
353
+ @dataclass(frozen=True, slots=True, kw_only=True)
354
+ class CustomField:
355
+ """A custom field of an item.
356
+
357
+ Attributes:
358
+ name: The field name.
359
+ value: The value; for boolean fields ``'true'`` or ``'false'``.
360
+ type: The field type.
361
+ linked_id: For linked fields, the built-in field it refers to (its numeric id).
362
+ """
363
+
364
+ name: str | None
365
+ value: str | None = field(repr=False)
366
+ type: FieldType | int
367
+ linked_id: int | None = None
368
+
369
+
370
+ @dataclass(frozen=True, slots=True, kw_only=True)
371
+ class PasswordHistoryEntry:
372
+ """A previous password of a login.
373
+
374
+ Attributes:
375
+ password: The old password.
376
+ last_used_date: When it was replaced.
377
+ """
378
+
379
+ password: str | None = field(repr=False)
380
+ last_used_date: datetime | None
381
+
382
+
383
+ @dataclass(frozen=True, slots=True, kw_only=True)
384
+ class Attachment:
385
+ """Attachment metadata. Download the content with ``download_attachment``.
386
+
387
+ Attributes:
388
+ id: The attachment id.
389
+ file_name: The file name (decrypted).
390
+ size: The size of the encrypted file in bytes (as reported by the uploading client).
391
+ url: The download address the server reported.
392
+ key: The attachment key, encrypted with the item key (internal).
393
+ """
394
+
395
+ id: str
396
+ file_name: str | None
397
+ size: int | None = None
398
+ url: str | None = None
399
+ key: str | None = field(default=None, repr=False)
400
+
401
+
402
+ @dataclass(frozen=True, slots=True, kw_only=True)
403
+ class Cipher:
404
+ """A vault item, decrypted.
405
+
406
+ Exactly one of ``login``, ``card``, ``identity``, ``ssh_key`` is set for the matching type; secure notes use
407
+ ``notes`` and ``secure_note_type``. Item types without a dedicated model (bank account, driver's license,
408
+ passport, future types) keep their decrypted fields in ``data``.
409
+
410
+ Attributes:
411
+ type: The item type.
412
+ name: The item name.
413
+ id: The server id; empty for an item that has not been created yet.
414
+ notes: Free-text notes.
415
+ organization_id: The owning organization, or None for a personal item.
416
+ folder_id: The folder (per user), or None.
417
+ favorite: Marked as favorite (per user).
418
+ reprompt: Whether the clients ask for the master password before showing secrets.
419
+ login: Login data, for ``CipherType.LOGIN``.
420
+ secure_note_type: The note type (always 0 today), for ``CipherType.SECURE_NOTE``.
421
+ card: Card data, for ``CipherType.CARD``.
422
+ identity: Identity data, for ``CipherType.IDENTITY``.
423
+ ssh_key: SSH key data, for ``CipherType.SSH_KEY``.
424
+ data: Decrypted type data for types without a dedicated model, by JSON key.
425
+ fields: Custom fields.
426
+ password_history: Previous passwords, newest first.
427
+ attachments: Attachment metadata.
428
+ collection_ids: Collections of an organization item.
429
+ creation_date: When the item was created.
430
+ revision_date: When the item last changed on the server.
431
+ deleted_date: When the item was moved to the trash, or None.
432
+ archived_date: When the item was archived, or None.
433
+ edit: Whether the user may change the item (False for read-only collections).
434
+ view_password: Whether the user may see the password (False with "hide passwords").
435
+ issues: Parts of the server data that could not be interpreted, as ``path: problem``. Updates never touch
436
+ them and refuse to change them.
437
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
438
+ object is written back. Not part of equality or ``repr()``.
439
+ """
440
+
441
+ type: CipherType | int
442
+ name: str | None
443
+ id: str = ''
444
+ notes: str | None = None
445
+ organization_id: str | None = None
446
+ folder_id: str | None = None
447
+ favorite: bool = False
448
+ reprompt: RepromptType | int = RepromptType.NONE
449
+ login: Login | None = None
450
+ secure_note_type: int | None = None
451
+ card: Card | None = None
452
+ identity: Identity | None = None
453
+ ssh_key: SshKey | None = None
454
+ data: dict[str, Any] = field(default_factory=dict, repr=False, compare=False, hash=False)
455
+ fields: tuple[CustomField, ...] = ()
456
+ password_history: tuple[PasswordHistoryEntry, ...] = ()
457
+ attachments: tuple[Attachment, ...] = ()
458
+ collection_ids: tuple[str, ...] = ()
459
+ creation_date: datetime | None = None
460
+ revision_date: datetime | None = None
461
+ deleted_date: datetime | None = None
462
+ archived_date: datetime | None = None
463
+ edit: bool = True
464
+ view_password: bool = True
465
+ issues: tuple[str, ...] = field(default=(), compare=False, hash=False)
466
+ raw: dict[str, Any] = _raw()
467
+
468
+ @property
469
+ def is_deleted(self) -> bool:
470
+ """Whether the item is in the trash.
471
+
472
+ Returns:
473
+ True if ``deleted_date`` is set.
474
+ """
475
+ return self.deleted_date is not None
476
+
477
+ @property
478
+ def is_archived(self) -> bool:
479
+ """Whether the item is archived.
480
+
481
+ Returns:
482
+ True if ``archived_date`` is set.
483
+ """
484
+ return self.archived_date is not None
485
+
486
+
487
+ @dataclass(frozen=True, slots=True, kw_only=True)
488
+ class Folder:
489
+ """A folder of the personal vault.
490
+
491
+ Attributes:
492
+ name: The folder name (decrypted).
493
+ id: The server id.
494
+ revision_date: When the folder last changed.
495
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
496
+ object is written back. Not part of equality or ``repr()``.
497
+ """
498
+
499
+ name: str | None
500
+ id: str = ''
501
+ revision_date: datetime | None = None
502
+ raw: dict[str, Any] = _raw()
503
+
504
+
505
+ @dataclass(frozen=True, slots=True, kw_only=True)
506
+ class Organization:
507
+ """An organization the user is a member of.
508
+
509
+ Attributes:
510
+ id: The organization id.
511
+ name: The organization name.
512
+ type: The user's role in it.
513
+ status: The user's membership status.
514
+ enabled: Whether the organization is enabled.
515
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
516
+ object is written back. Not part of equality or ``repr()``.
517
+ """
518
+
519
+ id: str
520
+ name: str | None
521
+ type: OrganizationUserType | int | None = None
522
+ status: int | None = None
523
+ enabled: bool = True
524
+ raw: dict[str, Any] = _raw()
525
+
526
+
527
+ @dataclass(frozen=True, slots=True, kw_only=True)
528
+ class Collection:
529
+ """An organization collection, decrypted.
530
+
531
+ Attributes:
532
+ id: The collection id.
533
+ organization_id: The organization it belongs to.
534
+ name: The collection name.
535
+ external_id: The identifier for directory synchronisation.
536
+ read_only: The user may only read the items.
537
+ hide_passwords: Passwords are hidden from the user.
538
+ manage: The user may manage the collection.
539
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
540
+ object is written back. Not part of equality or ``repr()``.
541
+ """
542
+
543
+ id: str
544
+ organization_id: str
545
+ name: str | None
546
+ external_id: str | None = None
547
+ read_only: bool = False
548
+ hide_passwords: bool = False
549
+ manage: bool = False
550
+ raw: dict[str, Any] = _raw()
551
+
552
+
553
+ @dataclass(frozen=True, slots=True, kw_only=True)
554
+ class CollectionAccess:
555
+ """A member's or group's access to one collection.
556
+
557
+ Attributes:
558
+ id: The collection id.
559
+ read_only: Items can only be read.
560
+ hide_passwords: Passwords are hidden.
561
+ manage: The collection can be managed (renamed, access changed).
562
+ """
563
+
564
+ id: str
565
+ read_only: bool = False
566
+ hide_passwords: bool = False
567
+ manage: bool = False
568
+
569
+
570
+ @dataclass(frozen=True, slots=True, kw_only=True)
571
+ class Member:
572
+ """A membership in an organization, as an admin sees it.
573
+
574
+ Attributes:
575
+ id: The membership id (not the user id).
576
+ organization_id: The organization.
577
+ user_id: The user's account id, or None while the invitation is not accepted.
578
+ email: The member's email address.
579
+ name: The member's display name.
580
+ type: The member's role.
581
+ status: The membership status.
582
+ collections: The member's collection access (empty for admins and owners, who see everything).
583
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
584
+ object is written back. Not part of equality or ``repr()``.
585
+ """
586
+
587
+ id: str
588
+ organization_id: str
589
+ user_id: str | None
590
+ email: str | None
591
+ name: str | None = None
592
+ type: OrganizationUserType | int | None = None
593
+ status: MemberStatus | int | None = None
594
+ collections: tuple[CollectionAccess, ...] = ()
595
+ raw: dict[str, Any] = _raw()
596
+
597
+
598
+ @dataclass(frozen=True, slots=True, kw_only=True)
599
+ class Group:
600
+ """An organization group. Needs ``ORG_GROUPS_ENABLED=true`` on the server.
601
+
602
+ Attributes:
603
+ id: The group id.
604
+ organization_id: The organization.
605
+ name: The group name (plain text).
606
+ external_id: The identifier for directory synchronisation.
607
+ collections: The group's collection access.
608
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
609
+ object is written back. Not part of equality or ``repr()``.
610
+ """
611
+
612
+ id: str
613
+ organization_id: str
614
+ name: str
615
+ external_id: str | None = None
616
+ collections: tuple[CollectionAccess, ...] = ()
617
+ raw: dict[str, Any] = _raw()
618
+
619
+
620
+ @dataclass(frozen=True, slots=True, kw_only=True)
621
+ class Policy:
622
+ """An organization policy.
623
+
624
+ Attributes:
625
+ type: The policy type.
626
+ enabled: Whether the policy is active.
627
+ data: Policy-specific options (camelCase keys as the server uses them), or None.
628
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
629
+ object is written back. Not part of equality or ``repr()``.
630
+ """
631
+
632
+ type: PolicyType | int
633
+ enabled: bool
634
+ data: dict[str, Any] | None = None
635
+ raw: dict[str, Any] = _raw()
636
+
637
+
638
+ @dataclass(frozen=True, slots=True, kw_only=True)
639
+ class OrganizationExport:
640
+ """Decrypted content of an organization export.
641
+
642
+ Attributes:
643
+ organization_id: The organization.
644
+ collections: All collections.
645
+ ciphers: All items.
646
+ """
647
+
648
+ organization_id: str
649
+ collections: tuple[Collection, ...] = ()
650
+ ciphers: tuple[Cipher, ...] = ()
651
+
652
+
653
+ @dataclass(frozen=True, slots=True, kw_only=True)
654
+ class TotpSetup:
655
+ """A pending authenticator (TOTP) setup.
656
+
657
+ Add ``uri`` (as QR code) or ``secret`` to an authenticator app, then finish the setup with a code from it.
658
+
659
+ Attributes:
660
+ secret: The base32 secret.
661
+ uri: The ``otpauth://`` URI.
662
+ verification_token: The server's token for finishing the setup (internal).
663
+ """
664
+
665
+ secret: str = field(repr=False)
666
+ uri: str = field(repr=False)
667
+ verification_token: str = field(repr=False)
668
+
669
+
670
+ @dataclass(frozen=True, slots=True, kw_only=True)
671
+ class KnownDevice:
672
+ """A device (client) that has logged in to the account.
673
+
674
+ Attributes:
675
+ id: The device record id.
676
+ name: The device name the client reported.
677
+ type: The device type number (21 is the SDK, used by this library).
678
+ identifier: The client-chosen device identifier.
679
+ creation_date: When the device first logged in.
680
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
681
+ object is written back. Not part of equality or ``repr()``.
682
+ """
683
+
684
+ id: str
685
+ name: str | None
686
+ type: int | None
687
+ identifier: str | None
688
+ creation_date: datetime | None = None
689
+ raw: dict[str, Any] = _raw()
690
+
691
+
692
+ @dataclass(frozen=True, slots=True, kw_only=True)
693
+ class Profile:
694
+ """The logged-in account.
695
+
696
+ Attributes:
697
+ id: The user id.
698
+ email: The email address.
699
+ name: The display name.
700
+ email_verified: Whether the email address is verified.
701
+ premium: Whether the account has premium features (always true on vaultwarden).
702
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
703
+ object is written back. Not part of equality or ``repr()``.
704
+ """
705
+
706
+ id: str
707
+ email: str
708
+ name: str | None = None
709
+ email_verified: bool = False
710
+ premium: bool = False
711
+ raw: dict[str, Any] = _raw()
712
+
713
+
714
+ @dataclass(frozen=True, slots=True, kw_only=True)
715
+ class Vault:
716
+ """Everything the user can see, decrypted (result of ``sync``).
717
+
718
+ Attributes:
719
+ profile: The account.
720
+ folders: The folders.
721
+ ciphers: The items (personal and organization).
722
+ collections: The accessible collections.
723
+ organizations: The memberships.
724
+ undecryptable: Ids of items, folders, collections or organizations that could not be decrypted.
725
+ """
726
+
727
+ profile: Profile
728
+ folders: tuple[Folder, ...] = ()
729
+ ciphers: tuple[Cipher, ...] = ()
730
+ collections: tuple[Collection, ...] = ()
731
+ organizations: tuple[Organization, ...] = ()
732
+ undecryptable: tuple[str, ...] = ()
733
+
734
+ def get(self, item_id: str) -> Cipher | None:
735
+ """Look up an item by id, without a request.
736
+
737
+ Args:
738
+ item_id: The item id.
739
+
740
+ Returns:
741
+ The item, or None if it is not in this vault.
742
+ """
743
+ return next((c for c in self.ciphers if c.id == item_id), None)
744
+
745
+
746
+ @dataclass(frozen=True, slots=True, kw_only=True)
747
+ class AdminMembership:
748
+ """A user's membership in an organization, as the admin panel shows it.
749
+
750
+ Attributes:
751
+ organization_id: The organization.
752
+ name: The organization name.
753
+ type: The user's role.
754
+ status: The membership status.
755
+ enabled: Whether the organization is enabled.
756
+ """
757
+
758
+ organization_id: str
759
+ name: str | None
760
+ type: OrganizationUserType | int | None = None
761
+ status: MemberStatus | int | None = None
762
+ enabled: bool = True
763
+
764
+
765
+ @dataclass(frozen=True, slots=True, kw_only=True)
766
+ class AdminUser:
767
+ """A user account as the server administrator sees it.
768
+
769
+ Attributes:
770
+ id: The user id.
771
+ email: The email address.
772
+ name: The display name.
773
+ enabled: False if an administrator disabled the account.
774
+ email_verified: Whether the email address is verified.
775
+ two_factor_enabled: Whether two-step login is on.
776
+ created_at: When the account was created.
777
+ last_active: When the account was last used.
778
+ organizations: The user's organization memberships.
779
+ raw: The original JSON from the server. Used to keep fields this library does not know when the
780
+ object is written back. Not part of equality or ``repr()``.
781
+ """
782
+
783
+ id: str
784
+ email: str
785
+ name: str | None = None
786
+ enabled: bool = True
787
+ email_verified: bool = False
788
+ two_factor_enabled: bool = False
789
+ created_at: datetime | None = None
790
+ last_active: datetime | None = None
791
+ organizations: tuple[AdminMembership, ...] = ()
792
+ raw: dict[str, Any] = _raw()
793
+
794
+
795
+ @dataclass(frozen=True, slots=True, kw_only=True)
796
+ class AdminOrganization:
797
+ """An organization as the server administrator sees it (collected from user memberships).
798
+
799
+ Attributes:
800
+ id: The organization id.
801
+ name: The organization name.
802
+ members: ``(user, role)`` pairs.
803
+ """
804
+
805
+ id: str
806
+ name: str | None
807
+ members: tuple[tuple[AdminUser, OrganizationUserType | int | None], ...] = ()
808
+
809
+ @property
810
+ def owners(self) -> tuple[AdminUser, ...]:
811
+ """The members with the owner role.
812
+
813
+ Returns:
814
+ The owners.
815
+ """
816
+ return tuple(user for user, role in self.members if role == OrganizationUserType.OWNER)
817
+
818
+
819
+ ItemRef: TypeAlias = Cipher | str
820
+ """A vault item or its id."""
821
+
822
+ FolderRef: TypeAlias = Folder | str
823
+ """A folder, its id, or its (unique) name."""
824
+
825
+ OrganizationRef: TypeAlias = Organization | str
826
+ """An organization, its id, or its (unique) name."""
827
+
828
+ CollectionRef: TypeAlias = Collection | CollectionAccess | str
829
+ """A collection, a collection access entry, or a collection id."""
830
+
831
+ MemberRef: TypeAlias = Member | str
832
+ """A membership, its id, or the member's email."""
833
+
834
+ GroupRef: TypeAlias = Group | str
835
+ """A group, its id, or its (unique) name."""
836
+
837
+
838
+ AdminUserRef: TypeAlias = AdminUser | str
839
+ """A user (admin view), their id, or their email."""
840
+
841
+ AdminOrganizationRef: TypeAlias = AdminOrganization | str
842
+ """An organization (admin view), its id, or its (unique) name."""