Skip to content

Commit f147abe

Browse files
committed
add watchlists commands
1 parent 635262e commit f147abe

10 files changed

Lines changed: 1139 additions & 112 deletions

File tree

docs/cli/watchlists.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Watchlist Commands
2+
3+
::: mkdocs-click
4+
:module: incydr.cli.cmds.watchlists
5+
:command: list_
6+
7+
::: mkdocs-click
8+
:module: incydr.cli.cmds.watchlists
9+
:command: show
10+
11+
::: mkdocs-click
12+
:module: incydr.cli.cmds.watchlists
13+
:command: create
14+
15+
::: mkdocs-click
16+
:module: incydr.cli.cmds.watchlists
17+
:command: update
18+
19+
::: mkdocs-click
20+
:module: incydr.cli.cmds.watchlists
21+
:command: delete
22+
23+
::: mkdocs-click
24+
:module: incydr.cli.cmds.watchlists
25+
:command: members
26+
:list_subcommands:
27+
28+
::: mkdocs-click
29+
:module: incydr.cli.cmds.watchlists
30+
:command: included_users
31+
:list_subcommands:
32+
33+
::: mkdocs-click
34+
:module: incydr.cli.cmds.watchlists
35+
:command: excluded_users
36+
:list_subcommands:
37+
38+
::: mkdocs-click
39+
:module: incydr.cli.cmds.watchlists
40+
:command: directory_groups
41+
:list_subcommands:
42+
43+
::: mkdocs-click
44+
:module: incydr.cli.cmds.watchlists
45+
:command: departments
46+
:list_subcommands:

incydr/_watchlists/client.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,6 @@ def __init__(self, parent):
5252
self._watchlist_type_id_map = {}
5353
self._uri = "/v1/watchlists"
5454

55-
# @property
56-
# def watchlist_type_id_map(self):
57-
# """Map watchlist types to IDs, if they exist."""
58-
# if not self._watchlist_type_id_map:
59-
# self._watchlist_type_id_map = {}
60-
# watchlists = self.get_page(page_size=100).watchlists
61-
# for item in watchlists:
62-
# if item.list_type == "CUSTOM":
63-
# # store title for custom lists instead of list_type
64-
# self._watchlist_type_id_map[item.title] = item.watchlist_id
65-
# self._watchlist_type_id_map[item.list_type] = item.watchlist_id
66-
# return self._watchlist_type_id_map
67-
6855
def get_page(
6956
self, page_num: int = 1, page_size: int = None, user_id: str = None
7057
) -> WatchlistsPage:

incydr/_watchlists/models/responses.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,34 @@ class WatchlistStats(ResponseModel):
177177
None,
178178
description="The number of users explicitly excluded from the watchlist.",
179179
alias="excludedUsersCount",
180+
# displays a value of None as 0
181+
table=lambda excluded_users_count: excluded_users_count
182+
if excluded_users_count
183+
else 0,
180184
)
181185
included_departments_count: Optional[int] = Field(
182186
None,
183187
description="The number of departments explicitly included on the watchlist.",
184188
alias="includedDepartmentsCount",
189+
table=lambda included_departments_count: included_departments_count
190+
if included_departments_count
191+
else 0,
185192
)
186193
included_directory_groups_count: Optional[int] = Field(
187194
None,
188195
description="The number of directory groups explicitly included on the watchlist.",
189196
alias="includedDirectoryGroupsCount",
197+
table=lambda included_directory_groups_count: included_directory_groups_count
198+
if included_directory_groups_count
199+
else 0,
190200
)
191201
included_users_count: Optional[int] = Field(
192202
None,
193203
description="The number of users explicitly included on the watchlist.",
194204
alias="includedUsersCount",
205+
table=lambda included_users_count: included_users_count
206+
if included_users_count
207+
else 0,
195208
)
196209

197210

incydr/cli/cmds/utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ def output_format_logger(
119119

120120

121121
def user_lookup(client, value):
122+
"""
123+
Returns the user ID for a given username, or returns the value unchanged if not a username.
124+
125+
Used with the `user_lookup_callback` method on user args.
126+
"""
122127
if "@" in str(value):
123128
# assume username/email was passed
124129
users = client.users.v1.get_page(username=value).users
@@ -142,11 +147,14 @@ def output_single_format(
142147
echo(result.json())
143148

144149

145-
# Drop in replacements for getattr() and setattr() that account for nested attributes
146-
# specified by dot notation
147-
148-
# See https://stackoverflow.com/questions/31174295/getattr-and-setattr-on-nested-objects/31174427?noredirect=1#comment86638618_31174427
150+
# TODO: these methods can be removed once the alerts outputting is refactored
149151
def rgetattr(obj, attr, *args):
152+
"""
153+
Drop in replacements for getattr() and setattr() that account for nested attributes specified by dot notation
154+
155+
See https://stackoverflow.com/questions/31174295/getattr-and-setattr-on-nested-objects/31174427?noredirect=1#comment86638618_31174427
156+
"""
157+
150158
def _getattr(obj, attr):
151159
return getattr(obj, attr, *args)
152160

0 commit comments

Comments
 (0)