From 19ebffbafa02fed456c67b9b81b21194748b0414 Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Mon, 3 Jun 2024 11:58:33 -0500 Subject: [PATCH] allow raw s3 bucket uris --- .../java/com/github/heuermh/cooper/Cooper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/heuermh/cooper/Cooper.java b/src/main/java/com/github/heuermh/cooper/Cooper.java index 797f836..e74b6ed 100644 --- a/src/main/java/com/github/heuermh/cooper/Cooper.java +++ b/src/main/java/com/github/heuermh/cooper/Cooper.java @@ -94,7 +94,7 @@ public final class Cooper implements Callable { static final HumanReadableFormatter FORMATTER = new HumanReadableFormatter(); /** s3 bucket and prefix regex pattern. */ - static final Pattern S3_URI = Pattern.compile("^s3:\\/\\/([a-zA-Z-]+)\\/(.+)$"); + static final Pattern S3_URI = Pattern.compile("^s3:\\/\\/([a-zA-Z-]+)\\/*(.*)$"); @Override @@ -116,10 +116,14 @@ public Integer call() throws Exception { logger.info("valid uri={} bucket={} prefix={}", uri, bucket, prefix); - ListObjectsV2Request request = ListObjectsV2Request.builder() - .bucket(bucket) - .prefix(prefix) - .build(); + ListObjectsV2Request.Builder requestBuilder = ListObjectsV2Request.builder() + .bucket(bucket); + + if (prefix != null && prefix.trim().length() > 0) { + requestBuilder = requestBuilder.prefix(prefix); + } + + ListObjectsV2Request request = requestBuilder.build(); logger.info("ListObjectsV2 request={}", request.toString());