Compare commits

...

1 Commits

Author SHA1 Message Date
YannC.
aee4524b7e fix: throw an error when trying to create a flow with a reserved keyword id
close #5832
2025-08-25 11:57:28 +02:00
2 changed files with 36 additions and 0 deletions

View File

@@ -36,6 +36,19 @@ import static io.kestra.core.models.Label.SYSTEM_PREFIX;
@Singleton
@Introspected
public class FlowValidator implements ConstraintValidator<FlowValidation, Flow> {
public static List<String> RESERVED_FLOW_IDS = List.of(
"pause",
"resume",
"force-run",
"change-status",
"kill",
"executions",
"search",
"source",
"disable",
"enable"
);
@Inject
private FlowService flowService;
@@ -50,6 +63,10 @@ public class FlowValidator implements ConstraintValidator<FlowValidation, Flow>
List<String> violations = new ArrayList<>();
if (RESERVED_FLOW_IDS.contains(value.getId())) {
violations.add("Flow id is a reserved keyword: " + value.getId() + ". List of reserved keywords: " + String.join(", ", RESERVED_FLOW_IDS));
}
if (flowService.requireExistingNamespace(value.getTenantId(), value.getNamespace())) {
violations.add("Namespace '" + value.getNamespace() + "' does not exist but is required to exist before a flow can be created in it.");
}

View File

@@ -412,4 +412,23 @@ class FlowServiceTest {
"The task 'for' cannot use the 'workerGroup' property as it's only relevant for runnable tasks."
);
}
@Test
void shouldReturnValidationErrorForReservedFlowId() {
// Given
String source = """
id: pause
namespace: io.kestra.unittest
tasks:
- id: task
type: io.kestra.plugin.core.log.Log
message: Reserved id test
""";
// When
List<ValidateConstraintViolation> results = flowService.validate("my-tenant", source);
// Then
assertThat(results).hasSize(1);
assertThat(results.getFirst().getConstraints()).contains("Flow id is a reserved keyword: pause");
}
}