-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split examples and tests into smaller units
- Loading branch information
Showing
10 changed files
with
174 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import asyncio | ||
import os | ||
|
||
from onepassword.client import Client | ||
|
||
# list all items in all vaults | ||
async def list_items_in_vaults(): | ||
token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
if not token: | ||
raise ValueError("OP_SERVICE_ACCOUNT_TOKEN must be set.") | ||
client = await Client.authenticate( | ||
auth=token, | ||
# Set the following to your own integration name and version. | ||
integration_name="My 1Password Integration", | ||
integration_version="v1.0.0", | ||
) | ||
vaults = await client.vaults.list_all() | ||
async for vault in vaults: | ||
items = await client.items.list_all(vault.id) | ||
async for item in items: | ||
print(item.title) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(list_items_in_vaults()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import asyncio | ||
import os | ||
|
||
from onepassword.client import Client | ||
|
||
# list all vaults | ||
async def list_vaults(): | ||
token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
if not token: | ||
raise ValueError("OP_SERVICE_ACCOUNT_TOKEN must be set.") | ||
client = await Client.authenticate( | ||
auth=token, | ||
# Set the following to your own integration name and version. | ||
integration_name="My 1Password Integration", | ||
integration_version="v1.0.0", | ||
) | ||
vaults = await client.vaults.list_all() | ||
async for vault in vaults: | ||
print(vault.title) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(list_vaults()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
from onepassword.secrets import Secrets | ||
|
||
# Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points. | ||
def resolve_secret_reference(): | ||
# Replace this with a real secret reference | ||
secret_reference = "op://vault/item/field" | ||
try: | ||
Secrets.validate_secret_reference(secret_reference) | ||
print("Secret reference resolved successfully") | ||
except Exception as error: | ||
print(error) | ||
|
||
if __name__ == "__main__": | ||
resolve_secret_reference() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
from onepassword.secrets import Secrets | ||
|
||
# Validate secret reference to ensure no syntax errors | ||
def validate_secret_reference(): | ||
try: | ||
Secrets.validate_secret_reference("op://vault/item/field") | ||
print("Secret reference is of valid syntax") | ||
except Exception as error: | ||
print(error) | ||
|
||
if __name__ == "__main__": | ||
validate_secret_reference() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# change working directory to the directory of the script | ||
|
||
cd "$(dirname "$0")" | ||
|
||
# Run all python files in the tests directory | ||
for file in *.py | ||
do | ||
python3 $file | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import asyncio | ||
import os | ||
|
||
from onepassword.client import Client | ||
|
||
async def test_list_items_in_vaults(): | ||
print("Starting list_items_in_vaults test") | ||
token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
if not token: | ||
raise ValueError("OP_SERVICE_ACCOUNT_TOKEN must be set.") | ||
client = await Client.authenticate( | ||
auth=token, | ||
# Set the following to your own integration name and version. | ||
integration_name="My 1Password Integration", | ||
integration_version="v1.0.0", | ||
) | ||
vaults = await client.vaults.list_all() | ||
async for vault in vaults: | ||
items = await client.items.list_all(vault.id) | ||
async for item in items: | ||
print(item.title) | ||
|
||
print("list_items_in_vaults test completed successfully") | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(test_list_items_in_vaults()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import asyncio | ||
import os | ||
|
||
from onepassword.client import Client | ||
|
||
async def test_list_vaults(): | ||
print("Starting list_vaults test") | ||
token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN") | ||
if not token: | ||
raise ValueError("OP_SERVICE_ACCOUNT_TOKEN must be set.") | ||
client = await Client.authenticate( | ||
auth=token, | ||
# Set the following to your own integration name and version. | ||
integration_name="My 1Password Integration", | ||
integration_version="v1.0.0", | ||
) | ||
vaults = await client.vaults.list_all() | ||
async for vault in vaults: | ||
print(vault.title) | ||
|
||
print("Finished list_vaults test successfully") | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(test_list_vaults()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from onepassword.secrets import Secrets | ||
import os | ||
|
||
def test_resolve_secret_reference(): | ||
print("Starting resolve_secret_reference test") | ||
test_secret_ref = os.getenv("CORE_SDK_TEST_SECRET_REF") | ||
if not test_secret_ref: | ||
raise ValueError("CORE_SDK_TEST_SECRET_REF must be set.") | ||
Secrets.validate_secret_reference(test_secret_ref) | ||
print("Finished resolve_secret_reference test successfully") | ||
|
||
if __name__ == "__main__": | ||
test_resolve_secret_reference() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from onepassword.secrets import Secrets | ||
|
||
# Validate secret reference to ensure no syntax errors | ||
def test_validate_secret_reference(): | ||
print("Starting validate_secret_reference test") | ||
Secrets.validate_secret_reference("op://vault/item/field") | ||
print("Finished validate_secret_reference test successfully") | ||
|
||
if __name__ == "__main__": | ||
test_validate_secret_reference() |