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

fix(pebble)!: change select=all to users=all for pebble get_notices #1146

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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.12.0

* Updated Pebble Notices `get_notices` parameter name to `users=all` (previously `select=all`).

# 2.11.0

* `StopEvent`, `RemoveEvent`, and all `LifeCycleEvent`s are no longer deferrable, and will raise a `RuntimeError` if `defer()` is called on the event object.
Expand Down
4 changes: 2 additions & 2 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ def get_notice(self, id: str) -> pebble.Notice:
def get_notices(
self,
*,
select: Optional[pebble.NoticesSelect] = None,
users: Optional[pebble.NoticesUsers] = None,
user_id: Optional[int] = None,
types: Optional[Iterable[Union[pebble.NoticeType, str]]] = None,
keys: Optional[Iterable[str]] = None,
Expand All @@ -2768,7 +2768,7 @@ def get_notices(
parameters.
"""
return self._pebble.get_notices(
select=select,
users=users,
user_id=user_id,
types=types,
keys=keys,
Expand Down
14 changes: 7 additions & 7 deletions ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,11 +1316,11 @@ class NoticeType(enum.Enum):
CUSTOM = 'custom'


class NoticesSelect(enum.Enum):
"""Enum of :meth:`Client.get_notices` ``select`` values."""
class NoticesUsers(enum.Enum):
IronCore864 marked this conversation as resolved.
Show resolved Hide resolved
"""Enum of :meth:`Client.get_notices` ``users`` values."""

ALL = 'all'
"""Select notices from all users (any user ID, including public notices).
"""Return notices from all users (any user ID, including public notices).

This only works for Pebble admins (for example, root).
"""
Expand Down Expand Up @@ -2803,7 +2803,7 @@ def get_notice(self, id: str) -> Notice:
def get_notices(
self,
*,
select: Optional[NoticesSelect] = None,
users: Optional[NoticesUsers] = None,
user_id: Optional[int] = None,
types: Optional[Iterable[Union[NoticeType, str]]] = None,
keys: Optional[Iterable[str]] = None,
Expand All @@ -2824,16 +2824,16 @@ def get_notices(
type has nanosecond precision).

Args:
select: Select which notices to return (instead of returning
users: Change which users' notices to return (instead of returning
notices for the current user).
user_id: Filter for notices for the specified user, including
public notices (only works for Pebble admins).
types: Filter for notices with any of the specified types.
keys: Filter for notices with any of the specified keys.
"""
query: Dict[str, Union[str, List[str]]] = {}
if select is not None:
query['select'] = select.value
if users is not None:
query['users'] = users.value
if user_id is not None:
query['user-id'] = str(user_id)
if types is not None:
Expand Down
6 changes: 3 additions & 3 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3361,7 +3361,7 @@ def get_notice(self, id: str) -> pebble.Notice:
def get_notices(
self,
*,
select: Optional[pebble.NoticesSelect] = None,
users: Optional[pebble.NoticesUsers] = None,
user_id: Optional[int] = None,
types: Optional[Iterable[Union[pebble.NoticeType, str]]] = None,
keys: Optional[Iterable[str]] = None,
Expand All @@ -3371,9 +3371,9 @@ def get_notices(
filter_user_id = 0 # default is to filter by request UID (root)
if user_id is not None:
filter_user_id = user_id
if select is not None:
if users is not None:
if user_id is not None:
raise self._api_error(400, 'cannot use both "select" and "user_id"')
raise self._api_error(400, 'cannot use both "users" and "user_id"')
filter_user_id = None

if types is not None:
Expand Down
4 changes: 2 additions & 2 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ def test_get_notices(self):

notices = self.container.get_notices(
user_id=1000,
select=pebble.NoticesSelect.ALL,
users=pebble.NoticesUsers.ALL,
types=[pebble.NoticeType.CUSTOM],
keys=['example.com/a', 'example.com/b'],
)
Expand All @@ -1988,7 +1988,7 @@ def test_get_notices(self):

self.assertEqual(self.pebble.requests, [('get_notices', dict(
user_id=1000,
select=pebble.NoticesSelect.ALL,
users=pebble.NoticesUsers.ALL,
types=[pebble.NoticeType.CUSTOM],
keys=['example.com/a', 'example.com/b'],
))])
Expand Down
4 changes: 2 additions & 2 deletions test/test_pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,7 @@ def test_get_notices_filters(self):

notices = self.client.get_notices(
user_id=1000,
select=pebble.NoticesSelect.ALL,
users=pebble.NoticesUsers.ALL,
types=[pebble.NoticeType.CUSTOM],
keys=['example.com/a', 'example.com/b'],
)
Expand All @@ -3042,7 +3042,7 @@ def test_get_notices_filters(self):

query = {
'user-id': '1000',
'select': 'all',
'users': 'all',
'types': ['custom'],
'keys': ['example.com/a', 'example.com/b'],
}
Expand Down
Loading