Skip to content

Commit

Permalink
Add output-json parameter to publish command for use by downstream pr…
Browse files Browse the repository at this point in the history
…ocesses.
  • Loading branch information
dbernstein committed Oct 20, 2023
1 parent 07eecb7 commit 8b7a667
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ def import_template(
help="The namespace you wish to target (e.g. tpp-prod, tpp-dev, tpp-staging).",
)
@click.option("--group-name", required=True, help="Name of the Quicksight User Group")
@click.option(
"--output-json",
required=True,
help="The file path to which operation output should be written as json",
)
def publish_dashboard(
aws_account_id: str,
template_id: str,
target_namespace: str,
group_name: str,
output_json: str,
):
"""
Create/Update a dashboard from a template
Expand All @@ -141,6 +147,7 @@ def publish_dashboard(
template_id=template_id,
target_namespace=target_namespace,
group_name=group_name,
output_json=output_json,
).execute()
log.info(result)

Expand Down
17 changes: 15 additions & 2 deletions core/operation/publish_dashboard_from_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ class PublishDashboardFromTemplateOperation(BaseOperation):
"""

def __init__(
self, template_id: str, target_namespace: str, group_name: str, *args, **kwargs
self,
template_id: str,
target_namespace: str,
group_name: str,
output_json: str,
*args,
**kwargs,
):
self._template_id = template_id
self._target_namespace = target_namespace
self._group_name = group_name
self._output_json = output_json
super().__init__(*args, **kwargs)

def execute(self) -> dict:
Expand Down Expand Up @@ -110,12 +117,18 @@ def execute(self) -> dict:
f"Unexpected response from trying to update_dashboard_permissions : {json.dumps(response, indent=4)} "
)

return {
result = {
"status": "success",
"dashboard_arn": dashboard_arn,
"dashboard_id": dashboard_id,
}

with open(self._output_json, "w") as output:
output.write(json.dumps(result))
self._log.info(f"Output written to {self._output_json}")

return result

def _create_or_update_dashboard(self, dashboard_params: dict) -> tuple[str, str]:
"""
Creates new or updates existing template.
Expand Down
12 changes: 12 additions & 0 deletions tests/core/operation/test_publish_operation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import json
import os.path
import tempfile

import botocore
from botocore.config import Config
from botocore.stub import Stubber
Expand All @@ -14,6 +18,8 @@ def test(self):
account = "012345678910"
group_name = "my_group"

output_json = tempfile.NamedTemporaryFile()

boto_config = Config(
region_name="us-east-1",
)
Expand Down Expand Up @@ -188,9 +194,15 @@ def test(self):
target_namespace=target_namespace,
aws_account_id=account,
group_name=group_name,
output_json=output_json.name,
)

result = op.execute()

assert result["status"] == "success"
assert result["dashboard_id"] == template_id
assert os.path.exists(output_json.name)

with open(output_json.name) as file:
result_from_file = json.loads(file.read())
assert result_from_file["dashboard_id"] == result["dashboard_id"]

0 comments on commit 8b7a667

Please sign in to comment.