Skip to content

Commit

Permalink
fix(api): yaml breaklines (#2778)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored Dec 9, 2024
1 parent 2660636 commit 81b3447
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions keep/api/routes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def get_workflows(

# create the workflow DTO
try:
workflow_raw = yaml.safe_load(workflow.workflow_raw)
# very big width to avoid line breaks
workflow_raw = yaml.dump(workflow_raw, width=99999)
workflow_dto = WorkflowDTO(
id=workflow.id,
name=workflow.name,
Expand All @@ -128,7 +131,7 @@ def get_workflows(
interval=workflow.interval,
providers=providers_dto,
triggers=triggers,
workflow_raw=workflow.workflow_raw,
workflow_raw=workflow_raw,
revision=workflow.revision,
last_updated=workflow.last_updated,
last_executions=last_executions,
Expand Down Expand Up @@ -492,7 +495,8 @@ def get_raw_workflow_by_id(
)
},
)



@router.get("/{workflow_id}", description="Get workflow by ID")
def get_workflow_by_id(
workflow_id: str,
Expand All @@ -503,23 +507,22 @@ def get_workflow_by_id(
tenant_id = authenticated_entity.tenant_id
# get all workflow
workflow = get_workflow(tenant_id=tenant_id, workflow_id=workflow_id)

if not workflow:
logger.warning(
f"Tenant tried to get workflow {workflow_id} that does not exist",
extra={"tenant_id": tenant_id},
)
raise HTTPException(404, "Workflow not found")
try:

try:
workflow_yaml = yaml.safe_load(workflow.workflow_raw)
valid_workflow_yaml = {"workflow": workflow_yaml}
final_workflow_raw = yaml.dump(valid_workflow_yaml)
workflow_dto = WorkflowDTO(
id=workflow.id,
name=workflow.name,
description=workflow.description
or "[This workflow has no description]",
description=workflow.description or "[This workflow has no description]",
created_by=workflow.created_by,
creation_time=workflow.creation_time,
interval=workflow.interval,
Expand All @@ -535,7 +538,6 @@ def get_workflow_by_id(
except yaml.YAMLError:
logger.exception("Invalid YAML format")
raise HTTPException(status_code=500, detail="Error fetching workflow meta data")



@router.get("/executions", description="Get workflow executions by alert fingerprint")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "keep"
version = "0.31.1"
version = "0.31.2"
description = "Alerting. for developers, by developers."
authors = ["Keep Alerting LTD"]
packages = [{include = "keep"}]
Expand Down

0 comments on commit 81b3447

Please sign in to comment.