Skip to content

Commit

Permalink
Improve the readability of source code
Browse files Browse the repository at this point in the history
Change str.format() formatting of the source code to f-string formatting.
  • Loading branch information
syso-jxx authored and wonder6845 committed Aug 23, 2022
1 parent 9299654 commit c345e42
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions sdk/keyvault/azure-keyvault-keys/samples/hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@
key_ops = ["encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey"]
key_name = "rsaKeyName"
rsa_key = client.create_rsa_key(key_name, size=key_size, key_operations=key_ops)
print("RSA Key with name '{0}' created of type '{1}'.".format(rsa_key.name, rsa_key.key_type))
print(f"RSA Key with name '{rsa_key.name}' created of type '{rsa_key.key_type}'")

# Let's create an Elliptic Curve key with algorithm curve type P-256.
# if the key already exists in the Key Vault, then a new version of the key is created.
print("\n.. Create an EC Key")
key_curve = "P-256"
key_name = "ECKeyName"
ec_key = client.create_ec_key(key_name, curve=key_curve)
print("EC Key with name '{0}' created of type '{1}'.".format(ec_key.name, ec_key.key_type))
print(f"EC Key with name '{ec_key.name}' created of type '{ec_key.key_type}'")

# Let's get the rsa key details using its name
print("\n.. Get a Key by its name")
rsa_key = client.get_key(rsa_key.name)
print("Key with name '{0}' was found.".format(rsa_key.name))
print(f"Key with name '{rsa_key.name}' was found.")

# Let's say we want to update the expiration time for the EC key and disable the key to be usable
# for cryptographic operations. The update method allows the user to modify the metadata (key attributes)
Expand All @@ -71,17 +71,15 @@
ec_key.name, ec_key.properties.version, expires_on=expires, enabled=False
)
print(
"Key with name '{0}' was updated on date '{1}'".format(updated_ec_key.name, updated_ec_key.properties.updated_on)
f"Key with name '{updated_ec_key.name}' was updated on date '{updated_ec_key.properties.updated_on}'"
)
print(
"Key with name '{0}' was updated to expire on '{1}'".format(
updated_ec_key.name, updated_ec_key.properties.expires_on
)
f"Key with name '{updated_ec_key.name}' was updated to expire on '{updated_ec_key.properties.expires_on}'"
)

# The RSA key is no longer used, need to delete it from the Key Vault.
print("\n.. Delete Keys")
client.begin_delete_key(ec_key.name)
client.begin_delete_key(rsa_key.name)
print("Deleted key '{0}'".format(ec_key.name))
print("Deleted key '{0}'".format(rsa_key.name))
print(f"Deleted key '{ec_key.name}'")
print(f"Deleted key '{rsa_key.name}'")

0 comments on commit c345e42

Please sign in to comment.