-
Notifications
You must be signed in to change notification settings - Fork 38
Adding ConfigClass for HTTPX #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
31d0e13
Add configclass
mattjacksoncello 426b901
fix cyclical imports
mattjacksoncello 3fa8e90
add example
mattjacksoncello c2e521c
Re order logic for getting httpx options
mattjacksoncello d447dc3
Update src/onepasswordconnectsdk/config.py
mattjacksoncello f4980bb
Update src/onepasswordconnectsdk/config.py
mattjacksoncello f4a9352
Rename 'cafile' to 'ca_file' in ClientConfig for consistency
mattjacksoncello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,85 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Example script demonstrating how to connect to a 1Password Connect server | ||
| using CA certificate verification and list all secrets in a vault. | ||
|
|
||
| Shows both synchronous and asynchronous usage. | ||
| Update the configuration variables below with your values. | ||
| """ | ||
|
|
||
| import asyncio | ||
| from onepasswordconnectsdk.client import new_client | ||
| from onepasswordconnectsdk.config import ClientConfig | ||
|
|
||
| # Configuration | ||
| CONNECT_URL = "https://connect.example.com" # Your 1Password Connect server URL | ||
| TOKEN = "eyJhbGc..." # Your 1Password Connect token | ||
| VAULT_ID = "vaults_abc123" # ID of the vault to list secrets from | ||
| CA_FILE = "path/to/ca.pem" # Path to your CA certificate file | ||
|
|
||
| def list_vault_secrets(): | ||
| """ | ||
| Connect to 1Password Connect server and list all secrets in the specified vault. | ||
| Uses CA certificate verification for secure connection. | ||
| """ | ||
| try: | ||
| # Configure client with CA certificate verification | ||
| config = ClientConfig( | ||
| cafile=CA_FILE, | ||
| timeout=30.0 # 30 second timeout | ||
| ) | ||
|
|
||
| # Initialize client with configuration | ||
| client = new_client(CONNECT_URL, TOKEN, config=config) | ||
|
|
||
| # Get all items in the vault | ||
| items = client.get_items(VAULT_ID) | ||
|
|
||
| # Print items | ||
| print(f"\nSecrets in vault {VAULT_ID}:") | ||
| print("-" * 40) | ||
| for item in items: | ||
| print(f"- {item.title} ({item.category})") | ||
|
|
||
| except Exception as e: | ||
| print(f"Error: {str(e)}") | ||
|
|
||
|
|
||
| async def list_vault_secrets_async(): | ||
| """ | ||
| Async version: Connect to 1Password Connect server and list all secrets in the specified vault. | ||
| Uses CA certificate verification for secure connection. | ||
| """ | ||
| try: | ||
| # Configure client with CA certificate verification | ||
| config = ClientConfig( | ||
| cafile=CA_FILE, | ||
| timeout=30.0 # 30 second timeout | ||
| ) | ||
|
|
||
| # Initialize async client with configuration | ||
| client = new_client(CONNECT_URL, TOKEN, is_async=True, config=config) | ||
|
|
||
| # Get all items in the vault | ||
| items = await client.get_items(VAULT_ID) | ||
|
|
||
| # Print items | ||
| print(f"\nSecrets in vault {VAULT_ID} (async):") | ||
| print("-" * 40) | ||
| for item in items: | ||
| print(f"- {item.title} ({item.category})") | ||
|
|
||
| # Close the client gracefully | ||
| await client.session.aclose() | ||
|
|
||
| except Exception as e: | ||
| print(f"Error: {str(e)}") | ||
|
|
||
| if __name__ == "__main__": | ||
| # Run sync version | ||
| print("Running synchronous example...") | ||
| list_vault_secrets() | ||
|
|
||
| # Run async version | ||
| print("\nRunning asynchronous example...") | ||
| asyncio.run(list_vault_secrets_async()) |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.