This is an automated email from the ASF dual-hosted git repository.
zhongjiajie pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 6f90156577 oss avoid listBuckets permission in bucket check (#14414)
6f90156577 is described below
commit 6f901565776a643402c54c612088fc5260af37c5
Author: zhangkuantian <[email protected]>
AuthorDate: Wed Jun 28 14:21:17 2023 +0800
oss avoid listBuckets permission in bucket check (#14414)
---------
Co-authored-by: kuantian.zhang <[email protected]>
---
.../common/log/remote/OssRemoteLogHandler.java | 19 +++++++------------
.../plugin/storage/oss/OssStorageOperator.java | 19 +++++++------------
2 files changed, 14 insertions(+), 24 deletions(-)
diff --git
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.java
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.java
index b7cd131e04..792085b194 100644
---
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.java
+++
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/OssRemoteLogHandler.java
@@ -31,7 +31,6 @@ import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import com.aliyun.oss.OSS;
-import com.aliyun.oss.model.Bucket;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.PutObjectRequest;
@@ -104,17 +103,13 @@ public class OssRemoteLogHandler implements
RemoteLogHandler, Closeable {
throw new
IllegalArgumentException(Constants.REMOTE_LOGGING_OSS_BUCKET_NAME + " is
empty");
}
- Bucket existsBucket = ossClient.listBuckets()
- .stream()
- .filter(
- bucket -> bucket.getName().equals(bucketName))
- .findFirst()
- .orElseThrow(() -> {
- return new IllegalArgumentException(
- "bucketName: " + bucketName + " does not exist,
you need to create them by yourself");
- });
-
- log.info("bucketName: {} has been found", existsBucket.getName());
+ boolean existsBucket = ossClient.doesBucketExist(bucketName);
+ if (!existsBucket) {
+ throw new IllegalArgumentException(
+ "bucketName: " + bucketName + " is not exists, you need to
create them by yourself");
+ }
+
+ log.info("bucketName: {} has been found", bucketName);
}
private String readOssAccessKeyId() {
diff --git
a/dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java
b/dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java
index 01b41592a7..80e8175cdd 100644
---
a/dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java
+++
b/dolphinscheduler-storage-plugin/dolphinscheduler-storage-oss/src/main/java/org/apache/dolphinscheduler/plugin/storage/oss/OssStorageOperator.java
@@ -59,7 +59,6 @@ import lombok.extern.slf4j.Slf4j;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.ServiceException;
-import com.aliyun.oss.model.Bucket;
import com.aliyun.oss.model.DeleteObjectsRequest;
import com.aliyun.oss.model.ListObjectsV2Request;
import com.aliyun.oss.model.ListObjectsV2Result;
@@ -509,17 +508,13 @@ public class OssStorageOperator implements Closeable,
StorageOperate {
throw new
IllegalArgumentException("resource.alibaba.cloud.oss.bucket.name is empty");
}
- Bucket existsBucket = ossClient.listBuckets()
- .stream()
- .filter(
- bucket -> bucket.getName().equals(bucketName))
- .findFirst()
- .orElseThrow(() -> {
- return new IllegalArgumentException(
- "bucketName: " + bucketName + " does not exist,
you need to create them by yourself");
- });
-
- log.info("bucketName: {} has been found, the current regionName is
{}", existsBucket.getName(), region);
+ boolean existsBucket = ossClient.doesBucketExist(bucketName);
+ if (!existsBucket) {
+ throw new IllegalArgumentException(
+ "bucketName: " + bucketName + " is not exists, you need to
create them by yourself");
+ }
+
+ log.info("bucketName: {} has been found, the current regionName is
{}", bucketName, region);
}
protected void deleteDir(String directoryName) {