houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.infra.framework.file.core.client.s3;
H 2
3 import cn.hutool.core.util.StrUtil;
4 import com.iailab.module.infra.framework.file.core.client.FileClientConfig;
5 import com.fasterxml.jackson.annotation.JsonIgnore;
6 import lombok.Data;
7 import org.hibernate.validator.constraints.URL;
8
9 import javax.validation.constraints.AssertTrue;
10 import javax.validation.constraints.NotNull;
11
12 /**
13  * S3 文件客户端的配置类
14  *
15  * @author iailab
16  */
17 @Data
18 public class S3FileClientConfig implements FileClientConfig {
19
20     public static final String ENDPOINT_QINIU = "qiniucs.com";
21     public static final String ENDPOINT_ALIYUN = "aliyuncs.com";
22     public static final String ENDPOINT_TENCENT = "myqcloud.com";
23
24     /**
25      * 节点地址
26      * 1. MinIO:https://www.baidu.com/Spring-Boot/MinIO 。例如说,http://127.0.0.1:9000
27      * 2. 阿里云:https://help.aliyun.com/document_detail/31837.html
28      * 3. 腾讯云:https://cloud.tencent.com/document/product/436/6224
29      * 4. 七牛云:https://developer.qiniu.com/kodo/4088/s3-access-domainname
30      * 5. 华为云:https://developer.huaweicloud.com/endpoint?OBS
31      */
32     @NotNull(message = "endpoint 不能为空")
33     private String endpoint;
34     /**
35      * 自定义域名
36      * 1. MinIO:通过 Nginx 配置
37      * 2. 阿里云:https://help.aliyun.com/document_detail/31836.html
38      * 3. 腾讯云:https://cloud.tencent.com/document/product/436/11142
39      * 4. 七牛云:https://developer.qiniu.com/kodo/8556/set-the-custom-source-domain-name
40      * 5. 华为云:https://support.huaweicloud.com/usermanual-obs/obs_03_0032.html
41      */
42     @URL(message = "domain 必须是 URL 格式")
43     private String domain;
44     /**
45      * 存储 Bucket
46      */
47     @NotNull(message = "bucket 不能为空")
48     private String bucket;
49
50     /**
51      * 访问 Key
52      * 1. MinIO:https://www.baidu.com/Spring-Boot/MinIO
53      * 2. 阿里云:https://ram.console.aliyun.com/manage/ak
54      * 3. 腾讯云:https://console.cloud.tencent.com/cam/capi
55      * 4. 七牛云:https://portal.qiniu.com/user/key
56      * 5. 华为云:https://support.huaweicloud.com/qs-obs/obs_qs_0005.html
57      */
58     @NotNull(message = "accessKey 不能为空")
59     private String accessKey;
60     /**
61      * 访问 Secret
62      */
63     @NotNull(message = "accessSecret 不能为空")
64     private String accessSecret;
65
66     @SuppressWarnings("RedundantIfStatement")
67     @AssertTrue(message = "domain 不能为空")
68     @JsonIgnore
69     public boolean isDomainValid() {
70         // 如果是七牛,必须带有 domain
71         if (StrUtil.contains(endpoint, ENDPOINT_QINIU) && StrUtil.isEmpty(domain)) {
72             return false;
73         }
74         return true;
75     }
76
77 }