|
3 | 3 | import io.kestra.core.models.annotations.Example; |
4 | 4 | import io.kestra.core.models.annotations.Metric; |
5 | 5 | import io.kestra.core.models.annotations.Plugin; |
6 | | -import io.kestra.core.models.annotations.PluginProperty; |
7 | 6 | import io.kestra.core.models.executions.metrics.Counter; |
| 7 | +import io.kestra.core.models.property.Data; |
8 | 8 | import io.kestra.core.models.property.Property; |
9 | 9 | import io.kestra.core.models.tasks.RunnableTask; |
10 | 10 | import io.kestra.core.runners.RunContext; |
|
27 | 27 | import java.nio.file.Path; |
28 | 28 | import java.nio.file.StandardCopyOption; |
29 | 29 | import java.time.Instant; |
30 | | -import java.util.Collection; |
31 | 30 | import java.util.HashMap; |
32 | 31 | import java.util.Map; |
| 32 | +import java.util.Objects; |
33 | 33 | import java.util.regex.Pattern; |
34 | 34 |
|
35 | 35 | import static io.kestra.core.utils.Rethrow.throwFunction; |
|
187 | 187 | title = "Upload a file(s) to a S3 bucket.", |
188 | 188 | description = "Uploads a single or multiple files to an Amazon S3 bucket." |
189 | 189 | ) |
190 | | -public class Upload extends AbstractS3Object implements RunnableTask<Upload.Output> { |
| 190 | +public class Upload extends AbstractS3Object implements RunnableTask<Upload.Output>, Data.From { |
191 | 191 | @Schema( |
192 | | - title = "The file(s) to upload", |
193 | | - description = "Can be a single file, a list of files or json array", |
| 192 | + title = Data.From.TITLE, |
| 193 | + description = Data.From.DESCRIPTION, |
194 | 194 | anyOf = {List.class, String.class} |
195 | 195 | ) |
196 | | - @PluginProperty(dynamic = true, internalStorageURI = true) |
197 | 196 | @NotNull |
198 | 197 | private Object from; |
199 | 198 |
|
@@ -333,15 +332,16 @@ public Output run(RunContext runContext) throws Exception { |
333 | 332 | } |
334 | 333 |
|
335 | 334 | private String[] parseFromProperty(RunContext runContext) throws Exception { |
336 | | - if (this.from instanceof Collection<?> fromURIs) { |
337 | | - return fromURIs.stream() |
338 | | - .map(throwFunction(from -> runContext.render((String) from))) |
339 | | - .toArray(String[]::new); |
340 | | - } else if (this.from instanceof String && Pattern.compile("^\\[.*]$", Pattern.DOTALL).matcher(((String) this.from).trim()).matches()) { |
| 335 | + |
| 336 | + if (this.from instanceof String && Pattern.compile("^\\[.*]$", Pattern.DOTALL).matcher(((String) this.from).trim()).matches()) |
341 | 337 | return JacksonMapper.ofJson().readValue(runContext.render((String) this.from), String[].class); |
342 | | - } else { |
343 | | - return new String[]{runContext.render((String) this.from)}; |
344 | | - } |
| 338 | + |
| 339 | + return Objects.requireNonNull(Data.from(this.from) |
| 340 | + .readAs(runContext, String.class, Object::toString) |
| 341 | + .map(throwFunction(runContext::render)) |
| 342 | + .collectList() |
| 343 | + .block()) |
| 344 | + .toArray(String[]::new); |
345 | 345 | } |
346 | 346 |
|
347 | 347 | private Output uploadSingleFile(RunContext runContext, S3TransferManager transferManager, |
|
0 commit comments