forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_vault_secrets_async.py
49 lines (41 loc) · 1.61 KB
/
key_vault_secrets_async.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import uuid
from azure.keyvault.secrets.aio import SecretClient
from key_vault_base_async import KeyVaultBaseAsync
class KeyVaultSecrets(KeyVaultBaseAsync):
def __init__(self):
args = self.get_client_args()
self.secret_client = SecretClient(**args)
self.secret_name = "secret-name-" + uuid.uuid1().hex
self.secret_value = "secret-value"
async def set_secret(self):
print("Setting a secret...")
secret = await self.secret_client.set_secret(
self.secret_name, self.secret_value
)
print("\tdone, secret: (" + secret.name + "," + secret.value + ").")
async def get_secret(self):
print("Getting a secret...")
secret = await self.secret_client.get_secret(self.secret_name)
print("\tdone, secret: (" + secret.name + "," + secret.value + ").")
async def delete_secret(self):
print("Deleting a secret...")
await self.secret_client.delete_secret(self.secret_name)
print("\tdone")
async def run(self):
print("")
print("------------------------")
print("Key Vault - Secrets\nIdentity - Credential")
print("------------------------")
print("1) Set a secret")
print("2) Get that secret")
print("3) Delete that secret (Clean up the resource)")
print("")
try:
await self.set_secret()
await self.get_secret()
finally:
await self.delete_secret()