Skip to content

Commit

Permalink
[KeyVault] - Fix key rotation sample (#18100)
Browse files Browse the repository at this point in the history
Recent Key Vault service changes for Key Rotation resulted in this sample causing a runtime error. @mccoyp noticed that the
JS sample is now outdated and would not work with the new validation rules in place.

To be specific, the validation rules always existed; however, they weren't enforced until recently.

This commit fixes the sample so that it works again
  • Loading branch information
maorleger authored Oct 8, 2021
1 parent 4e25dba commit 3304363
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sdk/keyvault/keyvault-keys/samples-dev/keyRotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ export async function main(): Promise<void> {
const key = await client.createKey(keyName, "EC");
console.log("created key", key);

// Set the key's automated rotation policy to rotate 30 days before the key expires.
// Set the key's automated rotation policy to rotate the key 30 days after the key is created.
const policy = await client.updateKeyRotationPolicy(key.name, {
lifetimeActions: [
{
action: "Rotate",
timeBeforeExpiry: "P30D"
timeAfterCreate: "P30D"
}
],
expiresIn: "P90D"
]
});
console.log("created policy", policy);

// Get the key's current rotation policy
const currentPolicy = await client.getKeyRotationPolicy(key.name);
console.log("fetched policy", currentPolicy);

// Update the key's automated rotation policy to notify 30 days after the key was created
// Update the key's automated rotation policy to notify 30 days before the key expires.
const updatedPolicy = await client.updateKeyRotationPolicy(key.name, {
lifetimeActions: [
{
action: "Notify",
timeAfterCreate: "P30D"
timeBeforeExpiry: "P30D"
}
]
],
expiresIn: "P90D"
});
console.log("updated policy", updatedPolicy);

Expand Down

0 comments on commit 3304363

Please sign in to comment.