forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
key_vault_secrets.py
46 lines (39 loc) · 1.5 KB
/
key_vault_secrets.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
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
import uuid
from azure.keyvault.secrets import SecretClient
from key_vault_base import KeyVaultBase
class KeyVaultSecrets(KeyVaultBase):
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"
def set_secret(self):
print("Setting a secret...")
self.secret_client.set_secret(self.secret_name, self.secret_Value)
print("\tdone")
def get_secret(self):
print("Getting a secret...")
secret = self.secret_client.get_secret(self.secret_name)
print("\tdone, secret: (" + secret.name + "," + secret.value + ").")
def delete_secret(self):
print("Deleting a secret...")
deleted_secret = self.secret_client.begin_delete_secret(self.secret_name).result()
print("\tdone: " + deleted_secret.name)
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:
self.set_secret()
self.get_secret()
finally:
self.delete_secret()