Skip to content

Commit

Permalink
[keyvalut] Enhance code style for one sample file
Browse files Browse the repository at this point in the history
Modernize to follow with up-to-date coding style for
sdk/keyvault/azure-keyvault-keys/samples/backup_restore_operations_async.py

Closes: Azure#18
  • Loading branch information
KdHyeon0661 authored and ianychoi committed Jul 28, 2022
1 parent ea34c9c commit 0dfbb0d
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ async def run_sample():
# if the key already exists in the Key Vault, then a new version of the key is created.
print("\n.. Create Key")
key = await client.create_key("keyNameAsync", "RSA")
print("Key with name '{0}' created with key type '{1}'".format(key.name, key.key_type))
print(f"Key with name '{key.name}' created with key type '{key.key_type}'")

# Backups are good to have, if in case keys gets deleted accidentally.
# For long term storage, it is ideal to write the backup to a file.
print("\n.. Create a backup for an existing Key")
key_backup = await client.backup_key(key.name)
print("Backup created for key with name '{0}'.".format(key.name))
print(f"Backup created for key with name '{key.name}'.")

# The rsa key is no longer in use, so you delete it.
deleted_key = await client.delete_key(key.name)
print("Deleted key with name '{0}'".format(deleted_key.name))
print(f"Deleted key with name '{deleted_key.name}'")

# Purge the deleted key.
# The purge will take some time, so wait before restoring the backup to avoid a conflict.
print("\n.. Purge the key")
await client.purge_deleted_key(key.name)
await asyncio.sleep(60)
print("Purged key with name '{0}'".format(deleted_key.name))
print(f"Purged key with name '{deleted_key.name}'")

# In the future, if the key is required again, we can use the backup value to restore it in the Key Vault.
print("\n.. Restore the key using the backed up key bytes")
key = await client.restore_key_backup(key_backup)
print("Restored key with name '{0}'".format(key.name))
print(f"Restored key with name '{key.name}'")

print("\nrun_sample done")
await credential.close()
Expand Down

0 comments on commit 0dfbb0d

Please sign in to comment.