|
6 | 6 |
|
7 | 7 | import json |
8 | 8 | import logging |
9 | | -from typing import Any |
| 9 | +from typing import TYPE_CHECKING, Any |
10 | 10 |
|
11 | 11 | import click |
12 | 12 | import yaml |
|
38 | 38 | ) |
39 | 39 | from policy_sentry.util.access_levels import transform_access_level_text |
40 | 40 |
|
| 41 | +if TYPE_CHECKING: |
| 42 | + from collections.abc import Iterable |
| 43 | + |
41 | 44 | logger = logging.getLogger(__name__) |
42 | 45 | iam_definition_path = DATASTORE_FILE_PATH |
43 | 46 |
|
44 | 47 |
|
45 | | -def print_list(output: list[Any], fmt: str = "json") -> None: |
| 48 | +def print_list(output: Iterable[Any], fmt: str = "json") -> None: |
46 | 49 | """Common method on how to print a list, depending on whether the user requests JSON or YAML output""" |
47 | 50 | print(yaml.dump(output)) if fmt == "yaml" else [print(item) for item in output] |
48 | 51 |
|
@@ -135,7 +138,7 @@ def query_action_table( |
135 | 138 | condition: str, |
136 | 139 | resource_type: str, |
137 | 140 | fmt: str = "json", |
138 | | -) -> list[str] | dict[str, list[dict[str, Any]]]: |
| 141 | +) -> Iterable[str]: |
139 | 142 | """Query the Action Table from the Policy Sentry database. |
140 | 143 | Use this one when leveraging Policy Sentry as a library.""" |
141 | 144 | if LOCAL_DATASTORE_FILE_PATH.exists(): |
@@ -164,7 +167,7 @@ def query_action_table( |
164 | 167 | else: |
165 | 168 | print("All services in the database:\n") |
166 | 169 | # it is a set here, which is ok |
167 | | - output = all_services # type:ignore[assignment] |
| 170 | + output = all_services |
168 | 171 | print_list(output=output, fmt=fmt) |
169 | 172 | elif name is None and access_level and not resource_type: |
170 | 173 | print(f"All IAM actions under the {service} service that have the access level {access_level}:") |
|
0 commit comments