Skip to content

Commit ac3b0f4

Browse files
committed
Merge remote-tracking branch 'origin' into morgan/150/example-test
2 parents 9a95f61 + 44f99f2 commit ac3b0f4

File tree

13 files changed

+506
-29
lines changed

13 files changed

+506
-29
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Operations:
8989
- [x] [Delete items](https://developer.1password.com/docs/sdks/manage-items#delete-an-item)
9090
- [x] [Archive items](https://developer.1password.com/docs/sdks/manage-items/#archive-an-item)
9191
- [x] [List items](https://developer.1password.com/docs/sdks/list-vaults-items/)
92-
- [x] [Share items](https://developer.1password.com/docs/sdks/share-items) (items with files cannot be shared)
92+
- [x] [Share items](https://developer.1password.com/docs/sdks/share-items)
9393
- [x] [Generate PIN, random and memorable passwords](https://developer.1password.com/docs/sdks/manage-items#generate-a-password)
9494

9595
Field types:
@@ -98,7 +98,7 @@ Field types:
9898
- [x] Concealed fields
9999
- [x] Text fields
100100
- [x] Notes
101-
- [x] SSH private keys, public keys, fingerprint and key type
101+
- [x] SSH private keys, public keys, fingerprint and key type
102102
- [x] One-time passwords
103103
- [x] URLs
104104
- [x] Websites (used to suggest and autofill logins)
@@ -107,8 +107,8 @@ Field types:
107107
- [x] Credit card numbers
108108
- [x] Emails
109109
- [x] References to other items
110-
- [ ] Address
111-
- [ ] Date
110+
- [x] Address
111+
- [x] Date
112112
- [x] MM/YY
113113
- [x] Files attachments and Document items
114114
- [x] Menu

example/example.py

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ async def main():
106106
)
107107
print(code)
108108
# [developer-docs.sdk.python.resolve-totp-code]-end
109-
109+
await resolve_all_secrets(
110+
client, created_item.vault_id, created_item.id, "username", "password"
111+
)
110112
# [developer-docs.sdk.python.get-totp-item-crud]-start
111113
# Fetch a totp code from the item
112114
for f in created_item.fields:
@@ -233,6 +235,7 @@ async def share_item(client: Client, vault_id: str, item_id: str):
233235

234236

235237
async def create_ssh_key_item(client: Client, vault_id: str):
238+
# [developer-docs.sdk.python.create-sshkey-item]-start
236239
# Generate a 2048-bit RSA private key
237240
private_key = rsa.generate_private_key(
238241
public_exponent=65537,
@@ -246,7 +249,6 @@ async def create_ssh_key_item(client: Client, vault_id: str):
246249
encryption_algorithm=serialization.NoEncryption(),
247250
)
248251

249-
# [developer-docs.sdk.python.create-sshkey-item]-start
250252
# Create an Item containing SSH Key and add it to your vault.
251253
to_create = ItemCreateParams(
252254
title="SSH Key Item Created With Python SDK",
@@ -386,5 +388,85 @@ async def create_attach_and_delete_file_field_item(client: Client, vault_id: str
386388
await client.items.delete(deleted_file_item.vault_id, deleted_file_item.id)
387389

388390

391+
async def resolve_all_secrets(
392+
client: Client, vault_id: str, item_id: str, field_id: str, field_id2: str
393+
):
394+
# [developer-docs.sdk.python.resolve-bulk-secret]-start
395+
# Retrieves multiple secrets from 1Password.
396+
secrets = await client.secrets.resolve_all(
397+
[
398+
f"op://{vault_id}/{item_id}/{field_id}",
399+
f"op://{vault_id}/{item_id}/{field_id2}",
400+
]
401+
)
402+
for secret in secrets.individual_responses.values():
403+
if secret.error is not None:
404+
print(str(secret.error))
405+
else:
406+
print(secret.content.secret)
407+
# [developer-docs.sdk.python.resolve-bulk-secret]-end
408+
409+
410+
def generate_special_item_fields():
411+
fields = (
412+
[
413+
# [developer-docs.sdk.python.address-field-type]-start
414+
ItemField(
415+
id="address",
416+
title="Address",
417+
sectionId="",
418+
field_type=ItemFieldType.ADDRESS,
419+
value="",
420+
details=ItemFieldDetailsAddress(
421+
content=AddressFieldDetails(
422+
street="1234 Main St",
423+
city="San Francisco",
424+
state="CA",
425+
zip="94111",
426+
country="USA",
427+
),
428+
),
429+
),
430+
# [developer-docs.sdk.python.address-field-type]-end
431+
# [developer-docs.sdk.python.date-field-type]-start
432+
ItemField(
433+
id="date",
434+
title="Date",
435+
section_id="",
436+
field_type=ItemFieldType.DATE,
437+
value="1998-03-15",
438+
),
439+
# [developer-docs.sdk.python.date-field-type]-end
440+
# [developer-docs.sdk.python.month-year-field-type]-start
441+
ItemField(
442+
id="month_year",
443+
title="Month Year",
444+
section_id="",
445+
field_type=ItemFieldType.MONTHYEAR,
446+
value="03/1998",
447+
),
448+
# [developer-docs.sdk.python.month-year-field-type]-end
449+
# [developer-docs.sdk.python.reference-field-type]-start
450+
ItemField(
451+
id="Reference",
452+
title="Reference",
453+
sectionId="",
454+
field_type=ItemFieldType.REFERENCE,
455+
value="f43hnkatjllm5fsfsmgaqdhv7a",
456+
),
457+
# [developer-docs.sdk.python.reference-field-type]-end
458+
# [developer-docs.sdk.python.totp-field-type]-start
459+
ItemField(
460+
id="onetimepassword",
461+
title="one-time-password",
462+
section_id="",
463+
field_type=ItemFieldType.TOTP,
464+
value="otpauth://totp/my-example-otp?secret=jncrjgbdjnrncbjsr&issuer=1Password",
465+
),
466+
# [developer-docs.sdk.python.totp-field-type]-end
467+
],
468+
)
469+
470+
389471
if __name__ == "__main__":
390472
asyncio.run(main())

src/onepassword/build_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SDK_BUILD_NUMBER = "0020001"
1+
SDK_BUILD_NUMBER = "0020101"

src/onepassword/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from onepassword.errors import raise_typed_exception
55

6-
# In empirical tests, we determined that maximum message size that can cross the FFI boundary
6+
# In empirical tests, we determined that maximum message size that can cross the FFI boundary
77
# is ~128MB. Past this limit, FFI will throw an error and the program will crash.
88
# We set the limit to 50MB to be safe and consistent with the other SDKs (where this limit is 64MB), to be reconsidered upon further testing
99
MESSAGE_LIMIT = 50 * 1024 * 1024
@@ -33,7 +33,8 @@ async def _invoke(invoke_config):
3333
serialized_config = json.dumps(invoke_config)
3434
if len(serialized_config.encode()) > MESSAGE_LIMIT:
3535
raise ValueError(
36-
f"message size exceeds the limit of {MESSAGE_LIMIT} bytes, please contact 1Password at [email protected] or https://developer.1password.com/joinslack if you need help.")
36+
f"message size exceeds the limit of {MESSAGE_LIMIT} bytes, please contact 1Password at [email protected] or https://developer.1password.com/joinslack if you need help."
37+
)
3738
try:
3839
return await core.invoke(serialized_config)
3940
except Exception as e:
@@ -45,7 +46,8 @@ def _invoke_sync(invoke_config):
4546
serialized_config = json.dumps(invoke_config)
4647
if len(serialized_config.encode()) > MESSAGE_LIMIT:
4748
raise ValueError(
48-
f"message size exceeds the limit of {MESSAGE_LIMIT} bytes, please contact 1Password at [email protected] or https://developer.1password.com/joinslack if you need help.")
49+
f"message size exceeds the limit of {MESSAGE_LIMIT} bytes, please contact 1Password at [email protected] or https://developer.1password.com/joinslack if you need help."
50+
)
4951
try:
5052
return core.invoke_sync(serialized_config)
5153
except Exception as e:
462 KB
Binary file not shown.
487 KB
Binary file not shown.
559 KB
Binary file not shown.
476 KB
Binary file not shown.
742 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
"""

0 commit comments

Comments
 (0)