|
@@ -1,6 +1,7 @@
|
|
|
package vip.xiaonuo.disk.config.minio;
|
|
package vip.xiaonuo.disk.config.minio;
|
|
|
|
|
|
|
|
import io.minio.MinioClient;
|
|
import io.minio.MinioClient;
|
|
|
|
|
+import io.minio.SetBucketPolicyArgs;
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
@@ -97,7 +98,36 @@ public class MinioConfig {
|
|
|
@Bean
|
|
@Bean
|
|
|
public MinioClient getMinioClient()
|
|
public MinioClient getMinioClient()
|
|
|
{
|
|
{
|
|
|
- return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
|
|
|
|
|
|
|
+ MinioClient minioClient=MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
|
|
|
|
|
+ // 设置存储桶策略为公开读取
|
|
|
|
|
+ String policy = "{\n" +
|
|
|
|
|
+ " \"Version\": \"2012-10-17\",\n" +
|
|
|
|
|
+ " \"Statement\": [\n" +
|
|
|
|
|
+ " {\n" +
|
|
|
|
|
+ " \"Effect\": \"Allow\",\n" +
|
|
|
|
|
+ " \"Principal\": {\"AWS\": \"*\"},\n" +
|
|
|
|
|
+ " \"Action\": [\"s3:GetBucketLocation\", \"s3:ListBucket\"],\n" +
|
|
|
|
|
+ " \"Resource\": \"arn:aws:s3:::" + bucketName + "\"\n" +
|
|
|
|
|
+ " },\n" +
|
|
|
|
|
+ " {\n" +
|
|
|
|
|
+ " \"Effect\": \"Allow\",\n" +
|
|
|
|
|
+ " \"Principal\": {\"AWS\": \"*\"},\n" +
|
|
|
|
|
+ " \"Action\": \"s3:GetObject\",\n" +
|
|
|
|
|
+ " \"Resource\": \"arn:aws:s3:::" + bucketName + "/*\"\n" +
|
|
|
|
|
+ " }\n" +
|
|
|
|
|
+ " ]\n" +
|
|
|
|
|
+ "}";
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ minioClient.setBucketPolicy(
|
|
|
|
|
+ SetBucketPolicyArgs.builder()
|
|
|
|
|
+ .bucket(bucketName)
|
|
|
|
|
+ .config(policy)
|
|
|
|
|
+ .build());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return minioClient;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|