Skip to content

Commit f77e2fc

Browse files
Update core to version f13f61ff
1 parent ef6be31 commit f77e2fc

File tree

7 files changed

+270
-3
lines changed

7 files changed

+270
-3
lines changed
888 KB
Binary file not shown.
936 KB
Binary file not shown.
988 KB
Binary file not shown.
1.01 MB
Binary file not shown.
877 KB
Binary file not shown.

src/onepassword/secrets.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .iterator import SDKIterator
55
from typing import Optional, List
66
from pydantic import TypeAdapter
7-
from .types import GeneratePasswordResponse, PasswordRecipe
7+
from .types import GeneratePasswordResponse, PasswordRecipe, ResolveAllResponse
88

99

1010
class Secrets:
@@ -35,6 +35,25 @@ async def resolve(self, secret_reference: str) -> str:
3535
response = TypeAdapter(str).validate_json(response)
3636
return response
3737

38+
async def resolve_all(self, secret_references: List[str]) -> ResolveAllResponse:
39+
"""
40+
Resolve takes in a list of secret references and returns the secrets they point to or errors if any.
41+
"""
42+
response = await _invoke(
43+
{
44+
"invocation": {
45+
"clientId": self.client_id,
46+
"parameters": {
47+
"name": "SecretsResolveAll",
48+
"parameters": {"secret_references": secret_references},
49+
},
50+
}
51+
}
52+
)
53+
54+
response = TypeAdapter(ResolveAllResponse).validate_json(response)
55+
return response
56+
3857
@staticmethod
3958
def validate_secret_reference(secret_reference: str) -> None:
4059
"""

src/onepassword/types.py

Lines changed: 250 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
from enum import Enum
88
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
1016

1117

1218
class GeneratePasswordResponse(BaseModel):
@@ -58,11 +64,13 @@ class ItemFieldType(str, Enum):
5864
TOTP = "Totp"
5965
EMAIL = "Email"
6066
REFERENCE = "Reference"
67+
SSHKEY = "SshKey"
6168
UNSUPPORTED = "Unsupported"
6269

6370

6471
class ItemFieldDetailsTypes(str, Enum):
6572
OTP = "Otp"
73+
SSH_KEY = "SshKey"
6674

6775

6876
class ItemFieldDetailsOtp(BaseModel):
@@ -74,8 +82,17 @@ class ItemFieldDetailsOtp(BaseModel):
7482
content: OtpFieldDetails
7583

7684

85+
class ItemFieldDetailsSshKey(BaseModel):
86+
"""
87+
Computed SSH Key attributes
88+
"""
89+
90+
type: Literal[ItemFieldDetailsTypes.SSH_KEY] = ItemFieldDetailsTypes.SSH_KEY
91+
content: Optional[SshKeyAttributes]
92+
93+
7794
# Field type-specific attributes.
78-
ItemFieldDetails = ItemFieldDetailsOtp
95+
ItemFieldDetails = Union[ItemFieldDetailsOtp, ItemFieldDetailsSshKey]
7996

8097

8198
class ItemField(BaseModel):
@@ -453,6 +470,237 @@ class OtpFieldDetails(BaseModel):
453470
"""
454471

455472

