oss avoid listBuckets permission in bucket check (#14414)

---------

Co-authored-by: kuantian.zhang <kuantian.zhang@inceptio.ai>
This commit is contained in:
zhangkuantian 2023-06-28 14:21:17 +08:00 committed by GitHub
parent bcd1df19b8
commit 6f90156577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 22 deletions

View File

@ -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");
});
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", existsBucket.getName());
log.info("bucketName: {} has been found", bucketName);
}
private String readOssAccessKeyId() {

View File

@ -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");
});
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 {}", existsBucket.getName(), region);
log.info("bucketName: {} has been found, the current regionName is {}", bucketName, region);
}
protected void deleteDir(String directoryName) {