Compare commits

..

No commits in common. "94d5a3b486812c979e3482cfc20b4b49d0c5f9bb" and "ad3c2bcaba4ad6bedf55e5d8eed70d728fcdf214" have entirely different histories.

4 changed files with 5 additions and 73 deletions

View File

@ -1,5 +0,0 @@
git checkout master
git merge dev
git push --all
git push --tags
git checkout dev

View File

@ -1,9 +1,6 @@
package cn.bunny.services.utils.minio; package cn.bunny.services.utils.minio;
import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient; import io.minio.MinioClient;
import io.minio.SetBucketPolicyArgs;
import lombok.Data; import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -27,30 +24,6 @@ public class MinioProperties {
@Bean @Bean
public MinioClient minioClient() { public MinioClient minioClient() {
MinioClient minioClient = MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build(); return MinioClient.builder().endpoint(endpointUrl).credentials(accessKey, secretKey).build();
try {
boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
if (!found) {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
String publicPolicy = String.format("{\n" +
" \"Version\": \"2012-10-17\",\n" +
" \"Statement\": [\n" +
" {\n" +
" \"Effect\": \"Allow\",\n" +
" \"Principal\": \"*\",\n" +
" \"Action\": [\"s3:GetObject\"],\n" +
" \"Resource\": [\"arn:aws:s3:::%s/*\"]\n" +
" }\n" +
" ]\n" +
"}", bucketName);
minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucketName).config(publicPolicy).build());
}
} catch (Exception exception) {
exception.getStackTrace();
}
return minioClient;
} }
} }

View File

@ -175,40 +175,4 @@ public class MinioUtil {
throw new AuthCustomerException(e.getMessage()); throw new AuthCustomerException(e.getMessage());
} }
} }
/**
* 判断桶是否存在
*
* @param bucketName 桶名称
* @return 布尔值是否存在
*/
public boolean createBucketIfNotExists(String bucketName) {
boolean found = false;
try {
found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
// 如果 bucket 不存在就创建
if (!found) makeBucket(bucketName);
return found;
} catch (Exception exception) {
log.error("判断桶是否存在 ------ 失败消息:{}", exception.getLocalizedMessage());
exception.getStackTrace();
}
throw new AuthCustomerException("未初始化 bucket");
}
/**
* 创建桶
*
* @param bucketName 桶的名称
*/
public void makeBucket(String bucketName) {
try {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
} catch (Exception exception) {
exception.getStackTrace();
throw new AuthCustomerException("创建失败");
}
}
} }

View File

@ -19,20 +19,20 @@ logging:
bunny: bunny:
master: master:
host: localhost host: 192.168.3.137
port: 3306 port: 3306
database: auth_admin database: auth_admin
username: root username: root
password: "123456" password: "123456"
redis: redis:
host: localhost host: 192.168.3.137
port: 6379 port: 6379
database: 0 database: 0
password: "123456" password: "123456"
minio: minio:
endpointUrl: "http://localhost:9000" # 连接地址 endpointUrl: "http://192.168.3.137:9000" # 连接地址
accessKey: bunny # 用户名 accessKey: bunny # 用户名
secretKey: "12345678" # 登录密码 secretKey: "12345678" # 登录密码
bucket-name: auth-admin # 指定哪个桶 bucket-name: auth-admin # 指定哪个桶