Skip to content

Commit 47ebf52

Browse files
authored
[Key Vault] Update default value of lifetime_actions (Azure#24070)
1 parent 3c5b585 commit 47ebf52

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

sdk/keyvault/azure-keyvault-keys/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 4.5.1 (2022-04-19)
3+
## 4.5.1 (2022-04-18)
44

55
### Bugs Fixed
66
- Fixed error that could occur when fetching a key rotation policy that has no defined

sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_models.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,14 @@ class KeyRotationLifetimeAction(object):
291291
:param action: The action that will be executed.
292292
:type action: ~azure.keyvault.keys.KeyRotationPolicyAction or str
293293
294-
:keyword str time_after_create: Time after creation to attempt the specified action, as an ISO 8601 duration.
294+
:keyword time_after_create: Time after creation to attempt the specified action, as an ISO 8601 duration.
295295
For example, 90 days is "P90D". See `Wikipedia <https://wikipedia.org/wiki/ISO_8601#Durations>`_ for more
296296
information on ISO 8601 durations.
297-
:keyword str time_before_expiry: Time before expiry to attempt the specified action, as an ISO 8601 duration.
297+
:paramtype time_after_create: Optional[str]
298+
:keyword time_before_expiry: Time before expiry to attempt the specified action, as an ISO 8601 duration.
298299
For example, 90 days is "P90D". See `Wikipedia <https://wikipedia.org/wiki/ISO_8601#Durations>`_ for more
299300
information on ISO 8601 durations.
301+
:paramtype time_before_expiry: Optional[str]
300302
"""
301303

302304
def __init__(self, action, **kwargs):
@@ -319,30 +321,32 @@ def _from_generated(cls, lifetime_action):
319321
class KeyRotationPolicy(object):
320322
"""The key rotation policy that belongs to a key.
321323
322-
:ivar str id: The identifier of the key rotation policy.
324+
:ivar id: The identifier of the key rotation policy.
325+
:vartype id: Optional[str]
323326
:ivar lifetime_actions: Actions that will be performed by Key Vault over the lifetime of a key.
324327
:vartype lifetime_actions: List[~azure.keyvault.keys.KeyRotationLifetimeAction]
325-
:ivar str expires_in: The expiry time of the policy that will be applied on new key versions, defined as an ISO 8601
328+
:ivar expires_in: The expiry time of the policy that will be applied on new key versions, defined as an ISO 8601
326329
duration. For example, 90 days is "P90D". See `Wikipedia <https://wikipedia.org/wiki/ISO_8601#Durations>`_ for
327330
more information on ISO 8601 durations.
331+
:vartype expires_in: Optional[str]
328332
:ivar created_on: When the policy was created, in UTC
329-
:vartype created_on: ~datetime.datetime
333+
:vartype created_on: Optional[~datetime.datetime]
330334
:ivar updated_on: When the policy was last updated, in UTC
331-
:vartype updated_on: ~datetime.datetime
335+
:vartype updated_on: Optional[~datetime.datetime]
332336
"""
333337

334338
def __init__(self, **kwargs):
335339
# type: (**Any) -> None
336340
self.id = kwargs.get("policy_id", None)
337-
self.lifetime_actions = kwargs.get("lifetime_actions", None)
341+
self.lifetime_actions = kwargs.get("lifetime_actions", [])
338342
self.expires_in = kwargs.get("expires_in", None)
339343
self.created_on = kwargs.get("created_on", None)
340344
self.updated_on = kwargs.get("updated_on", None)
341345

342346
@classmethod
343347
def _from_generated(cls, policy):
344348
lifetime_actions = (
345-
None
349+
[]
346350
if policy.lifetime_actions is None
347351
else [KeyRotationLifetimeAction._from_generated(action) for action in policy.lifetime_actions] # pylint:disable=protected-access
348352
)

sdk/keyvault/azure-keyvault-keys/tests/test_key_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
KeyRotationPolicyAction,
2222
KeyType,
2323
)
24+
from azure.keyvault.keys._generated.v7_3.models import KeyRotationPolicy as _KeyRotationPolicy
2425
import pytest
2526
from six import byte2int
2627

@@ -754,3 +755,11 @@ def test_case_insensitive_key_type():
754755
assert KeyType("OCT") == KeyType.oct
755756
# KeyType with mixed-case value
756757
assert KeyType("oct-hsm") == KeyType.oct_hsm
758+
759+
760+
def test_empty_rotation_policy_actions():
761+
"""Regression test: make sure a KeyRotationPolicy can be created with a response that has None properties"""
762+
generated_policy = _KeyRotationPolicy()
763+
assert generated_policy.lifetime_actions is None
764+
policy = KeyRotationPolicy._from_generated(generated_policy)
765+
assert policy.lifetime_actions == []

0 commit comments

Comments
 (0)