473+
class Response(BaseModel, Generic[T, E]):
474+
content: Optional[T] = Field(default=None)
475+
error: Optional[E] = Field(default=None)
476+
477+
478+
class ResolveReferenceErrorTypes(str, Enum):
479+
PARSING = "parsing"
480+
FIELD_NOT_FOUND = "fieldNotFound"
481+
VAULT_NOT_FOUND = "vaultNotFound"
482+
TOO_MANY_VAULTS = "tooManyVaults"
483+
ITEM_NOT_FOUND = "itemNotFound"
484+
TOO_MANY_ITEMS = "tooManyItems"
485+
TOO_MANY_MATCHING_FIELDS = "tooManyMatchingFields"
486+
NO_MATCHING_SECTIONS = "noMatchingSections"
487+
TOO_MANY_MATCHING_SECTIONS = "tooManyMatchingSections"
488+
INCOMPATIBLE_TOTP_QUERY_PARAMETER_FIELD = "incompatibleTOTPQueryParameterField"
489+
UNABLE_TO_GENERATE_TOTP_CODE = "unableToGenerateTotpCode"
490+
S_SH_KEY_METADATA_NOT_FOUND = "sSHKeyMetadataNotFound"
491+
UNSUPPORTED_FILE_FORMAT = "unsupportedFileFormat"
492+
INCOMPATIBLE_SSH_KEY_QUERY_PARAMETER_FIELD = "incompatibleSshKeyQueryParameterField"
493+
UNABLE_TO_PARSE_PRIVATE_KEY = "unableToParsePrivateKey"
494+
UNABLE_TO_FORMAT_PRIVATE_KEY_TO_OPEN_SSH = "unableToFormatPrivateKeyToOpenSsh"
495+
496+
497+
class ResolveReferenceErrorParsing(BaseModel):
498+
"""
499+
Error parsing the secret reference
500+
"""
501+
502+
type: Literal[ResolveReferenceErrorTypes.PARSING] = (
503+
ResolveReferenceErrorTypes.PARSING
504+
)
505+
message: ErrorMessage
506+
507+
508+
class ResolveReferenceErrorFieldNotFound(BaseModel):
509+
"""
510+
The specified reference cannot be found within the item
511+
"""
512+
513+
type: Literal[ResolveReferenceErrorTypes.FIELD_NOT_FOUND] = (
514+
ResolveReferenceErrorTypes.FIELD_NOT_FOUND
515+
)
516+
517+
518+
class ResolveReferenceErrorVaultNotFound(BaseModel):
519+
"""
520+
No vault matched the secret reference query
521+
"""
522+
523+
type: Literal[ResolveReferenceErrorTypes.VAULT_NOT_FOUND] = (
524+
ResolveReferenceErrorTypes.VAULT_NOT_FOUND
525+
)
526+
527+
528+
class ResolveReferenceErrorTooManyVaults(BaseModel):
529+
"""
530+
More than one vault matched the secret reference query
531+
"""
532+
533+
type: Literal[ResolveReferenceErrorTypes.TOO_MANY_VAULTS] = (
534+
ResolveReferenceErrorTypes.TOO_MANY_VAULTS
535+
)
536+
537+
538+
class ResolveReferenceErrorItemNotFound(BaseModel):
539+
"""
540+
No item matched the secret reference query
541+
"""
542+
543+
type: Literal[ResolveReferenceErrorTypes.ITEM_NOT_FOUND] = (
544+
ResolveReferenceErrorTypes.ITEM_NOT_FOUND
545+
)
546+
547+
548+
class ResolveReferenceErrorTooManyItems(BaseModel):
549+
"""
550+
More than one item matched the secret reference query
551+
"""
552+
553+
type: Literal[ResolveReferenceErrorTypes.TOO_MANY_ITEMS] = (
554+
ResolveReferenceErrorTypes.TOO_MANY_ITEMS
555+
)
556+
557+
558+
class ResolveReferenceErrorTooManyMatchingFields(BaseModel):
559+
"""
560+
More than one field matched the provided secret reference
561+
"""
562+
563+
type: Literal[ResolveReferenceErrorTypes.TOO_MANY_MATCHING_FIELDS] = (
564+
ResolveReferenceErrorTypes.TOO_MANY_MATCHING_FIELDS
565+
)
566+
567+
568+
class ResolveReferenceErrorNoMatchingSections(BaseModel):
569+
"""
570+
No section found within the item for the provided identifier
571+
"""
572+
573+
type: Literal[ResolveReferenceErrorTypes.NO_MATCHING_SECTIONS] = (
574+
ResolveReferenceErrorTypes.NO_MATCHING_SECTIONS
575+
)
576+
577+
578+
class ResolveReferenceErrorTooManyMatchingSections(BaseModel):
579+
"""
580+
More than one matching section found within the item
581+
"""
582+
583+
type: Literal[ResolveReferenceErrorTypes.TOO_MANY_MATCHING_SECTIONS] = (
584+
ResolveReferenceErrorTypes.TOO_MANY_MATCHING_SECTIONS
585+
)
586+
587+
588+
class ResolveReferenceErrorIncompatibleTOTPQueryParameterField(BaseModel):
589+
"""
590+
Incompatiable TOTP query parameters
591+
"""
592+
593+
type: Literal[
594+
ResolveReferenceErrorTypes.INCOMPATIBLE_TOTP_QUERY_PARAMETER_FIELD
595+
] = ResolveReferenceErrorTypes.INCOMPATIBLE_TOTP_QUERY_PARAMETER_FIELD
596+
597+
598+
class ResolveReferenceErrorUnableToGenerateTotpCode(BaseModel):
599+
"""
600+
The totp was not able to be generated
601+
"""
602+
603+
type: Literal[ResolveReferenceErrorTypes.UNABLE_TO_GENERATE_TOTP_CODE] = (
604+
ResolveReferenceErrorTypes.UNABLE_TO_GENERATE_TOTP_CODE
605+
)
606+
message: ErrorMessage
607+
608+
609+
class ResolveReferenceErrorSSHKeyMetadataNotFound(BaseModel):
610+
"""
611+
Couldn't find attributes specific to an SSH Key field
612+
"""
613+
614+
type: Literal[ResolveReferenceErrorTypes.S_SH_KEY_METADATA_NOT_FOUND] = (
615+
ResolveReferenceErrorTypes.S_SH_KEY_METADATA_NOT_FOUND
616+
)
617+
618+
619+
class ResolveReferenceErrorUnsupportedFileFormat(BaseModel):
620+
"""
621+
Currently only support text files
622+
"""
623+
624+
type: Literal[ResolveReferenceErrorTypes.UNSUPPORTED_FILE_FORMAT] = (
625+
ResolveReferenceErrorTypes.UNSUPPORTED_FILE_FORMAT
626+
)
627+
628+
629+
class ResolveReferenceErrorIncompatibleSshKeyQueryParameterField(BaseModel):
630+
"""
631+
Trying to convert a non-private key to a private key format
632+
"""
633+
634+
type: Literal[
635+
ResolveReferenceErrorTypes.INCOMPATIBLE_SSH_KEY_QUERY_PARAMETER_FIELD
636+
] = ResolveReferenceErrorTypes.INCOMPATIBLE_SSH_KEY_QUERY_PARAMETER_FIELD
637+
638+
639+
class ResolveReferenceErrorUnableToParsePrivateKey(BaseModel):
640+
"""
641+
Unable to properly parse a private key string to convert to an internal Private Key type
642+
"""
643+
644+
type: Literal[ResolveReferenceErrorTypes.UNABLE_TO_PARSE_PRIVATE_KEY] = (
645+
ResolveReferenceErrorTypes.UNABLE_TO_PARSE_PRIVATE_KEY
646+
)
647+
648+
649+
class ResolveReferenceErrorUnableToFormatPrivateKeyToOpenSsh(BaseModel):
650+
"""
651+
Unable to format a private key to OpenSSH format
652+
"""
653+
654+
type: Literal[
655+
ResolveReferenceErrorTypes.UNABLE_TO_FORMAT_PRIVATE_KEY_TO_OPEN_SSH
656+
] = ResolveReferenceErrorTypes.UNABLE_TO_FORMAT_PRIVATE_KEY_TO_OPEN_SSH
657+
658+
659+
ResolveReferenceError = Union[
660+
ResolveReferenceErrorParsing,
661+
ResolveReferenceErrorFieldNotFound,
662+
ResolveReferenceErrorVaultNotFound,
663+
ResolveReferenceErrorTooManyVaults,
664+
ResolveReferenceErrorItemNotFound,
665+
ResolveReferenceErrorTooManyItems,
666+
ResolveReferenceErrorTooManyMatchingFields,
667+
ResolveReferenceErrorNoMatchingSections,
668+
ResolveReferenceErrorTooManyMatchingSections,
669+
ResolveReferenceErrorIncompatibleTOTPQueryParameterField,
670+
ResolveReferenceErrorUnableToGenerateTotpCode,
671+
ResolveReferenceErrorSSHKeyMetadataNotFound,
672+
ResolveReferenceErrorUnsupportedFileFormat,
673+
ResolveReferenceErrorIncompatibleSshKeyQueryParameterField,
674+
ResolveReferenceErrorUnableToParsePrivateKey,
675+
ResolveReferenceErrorUnableToFormatPrivateKeyToOpenSsh,
676+
]
677+
678+
679+
class ResolveAllResponse(BaseModel):
680+
model_config = ConfigDict(populate_by_name=True)
681+
682+
individual_responses: List[Response[str, ResolveReferenceError]] = Field(
683+
alias="individualResponses"
684+
)
685+
686+
687+
class SshKeyAttributes(BaseModel):
688+
model_config = ConfigDict(populate_by_name=True)
689+
690+
public_key: str = Field(alias="publicKey")
691+
"""
692+
The public part of the SSH Key
693+
"""
694+
fingerprint: str
695+
"""
696+
The fingerprint of the SSH Key
697+
"""
698+
key_type: str = Field(alias="keyType")
699+
"""
700+
The key type ("Ed25519" or "RSA, {length}-bit")
701+
"""
702+
703+
456704
class VaultOverview(BaseModel):
457705
"""
458706
Represents a decrypted 1Password vault.

0 commit comments

Comments
 (0)