-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): validate that an input of type FILE didn't have any defaults
- Loading branch information
1 parent
dd3e64a
commit b9620a5
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
core/src/main/java/io/kestra/core/validations/FileInputValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.kestra.core.validations; | ||
|
||
import io.kestra.core.validations.validator.FileInputValidator; | ||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = FileInputValidator.class) | ||
public @interface FileInputValidation { | ||
String message() default "invalid file input"; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/io/kestra/core/validations/validator/FileInputValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.kestra.core.validations.validator; | ||
|
||
import io.kestra.core.models.flows.input.FileInput; | ||
import io.kestra.core.validations.FileInputValidation; | ||
import io.micronaut.core.annotation.AnnotationValue; | ||
import io.micronaut.core.annotation.Introspected; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.validation.validator.constraints.ConstraintValidator; | ||
import io.micronaut.validation.validator.constraints.ConstraintValidatorContext; | ||
import jakarta.inject.Singleton; | ||
|
||
@Singleton | ||
@Introspected | ||
public class FileInputValidator implements ConstraintValidator<FileInputValidation, FileInput> { | ||
@Override | ||
public boolean isValid(@Nullable FileInput value, @NonNull AnnotationValue<FileInputValidation> annotationMetadata, @NonNull ConstraintValidatorContext context) { | ||
if (value == null) { | ||
return true; // nulls are allowed according to spec | ||
} | ||
|
||
if (value.getDefaults() != null) { | ||
context.disableDefaultConstraintViolation(); | ||
context.buildConstraintViolationWithTemplate("no `defaults` can be set for inputs of type 'FILE'") | ||
.addConstraintViolation(); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
core/src/test/resources/flows/invalids/inputs-validation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
id: inputs-validations | ||
namespace: io.kestra.tests | ||
|
||
inputs: | ||
- id: file | ||
type: FILE | ||
defaults: something | ||
- id: array | ||
type: ARRAY | ||
itemType: ARRAY | ||
|
||
tasks: | ||
- id: hello | ||
type: io.kestra.plugin.core.log.Log | ||
message: Hello World! 🚀 |