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