All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.oss.PlatformQiniuAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.oss;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.oss.condition.ConditionalOnOssEnabled;
import org.zodiac.autoconfigure.security.condition.ConditionalOnSecurityHttpEnabled;

/**
 * Qiniu配置类。
 *
 */
@SpringBootConfiguration
@ConditionalOnOssEnabled
//@ConditionalOnWebApplication
@ConditionalOnSecurityHttpEnabled
@AutoConfigureAfter(value = {PlatformOssAutoConfiguration.class})
@ConditionalOnProperty(value = org.zodiac.oss.constants.OssSystemPropertiesConstants.PLATFORM_OSS_NAME, havingValue = org.zodiac.oss.constants.OssConstants.QINIU)
@ConditionalOnClass(value = {com.qiniu.util.Auth.class, com.qiniu.storage.UploadManager.class, com.qiniu.storage.BucketManager.class, org.zodiac.oss.config.PlatformOssInfo.class})
public class PlatformQiniuAutoConfiguration {

    private final PlatformOssProperties ossProperties;
    private final org.zodiac.oss.rule.OssRule ossRule;

    public PlatformQiniuAutoConfiguration(PlatformOssProperties ossProperties, org.zodiac.oss.rule.OssRule ossRule) {
        this.ossProperties = ossProperties;
        this.ossRule = ossRule;
    }

    @Bean
    @ConditionalOnMissingBean
    protected com.qiniu.storage.Configuration qnConfiguration() {
        return new com.qiniu.storage.Configuration(com.qiniu.storage.Region.autoRegion());
    }

    @Bean
    @ConditionalOnMissingBean
    protected com.qiniu.util.Auth auth() {
        return com.qiniu.util.Auth.create(ossProperties.getAccessKey(), ossProperties.getSecretKey());
    }

    @Bean
    @ConditionalOnBean(value = {com.qiniu.storage.Configuration.class})
    protected com.qiniu.storage.UploadManager uploadManager(com.qiniu.storage.Configuration cfg) {
        return new com.qiniu.storage.UploadManager(cfg);
    }

    @Bean
    @ConditionalOnBean(value = {com.qiniu.storage.Configuration.class})
    protected com.qiniu.storage.BucketManager bucketManager(com.qiniu.storage.Configuration cfg) {
        return new com.qiniu.storage.BucketManager(com.qiniu.util.Auth.create(ossProperties.getAccessKey(), ossProperties.getSecretKey()), cfg);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnBean(value = {com.qiniu.util.Auth.class, com.qiniu.storage.UploadManager.class, com.qiniu.storage.BucketManager.class})
    protected org.zodiac.oss.QiniuTemplate qiniuTemplate(com.qiniu.util.Auth auth, com.qiniu.storage.UploadManager uploadManager, com.qiniu.storage.BucketManager bucketManager) {
        return new org.zodiac.oss.QiniuTemplate(auth, uploadManager, bucketManager, ossProperties, ossRule);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy