Skip to content

Commit af38166

Browse files
authored
fix: validation for secrets and consts (#4525)
1 parent b600218 commit af38166

File tree

9 files changed

+67
-14
lines changed

9 files changed

+67
-14
lines changed

docs/snippets/providers/http-snippet-autogenerated.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ steps:
2121
params: {value}
2222
proxies: {value}
2323
fail_on_error: {value}
24+
verify: {value}
2425
```
2526
2627
@@ -37,6 +38,7 @@ actions:
3738
body: {value}
3839
params: {value}
3940
proxies: {value}
41+
verify: {value}
4042
```
4143
4244

keep-ui/entities/workflows/lib/validate-yaml.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ export const validateMustacheVariableNameForYAML = (
295295
}
296296
return null;
297297
}
298+
if (parts[0] === "consts") {
299+
const constName = parts[1];
300+
if (!constName) {
301+
return [
302+
`Variable: ${cleanedVariableName} - To access a constant, you need to specify the constant name.`,
303+
];
304+
}
305+
if (!definition.consts?.[constName]) {
306+
return [
307+
`Variable: ${cleanedVariableName} - Constant "${constName}" not found.`,
308+
"error",
309+
];
310+
}
311+
}
298312
if (parts[0] === "steps") {
299313
const stepName = parts[1];
300314
if (!stepName) {

keep-ui/entities/workflows/lib/validation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ export const validateMustacheVariableName = (
4848
}
4949
return null;
5050
}
51+
if (parts[0] === "consts") {
52+
const constName = parts[1];
53+
if (!constName) {
54+
return `Variable: '${variableName}' - To access a constant, you need to specify the constant name.`;
55+
}
56+
if (!definition.properties.consts?.[constName]) {
57+
return `Variable: '${variableName}' - Constant '${constName}' not found.`;
58+
}
59+
}
5160
if (parts[0] === "steps") {
5261
const stepName = parts[1];
5362
if (!stepName) {

keep-ui/entities/workflows/model/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export const WorkflowPropertiesSchema = z.object({
199199
description: z.string().min(1),
200200
disabled: z.boolean(),
201201
isLocked: z.boolean(),
202-
consts: z.record(z.string(), z.string()),
202+
consts: z.record(z.string(), z.string()).optional(),
203203
alert: AlertTriggerValueSchema.optional(),
204204
interval: IntervalTriggerValueSchema.optional(),
205205
incident: IncidentTriggerValueSchema.optional(),

keep-ui/shared/ui/WorkflowYAMLEditor/lib/useYamlValidation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export interface UseYamlValidationResult {
2020
validationErrors: YamlValidationError[] | null;
2121
validateMustacheExpressions: (
2222
model: editor.ITextModel | null,
23-
monaco: typeof import("monaco-editor") | null
23+
monaco: typeof import("monaco-editor") | null,
24+
secrets: Record<string, string>
2425
) => void;
2526
handleMarkersChanged: (
2627
editor: editor.IStandaloneCodeEditor,
@@ -92,7 +93,8 @@ export function useYamlValidation({
9293
const validateMustacheExpressions = useCallback(
9394
(
9495
model: editor.ITextModel | null,
95-
monaco: typeof import("monaco-editor") | null
96+
monaco: typeof import("monaco-editor") | null,
97+
secrets: Record<string, string> = {}
9698
) => {
9799
if (!model || !monaco) {
98100
return;
@@ -113,8 +115,6 @@ export function useYamlValidation({
113115
const mustacheRegex = /\{\{([^}]+)\}\}/g;
114116
// Collect markers to add to the model
115117
const markers: editor.IMarkerData[] = [];
116-
// Use an empty secrets object for now - could be passed as a prop in the future
117-
const secrets: Record<string, string> = {};
118118

119119
let match;
120120
while ((match = mustacheRegex.exec(text)) !== null) {
@@ -159,7 +159,7 @@ export function useYamlValidation({
159159
currentStep,
160160
currentStepType,
161161
workflowDefinition.workflow,
162-
secrets,
162+
secrets ?? {},
163163
providers ?? null,
164164
installedProviders ?? null
165165
);

keep-ui/shared/ui/WorkflowYAMLEditor/ui/WorkflowYAMLEditor.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { YamlValidationError } from "../model/types";
1818
import { useYamlValidation } from "../lib/useYamlValidation";
1919
import { WorkflowYAMLEditorToolbar } from "./WorkflowYAMLEditorToolbar";
2020
import { navigateToErrorPosition } from "../lib/utils";
21+
import { useWorkflowSecrets } from "@/utils/hooks/useWorkflowSecrets";
2122

2223
const KeepSchemaPath = "file:///workflow-schema.json";
2324

@@ -51,6 +52,8 @@ export const WorkflowYAMLEditor = ({
5152
}: WorkflowYAMLEditorProps) => {
5253
const monacoRef = useRef<typeof import("monaco-editor") | null>(null);
5354
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);
55+
const { getSecrets } = useWorkflowSecrets(workflowId);
56+
const { data: secrets } = getSecrets;
5457

5558
const {
5659
validationErrors,
@@ -81,7 +84,8 @@ export const WorkflowYAMLEditor = ({
8184
if (editorRef.current && monacoRef.current) {
8285
validateMustacheExpressions(
8386
editorRef.current.getModel(),
84-
monacoRef.current
87+
monacoRef.current,
88+
secrets ?? {}
8589
);
8690
}
8791
},
@@ -117,7 +121,8 @@ export const WorkflowYAMLEditor = ({
117121
if (isEditorMounted && editorRef.current && monacoRef.current) {
118122
validateMustacheExpressions(
119123
editorRef.current.getModel(),
120-
monacoRef.current
124+
monacoRef.current,
125+
secrets ?? {}
121126
);
122127
}
123128
}, [validateMustacheExpressions, isEditorMounted]);

keep-ui/utils/hooks/useWorkflowSecrets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useState } from "react";
22
import { useApi } from "@/shared/lib/hooks/useApi";
33
import useSWR from "swr";
44

5-
export function useWorkflowSecrets(workflowId: string | null) {
5+
export function useWorkflowSecrets(workflowId: string | null | undefined) {
66
const api = useApi();
77
const [error, setError] = useState<string>("");
88

keep/providers/http_provider/http_provider.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _notify(
5656
body: dict = None,
5757
params: dict = None,
5858
proxies: dict = None,
59+
verify: bool = True,
5960
**kwargs,
6061
):
6162
"""
@@ -68,6 +69,7 @@ def _notify(
6869
body=body,
6970
params=params,
7071
proxies=proxies,
72+
verify=verify,
7173
**kwargs,
7274
)
7375

@@ -80,6 +82,7 @@ def _query(
8082
params: dict = None,
8183
proxies: dict = None,
8284
fail_on_error: bool = True,
85+
verify: bool = True,
8386
**kwargs: dict,
8487
) -> dict:
8588
"""
@@ -107,19 +110,39 @@ def _query(
107110
)
108111
if method == "GET":
109112
response = requests.get(
110-
url, headers=headers, params=params, proxies=proxies, **kwargs
113+
url,
114+
headers=headers,
115+
params=params,
116+
proxies=proxies,
117+
verify=verify,
118+
**kwargs,
111119
)
112120
elif method == "POST":
113121
response = requests.post(
114-
url, headers=headers, json=body, proxies=proxies, **kwargs
122+
url,
123+
headers=headers,
124+
json=body,
125+
proxies=proxies,
126+
verify=verify,
127+
**kwargs,
115128
)
116129
elif method == "PUT":
117130
response = requests.put(
118-
url, headers=headers, json=body, proxies=proxies, **kwargs
131+
url,
132+
headers=headers,
133+
json=body,
134+
proxies=proxies,
135+
verify=verify,
136+
**kwargs,
119137
)
120138
elif method == "DELETE":
121139
response = requests.delete(
122-
url, headers=headers, json=body, proxies=proxies, **kwargs
140+
url,
141+
headers=headers,
142+
json=body,
143+
proxies=proxies,
144+
verify=verify,
145+
**kwargs,
123146
)
124147
else:
125148
raise Exception(f"Unsupported HTTP method: {method}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "keep"
3-
version = "0.41.18"
3+
version = "0.41.19"
44
description = "Alerting. for developers, by developers."
55
authors = ["Keep Alerting LTD"]
66
packages = [{include = "keep"}]

0 commit comments

Comments
 (0)