Skip to content

Commit

Permalink
Correctly pluralise config types and sort them alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Basche authored and Tom Basche committed Dec 15, 2019
1 parent 0ccdf9b commit 7d8a9f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions doghouse/datadog_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def __make_api_request(self, resource, method, key, *args, **kwargs):
f"Have your credentials been set in {self.default_config_file}?"
)
else:
to_return = objs
if key:
return objs[key]
return objs
to_return = objs[key]
return sorted(to_return, key=lambda x: x.get('title', x.get('name')))
return []

def get_dashboards(self) -> list:
Expand Down
14 changes: 8 additions & 6 deletions doghouse/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CONFIG_DIR = f"{DATADOG_CLIENT.home}/{DATADOG_CLIENT.config_dir}"

ACCEPTABLE_TYPES = ["monitor", "dashboard"]
PLURAL_ACCEPTABLE_TYPES = ["monitors", "dashboards"]
FILES = [f"{type_}s" for type_ in ACCEPTABLE_TYPES]
PUSH_CONFIG: Dict[str, Callable] = {k: lambda x: x for k in FILES}

Expand Down Expand Up @@ -157,15 +158,16 @@ def configure(api_key, app_key):
@main.command()
@click.argument("config_type", type=str)
def list(config_type): # noqa
if config_type not in ACCEPTABLE_TYPES:
click.echo(f"list <config_type> must be one of {','.join(ACCEPTABLE_TYPES)}")
if config_type not in PLURAL_ACCEPTABLE_TYPES:
click.echo(f"list <config_type> must be one of {','.join(PLURAL_ACCEPTABLE_TYPES)}")
return
if config_type == "monitor":
if config_type == "monitors":
objs = DATADOG_CLIENT.get_monitors()

if config_type == "dashboard":
elif config_type == "dashboards":
objs = DATADOG_CLIENT.get_dashboards()
click.echo(f"\nListing {config_type}s: ")
else:
return
click.echo(f"\nListing {config_type}: ")
for obj in objs:
click.echo(f" - {obj.get('title', obj.get('name'))}")

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
config_dir = ".doghouse"
Path(Path.home() / config_dir).mkdir(parents=True, exist_ok=True)

VERSION = "0.1"

setup(
name="doghouse",
version="0.1",
version=VERSION,
description="Datadog config as code",
author="Thomas Basche",
author_email="[email protected]",
Expand Down

0 comments on commit 7d8a9f5

Please sign in to comment.