package com.jay.monitor.data.server.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.jay.monitor.data.server.componts.OOSInvoke;
import com.jay.monitor.data.server.config.props.OSSProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/12/15 15:38
 */
@Configuration
@EnableConfigurationProperties(value = {OSSProperties.class})
public class OSSConfig {

    @Bean
    @ConditionalOnProperty(value = {"spring.oss.endpoint","spring.oss.access-key-id","spring.oss.access-key-secret"})
    public OOSInvoke oosInvoke(OSSProperties ossProperties) {
        OSS ossClient = new OSSClientBuilder().build(ossProperties.getEndpoint(), ossProperties.getAccessKeyId(), ossProperties.getAccessKeySecret());
        OOSInvoke oosInvoke = new OOSInvoke(ossClient, ossProperties);
        return oosInvoke;
    }

}
