Skip to content

Commit

Permalink
feat: add the description field to SecretInfo (#1338)
Browse files Browse the repository at this point in the history
The `SecretInfo` class exposed all the fields from `secret-info-get`
exception `description`. This PR adds that field as well.

Fixes #1289.
  • Loading branch information
tonyandrewmeyer authored Aug 26, 2024
1 parent 3677507 commit a0b1480
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,13 +1181,15 @@ def __init__(
expires: Optional[datetime.datetime],
rotation: Optional[SecretRotate],
rotates: Optional[datetime.datetime],
description: Optional[str] = None,
):
self.id = Secret._canonicalize_id(id)
self.label = label
self.revision = revision
self.expires = expires
self.rotation = rotation
self.rotates = rotates
self.description = description

@classmethod
def from_dict(cls, id: str, d: Dict[str, Any]) -> 'SecretInfo':
Expand All @@ -1205,6 +1207,7 @@ def from_dict(cls, id: str, d: Dict[str, Any]) -> 'SecretInfo':
expires=timeconv.parse_rfc3339(expires) if expires is not None else None,
rotation=rotation,
rotates=timeconv.parse_rfc3339(rotates) if rotates is not None else None,
description=typing.cast(Optional[str], d.get('description')),
)

def __repr__(self):
Expand All @@ -1215,7 +1218,8 @@ def __repr__(self):
f'revision={self.revision}, '
f'expires={self.expires!r}, '
f'rotation={self.rotation}, '
f'rotates={self.rotates!r})'
f'rotates={self.rotates!r}, '
f'description={self.description!r})'
)


Expand Down
1 change: 1 addition & 0 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2814,6 +2814,7 @@ def secret_info_get(
expires=secret.expire_time,
rotation=rotation,
rotates=rotates,
description=secret.description,
)

def secret_set(
Expand Down
5 changes: 5 additions & 0 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3565,13 +3565,15 @@ def test_init(self):
expires=datetime.datetime(2022, 12, 9, 14, 10, 0),
rotation=ops.SecretRotate.MONTHLY,
rotates=datetime.datetime(2023, 1, 9, 14, 10, 0),
description='desc',
)
assert info.id == 'secret:3'
assert info.label == 'lbl'
assert info.revision == 7
assert info.expires == datetime.datetime(2022, 12, 9, 14, 10, 0)
assert info.rotation == ops.SecretRotate.MONTHLY
assert info.rotates == datetime.datetime(2023, 1, 9, 14, 10, 0)
assert info.description == 'desc'

assert repr(info).startswith('SecretInfo(')
assert repr(info).endswith(')')
Expand All @@ -3586,6 +3588,7 @@ def test_from_dict(self):
'expiry': '2022-12-09T14:10:00Z',
'rotation': 'yearly',
'rotates': '2023-01-09T14:10:00Z',
'description': 'desc',
},
)
assert info.id == 'secret:4'
Expand All @@ -3594,6 +3597,7 @@ def test_from_dict(self):
assert info.expires == datetime.datetime(2022, 12, 9, 14, 10, 0, tzinfo=utc)
assert info.rotation == ops.SecretRotate.YEARLY
assert info.rotates == datetime.datetime(2023, 1, 9, 14, 10, 0, tzinfo=utc)
assert info.description == 'desc'

info = ops.SecretInfo.from_dict(
'secret:4',
Expand All @@ -3609,6 +3613,7 @@ def test_from_dict(self):
assert info.expires is None
assert info.rotation is None
assert info.rotates is None
assert info.description is None

info = ops.SecretInfo.from_dict('5', {'revision': 9})
assert info.id == 'secret:5'
Expand Down

0 comments on commit a0b1480

Please sign in to comment.