Skip to content

Commit 6c2c09e

Browse files
feat(aws-s3): migrate Upload task to use Data.From facility (#653)
1 parent faa5be0 commit 6c2c09e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/main/java/io/kestra/plugin/aws/s3/Upload.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import io.kestra.core.models.annotations.Example;
44
import io.kestra.core.models.annotations.Metric;
55
import io.kestra.core.models.annotations.Plugin;
6-
import io.kestra.core.models.annotations.PluginProperty;
76
import io.kestra.core.models.executions.metrics.Counter;
7+
import io.kestra.core.models.property.Data;
88
import io.kestra.core.models.property.Property;
99
import io.kestra.core.models.tasks.RunnableTask;
1010
import io.kestra.core.runners.RunContext;
@@ -27,9 +27,9 @@
2727
import java.nio.file.Path;
2828
import java.nio.file.StandardCopyOption;
2929
import java.time.Instant;
30-
import java.util.Collection;
3130
import java.util.HashMap;
3231
import java.util.Map;
32+
import java.util.Objects;
3333
import java.util.regex.Pattern;
3434

3535
import static io.kestra.core.utils.Rethrow.throwFunction;
@@ -187,13 +187,12 @@
187187
title = "Upload a file(s) to a S3 bucket.",
188188
description = "Uploads a single or multiple files to an Amazon S3 bucket."
189189
)
190-
public class Upload extends AbstractS3Object implements RunnableTask<Upload.Output> {
190+
public class Upload extends AbstractS3Object implements RunnableTask<Upload.Output>, Data.From {
191191
@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,
194194
anyOf = {List.class, String.class}
195195
)
196-
@PluginProperty(dynamic = true, internalStorageURI = true)
197196
@NotNull
198197
private Object from;
199198

@@ -333,15 +332,16 @@ public Output run(RunContext runContext) throws Exception {
333332
}
334333

335334
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())
341337
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);
345345
}
346346

347347
private Output uploadSingleFile(RunContext runContext, S3TransferManager transferManager,

0 commit comments

Comments
 (0)