-
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.
SM-874: Add a ProjectsClient and address PR comments
- Loading branch information
1 parent
82f0fe1
commit 8c6b527
Showing
2 changed files
with
77 additions
and
6 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 |
---|---|---|
@@ -1,21 +1,46 @@ | ||
import json | ||
import logging | ||
from BitwardenClient.bitwarden_client import BitwardenClient | ||
from BitwardenClient.schemas import client_settings_from_dict | ||
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": "SDK", | ||
"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" | ||
|
||
result = client.access_token_login("access token here") | ||
# Attempt to authenticate with the Secrets Manager Access Token | ||
result = client.access_token_login("access_token_here") | ||
|
||
secret = client.secrets().create("TEST_SECRET", "This is a test secret", "organization id here", "Secret1234!", ["project id here"]) | ||
if result.success == False: | ||
sys.exit(result.error_message) | ||
|
||
input("Press Enter to delete the secret...") | ||
# -- 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)) |