active_only argument for list subscription types

pull/105/head
Neeraj Kashyap 2021-08-12 16:05:42 -07:00
rodzic 5fd3a4797d
commit 01303ebd7d
2 zmienionych plików z 22 dodań i 3 usunięć

Wyświetl plik

@ -97,6 +97,11 @@ This CLI is configured to work with the following API URLs:
parser_subscription_types_list = subcommands_subscription_types.add_parser(
"list", description="List subscription types"
)
parser_subscription_types_list.add_argument(
"--active",
action="store_true",
help="Set this flag to only list active subscription types",
)
parser_subscription_types_list.set_defaults(
func=subscription_types.cli_list_subscription_types
)

Wyświetl plik

@ -134,23 +134,37 @@ def cli_create_subscription_type(args: argparse.Namespace) -> None:
print(result.json())
def list_subscription_types() -> BugoutResources:
def list_subscription_types(active_only: bool = False) -> BugoutResources:
"""
Lists all subscription types registered as Brood resources for this Moonstream application.
Args:
- active_only: Set this to true if you only want to list active subscription types. By default,
all subscription types are listed, be they active or inactive.
"""
response = bc.list_resources(
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
params={"type": BUGOUT_RESOURCE_TYPE},
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
)
return response
# TODO(kompotkot): Currently, we cannot filter using non-string fields in Brood resources. This means
# that we have to implement the active_only filter in this API instead of just setting a query parameter
# in the Brood API call. This should be fixed.
if not active_only:
return response
active_resources = [
resource for resource in response.resources if resource.resource_data["active"]
]
return BugoutResources(resources=active_resources)
def cli_list_subscription_types(args: argparse.Namespace) -> None:
"""
Handler for "mnstr subtypes list".
"""
results = list_subscription_types()
results = list_subscription_types(args.active)
print(results.json())