Skip to content

Commit

Permalink
94 feat improve cli commands (#100)
Browse files Browse the repository at this point in the history
* refactor(docker-compose.yml): adding env variable

* feat(cli/configs.py): adding syntax highlight to details

* refactor(cli/pipelines.py): changing pipelines command arguments

* refactor(docker-compose.yml): adding env variable

* feat(cli/configs.py): adding syntax highlight to details

* refactor(cli/pipelines.py): changing pipelines command arguments
  • Loading branch information
odarotto committed Jul 26, 2024
1 parent 1a2fffe commit fe78020
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 26 deletions.
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ services:
- SANIC_HEALTH_MANAGERS_CHECK_TIMES=10
- SANIC_HEALTH_MANAGERS_CHECK_INTERVAL_SECONDS=30
- SANIC_LISTENERS_THRESHOLD_SECONDS=120
- SANIC_WORKSPACE_FILEPATH=/etc/workspace.yml
- TZ=Etc/UTC
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./workflow/workspaces/development.yml:/etc/workspace.yml
networks:
- workflow

Expand Down
26 changes: 14 additions & 12 deletions workflow/cli/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml
from rich import pretty
from rich.console import Console
from rich.json import JSON
from rich.syntax import Syntax
from rich.table import Table
from rich.text import Text
from yaml import safe_load
Expand Down Expand Up @@ -110,8 +110,10 @@ def deploy(filename: click.Path):
except requests.HTTPError as deploy_error:
console.print(deploy_error.response.json()["error_description"][0]["msg"])
return
header_text = Text("Config deployed: ")
header_text.append(data["name"], style="blink underline bright_blue")
table.add_column(
"Deploy Result",
header=header_text,
min_width=35,
max_width=50,
justify="left",
Expand Down Expand Up @@ -192,7 +194,7 @@ def ps(name: str, id: str, details: bool):
projection: str = json.dumps({})
console_content = None
column_max_width = 300
column_min_width = 40
column_min_width = 50
try:
payload = http.configs.get_configs(
name=name, query=query, projection=projection
Expand All @@ -210,20 +212,20 @@ def ps(name: str, id: str, details: bool):
)
text.append(render_config(http, payload))
if details:
table.add_column("Details", max_width=column_max_width, justify="left")
_details = safe_load(payload["yaml"])
_details = {
k: v
for k, v in _details.items()
if k not in ["name", "version", "deployments"]
}
table.add_row(text, JSON(json.dumps(_details), indent=2))
table.add_column(
"Details",
max_width=column_max_width,
min_width=column_min_width,
justify="left",
)
_details = payload["yaml"]
table.add_row(text, Syntax(_details, "yaml"))
else:
table.add_row(text)
table.add_section()
table.add_row(
Text("Explore pipelines in detail: \n", style="magenta i").append(
"workflow pipelines ps <config_name> <pipeline_id>",
"workflow pipelines ps <pipeline_id>",
style="dark_blue on cyan",
)
)
Expand Down
20 changes: 16 additions & 4 deletions workflow/cli/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,31 @@ def count():


@pipelines.command("ps", help="Get pipeline details.")
@click.argument("pipeline", type=str, required=True)
# @click.argument("pipeline", type=str, required=True)
@click.argument("id", type=str, required=True)
def ps(pipeline: str, id: str):
def ps(id: str):
"""List a pipeline configuration in detail."""
http = HTTPContext()
query: str = json.dumps({"id": id})
projection: str = json.dumps({})
console_content = None
column_max_width = 300
column_min_width = 40
# ? Get Config name, needed for querying the pipeline
try:
config_name = http.configs.get_configs(
query=json.dumps({"pipelines": id}), projection=json.dumps({"name": 1})
)[0]["name"]
except Exception:
error_text = Text(
f"Could not found any Config parent for Pipeline {id}.", style="red"
)
console.print(error_text)
return
# ? Get the pipeline
try:
payload = http.pipelines.get_pipelines(
name=pipeline, query=query, projection=projection
name=config_name, query=query, projection=projection
)[
0 # type: ignore
]
Expand All @@ -114,7 +126,7 @@ def ps(pipeline: str, id: str):
else:
text = Text()
table.add_column(
f"Pipeline: {pipeline}",
f"Pipeline: {config_name}",
min_width=column_min_width,
max_width=column_max_width,
justify="left",
Expand Down
31 changes: 26 additions & 5 deletions workflow/utils/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,45 @@ def render_config(http: HTTPContext, payload: Dict[str, Any]) -> Text:
key_value_text = Text()
if k == "pipelines":
key_value_text.append(f"{k}: \n", style="bright_blue")
for child in pipelines_statuses:
for status in pipelines_statuses:
key_value_text.append(
f"\t{child['id']}: ", # type: ignore
style=status_colors[child["status"]], # type: ignore
f"\t{status['id']}: ", # type: ignore
style=f"{status_colors[status['status']]}", # type: ignore
)
key_value_text.append(
f"{status_symbols[child['status']]}\n", # type: ignore
style=status_colors[child["status"]], # type: ignore
f"{status_symbols[status['status']]}\n", # type: ignore
style=status_colors[status["status"]], # type: ignore
)
text.append_text(key_value_text)
continue
if k == "deployments":
key_value_text.append(f"{k}: \n", style="bright_blue")
if v:
for deployment in v:
key_value_text.append_text(render_dict(deployment))
key_value_text.append("\n")
text.append_text(key_value_text)
continue
continue
key_value_text.append(f"{k}: ", style="bright_blue")
key_value_text.append(f"{v}\n", style="white")
text.append_text(key_value_text)

return text


def render_dict(payload: Dict[str, Any], listing: bool = True) -> Text:
text = Text(" - " if listing else "")
for i_k, i_v in payload.items():
if isinstance(i_v, dict):
text.append(render_dict(i_v, listing=False))
continue
text.append(
f"\t{i_k}: ", style="bright_green"
)
text.append(f"{i_v}\n")
return text

def clean_output(message: str) -> str:
"""Cleans strings from Click.command output.
Expand Down
5 changes: 0 additions & 5 deletions workflow/workspaces/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ config:
- "move"
storage: "posix"
results: true
permissions:
posix:
user: "user"
group: "chime-frb-ro"
command: "setfacl -R -m g:{group}:r {path}"

deployers:
local:
Expand Down

0 comments on commit fe78020

Please sign in to comment.