|
6 | 6 |
|
7 | 7 | from enum import Enum |
8 | 8 | from pydantic import BaseModel, ConfigDict, Field |
9 | | -from typing import List, Literal, Optional, Union |
| 9 | +from typing import Generic, List, Literal, Optional, TypeVar, Union |
| 10 | + |
| 11 | +E = TypeVar("E") |
| 12 | +T = TypeVar("T") |
| 13 | + |
| 14 | + |
| 15 | +ErrorMessage = str |
10 | 16 |
|
11 | 17 |
|
12 | 18 | class GeneratePasswordResponse(BaseModel): |
@@ -453,6 +459,184 @@ class OtpFieldDetails(BaseModel): |
453 | 459 | """ |
454 | 460 |
|
455 | 461 |
|
| 462 | +class Response(BaseModel, Generic[T, E]): |
| 463 | + content: Optional[T] = Field(default=None) |
| 464 | + error: Optional[E] = Field(default=None) |
| 465 | + |
| 466 | + |
| 467 | +class ResolveReferenceErrorTypes(str, Enum): |
| 468 | + PARSING = "parsing" |
| 469 | + FIELD_NOT_FOUND = "fieldNotFound" |
| 470 | + VAULT_NOT_FOUND = "vaultNotFound" |
| 471 | + TOO_MANY_VAULTS = "tooManyVaults" |
| 472 | + ITEM_NOT_FOUND = "itemNotFound" |
| 473 | + TOO_MANY_ITEMS = "tooManyItems" |
| 474 | + TOO_MANY_MATCHING_FIELDS = "tooManyMatchingFields" |
| 475 | + NO_MATCHING_SECTIONS = "noMatchingSections" |
| 476 | + TOO_MANY_MATCHING_SECTIONS = "tooManyMatchingSections" |
| 477 | + INCOMPATIBLE_TOTP_QUERY_PARAMETER_FIELD = "incompatibleTOTPQueryParameterField" |
| 478 | + UNABLE_TO_GENERATE_TOTP_CODE = "unableToGenerateTotpCode" |
| 479 | + S_SH_KEY_METADATA_NOT_FOUND = "sSHKeyMetadataNotFound" |
| 480 | + UNSUPPORTED_FILE_FORMAT = "unsupportedFileFormat" |
| 481 | + |
| 482 | + |
| 483 | +class ResolveReferenceErrorParsing(BaseModel): |
| 484 | + """ |
| 485 | + Error parsing the secret reference |
| 486 | + """ |
| 487 | + |
| 488 | + type: Literal[ResolveReferenceErrorTypes.PARSING] = ( |
| 489 | + ResolveReferenceErrorTypes.PARSING |
| 490 | + ) |
| 491 | + message: ErrorMessage |
| 492 | + |
| 493 | + |
| 494 | +class ResolveReferenceErrorFieldNotFound(BaseModel): |
| 495 | + """ |
| 496 | + The specified reference cannot be found within the item |
| 497 | + """ |
| 498 | + |
| 499 | + type: Literal[ResolveReferenceErrorTypes.FIELD_NOT_FOUND] = ( |
| 500 | + ResolveReferenceErrorTypes.FIELD_NOT_FOUND |
| 501 | + ) |
| 502 | + |
| 503 | + |
| 504 | +class ResolveReferenceErrorVaultNotFound(BaseModel): |
| 505 | + """ |
| 506 | + No vault matched the secret reference query |
| 507 | + """ |
| 508 | + |
| 509 | + type: Literal[ResolveReferenceErrorTypes.VAULT_NOT_FOUND] = ( |
| 510 | + ResolveReferenceErrorTypes.VAULT_NOT_FOUND |
| 511 | + ) |
| 512 | + |
| 513 | + |
| 514 | +class ResolveReferenceErrorTooManyVaults(BaseModel): |
| 515 | + """ |
| 516 | + More than one vault matched the secret reference query |
| 517 | + """ |
| 518 | + |
| 519 | + type: Literal[ResolveReferenceErrorTypes.TOO_MANY_VAULTS] = ( |
| 520 | + ResolveReferenceErrorTypes.TOO_MANY_VAULTS |
| 521 | + ) |
| 522 | + |
| 523 | + |
| 524 | +class ResolveReferenceErrorItemNotFound(BaseModel): |
| 525 | + """ |
| 526 | + No item matched the secret reference query |
| 527 | + """ |
| 528 | + |
| 529 | + type: Literal[ResolveReferenceErrorTypes.ITEM_NOT_FOUND] = ( |
| 530 | + ResolveReferenceErrorTypes.ITEM_NOT_FOUND |
| 531 | + ) |
| 532 | + |
| 533 | + |
| 534 | +class ResolveReferenceErrorTooManyItems(BaseModel): |
| 535 | + """ |
| 536 | + More than one item matched the secret reference query |
| 537 | + """ |
| 538 | + |
| 539 | + type: Literal[ResolveReferenceErrorTypes.TOO_MANY_ITEMS] = ( |
| 540 | + ResolveReferenceErrorTypes.TOO_MANY_ITEMS |
| 541 | + ) |
| 542 | + |
| 543 | + |
| 544 | +class ResolveReferenceErrorTooManyMatchingFields(BaseModel): |
| 545 | + """ |
| 546 | + More than one field matched the provided secret reference |
| 547 | + """ |
| 548 | + |
| 549 | + type: Literal[ResolveReferenceErrorTypes.TOO_MANY_MATCHING_FIELDS] = ( |
| 550 | + ResolveReferenceErrorTypes.TOO_MANY_MATCHING_FIELDS |
| 551 | + ) |
| 552 | + |
| 553 | + |
| 554 | +class ResolveReferenceErrorNoMatchingSections(BaseModel): |
| 555 | + """ |
| 556 | + No section found within the item for the provided identifier |
| 557 | + """ |
| 558 | + |
| 559 | + type: Literal[ResolveReferenceErrorTypes.NO_MATCHING_SECTIONS] = ( |
| 560 | + ResolveReferenceErrorTypes.NO_MATCHING_SECTIONS |
| 561 | + ) |
| 562 | + |
| 563 | + |
| 564 | +class ResolveReferenceErrorTooManyMatchingSections(BaseModel): |
| 565 | + """ |
| 566 | + More than one matching section found within the item |
| 567 | + """ |
| 568 | + |
| 569 | + type: Literal[ResolveReferenceErrorTypes.TOO_MANY_MATCHING_SECTIONS] = ( |
| 570 | + ResolveReferenceErrorTypes.TOO_MANY_MATCHING_SECTIONS |
| 571 | + ) |
| 572 | + |
| 573 | + |
| 574 | +class ResolveReferenceErrorIncompatibleTOTPQueryParameterField(BaseModel): |
| 575 | + """ |
| 576 | + Incompatiable TOTP query parameters |
| 577 | + """ |
| 578 | + |
| 579 | + type: Literal[ |
| 580 | + ResolveReferenceErrorTypes.INCOMPATIBLE_TOTP_QUERY_PARAMETER_FIELD |
| 581 | + ] = ResolveReferenceErrorTypes.INCOMPATIBLE_TOTP_QUERY_PARAMETER_FIELD |
| 582 | + |
| 583 | + |
| 584 | +class ResolveReferenceErrorUnableToGenerateTotpCode(BaseModel): |
| 585 | + """ |
| 586 | + The totp was not able to be generated |
| 587 | + """ |
| 588 | + |
| 589 | + type: Literal[ResolveReferenceErrorTypes.UNABLE_TO_GENERATE_TOTP_CODE] = ( |
| 590 | + ResolveReferenceErrorTypes.UNABLE_TO_GENERATE_TOTP_CODE |
| 591 | + ) |
| 592 | + message: ErrorMessage |
| 593 | + |
| 594 | + |
| 595 | +class ResolveReferenceErrorSSHKeyMetadataNotFound(BaseModel): |
| 596 | + """ |
| 597 | + Couldn't find attributes specific to an SSH Key field |
| 598 | + """ |
| 599 | + |
| 600 | + type: Literal[ResolveReferenceErrorTypes.S_SH_KEY_METADATA_NOT_FOUND] = ( |
| 601 | + ResolveReferenceErrorTypes.S_SH_KEY_METADATA_NOT_FOUND |
| 602 | + ) |
| 603 | + |
| 604 | + |
| 605 | +class ResolveReferenceErrorUnsupportedFileFormat(BaseModel): |
| 606 | + """ |
| 607 | + Currently only support text files |
| 608 | + """ |
| 609 | + |
| 610 | + type: Literal[ResolveReferenceErrorTypes.UNSUPPORTED_FILE_FORMAT] = ( |
| 611 | + ResolveReferenceErrorTypes.UNSUPPORTED_FILE_FORMAT |
| 612 | + ) |
| 613 | + |
| 614 | + |
| 615 | +ResolveReferenceError = Union[ |
| 616 | + ResolveReferenceErrorParsing, |
| 617 | + ResolveReferenceErrorFieldNotFound, |
| 618 | + ResolveReferenceErrorVaultNotFound, |
| 619 | + ResolveReferenceErrorTooManyVaults, |
| 620 | + ResolveReferenceErrorItemNotFound, |
| 621 | + ResolveReferenceErrorTooManyItems, |
| 622 | + ResolveReferenceErrorTooManyMatchingFields, |
| 623 | + ResolveReferenceErrorNoMatchingSections, |
| 624 | + ResolveReferenceErrorTooManyMatchingSections, |
| 625 | + ResolveReferenceErrorIncompatibleTOTPQueryParameterField, |
| 626 | + ResolveReferenceErrorUnableToGenerateTotpCode, |
| 627 | + ResolveReferenceErrorSSHKeyMetadataNotFound, |
| 628 | + ResolveReferenceErrorUnsupportedFileFormat, |
| 629 | +] |
| 630 | + |
| 631 | + |
| 632 | +class ResolveAllResponse(BaseModel): |
| 633 | + model_config = ConfigDict(populate_by_name=True) |
| 634 | + |
| 635 | + individual_responses: List[Response[str, ResolveReferenceError]] = Field( |
| 636 | + alias="individualResponses" |
| 637 | + ) |
| 638 | + |
| 639 | + |
456 | 640 | class VaultOverview(BaseModel): |
457 | 641 | """ |
458 | 642 | Represents a decrypted 1Password vault. |
|
0 commit comments