package com.brframework.commonoss.config;

import com.brframework.commonoss.core.AliYunOSSClient;
import com.brframework.commonoss.core.AliYunOSSClientBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 对象存储配置
 * @author xu
 * @date 2019/8/21 10:22
 */
@Configuration
@ConfigurationProperties("oss.aliyun")
@Data
public class AliYunOSSConfig {

    // Endpoint以杭州为例，其它Region请按实际情况填写。
    private String endpoint;
    // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建RAM账号。
    private String accessKeyId;
    private String accessKeySecret;
    private String defaultBucketName;
    private String defaultCDNDomain;

    @Bean
    public AliYunOSSClient ossClient(){

        // 创建OSSClient实例。
        return (AliYunOSSClient) new AliYunOSSClientBuilder()
                .setDefaultBucketName(defaultBucketName)
                .setDefaultCDNDomain(defaultCDNDomain)
                .build(endpoint, accessKeyId, accessKeySecret);
    }

}
