Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the description field to SecretInfo #1338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading