-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Type of change <!-- (mark with an `X`) --> ``` - [x] Bug fix - [ ] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective <!--Describe what the purpose of this PR is. For example: what bug you're fixing or what new feature you're adding--> The Python integration is out of date and is not currently working. This PR fixes the Python integration by adding the ability to log in via access token, which is currently the supported way to interact with the Bitwarden Secrets Manager SDK. This PR also adds a `ProjectsClient` to `bitwarden_client.py` for easy use, and updates the error handling on Project or Secret deletes in the SDK. ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> - **crates/sdk-schemas/src/main.rs:** We need the `AccessTokenLoginResponse` struct to be generated so access token auth is available to integrations - **languages/python/BitwardenClient/bitwarden_client.py:** - Import the following from `.schemas`: - `AccessTokenLoginRequest` - `AccessTokenLoginResponse` - `ResponseForAccessTokenLoginResponse` - Define a new function `access_token_login` to support authenticating with an access token - Add the `project_ids` parameter to the `create` and `update` functions for `SecretsClient` - Add a `ProjectsClient` class and `projects()` to the `BitwardenClient` - Removed the password login methods, as they are not supported - Removed the imports that are not needed, and add one that are (like `sys`, etc.) - **languages/python/README.md:** Update the readme instructions, give more examples - **languages/python/login.py:** Renamed `login.py` to `example.py` - **languages/python/example.py:** Update the example to showcase auth with an access token ## Before you submit - Please add **unit tests** where it makes sense to do so (encouraged but not required)
- Loading branch information
1 parent
af31957
commit 92a67b1
Showing
5 changed files
with
115 additions
and
50 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
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,44 @@ | ||
import json | ||
import logging | ||
import sys | ||
from BitwardenClient.bitwarden_client import BitwardenClient | ||
from BitwardenClient.schemas import client_settings_from_dict, DeviceType | ||
|
||
# Create the BitwardenClient, which is used to interact with the SDK | ||
client = BitwardenClient(client_settings_from_dict({ | ||
"apiUrl": "http://localhost:4000", | ||
"deviceType": DeviceType.SDK, | ||
"identityUrl": "http://localhost:33656", | ||
"userAgent": "Python", | ||
})) | ||
|
||
# Add some logging & set the org id | ||
logging.basicConfig(level=logging.DEBUG) | ||
organization_id = "org_id_here" | ||
|
||
# Attempt to authenticate with the Secrets Manager Access Token | ||
client.access_token_login("access_token_here") | ||
|
||
# -- Example Project Commands -- | ||
|
||
project = client.projects().create("ProjectName", organization_id) | ||
project2 = client.projects().create("Project - Don't Delete Me!", organization_id) | ||
updated_project = client.projects().update(project.data.id, "Cool New Project Name", organization_id) | ||
get_that_project = client.projects().get(project.data.id) | ||
|
||
input("Press Enter to delete the project...") | ||
client.projects().delete([project.data.id]) | ||
|
||
print(client.projects().list(organization_id)) | ||
|
||
# -- Example Secret Commands -- | ||
|
||
secret = client.secrets().create("TEST_SECRET", "This is a test secret", organization_id, "Secret1234!", [project2.data.id]) | ||
secret2 = client.secrets().create("Secret - Don't Delete Me!", "This is a test secret that will stay", organization_id, "Secret1234!", [project2.data.id]) | ||
secret_updated = client.secrets().update(secret.data.id, "TEST_SECRET_UPDATED", "This as an updated test secret", organization_id, "Secret1234!_updated", [project2.data.id]) | ||
secret_retrieved = client.secrets().get(secret.data.id) | ||
|
||
input("Press Enter to delete the secret...") | ||
client.secrets().delete([secret.data.id]) | ||
|
||
print(client.secrets().list(organization_id)) |
This file was deleted.
Oops, something went wrong.