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

com.fastchar.oss.ali.FastAliOSSConfig Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
package com.fastchar.oss.ali;

import com.fastchar.annotation.AFastClassFind;
import com.fastchar.core.FastChar;
import com.fastchar.interfaces.IFastConfig;
import com.fastchar.oss.exception.FastAliBlockException;

import java.util.ArrayList;
import java.util.List;

/**
 * 阿里OSS 配置
 */
@AFastClassFind(value = "com.aliyun.oss.OSSClient", url = "https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss")
public class FastAliOSSConfig implements IFastConfig {
    private String accessKeyId;
    private String accessKeySecret;
    private String endPoint;
    private List blocks = new ArrayList<>();
    private int minute = 60;
    private boolean debug;

    public FastAliOSSConfig() {
        FastChar.getOverrides().add(FastAliOSSFile.class);
        if (FastChar.getConstant().isDebug()) {
            FastChar.getLog().info(this.getClass(), "已启用阿里云OSS(对象存储)服务器!");
        }
        FastChar.getValues().put("oss", "ali");
    }

    public String getAccessKeyId() {
        return accessKeyId;
    }

    public FastAliOSSConfig setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
        return this;
    }

    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    public FastAliOSSConfig setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
        return this;
    }

    public String getEndPoint() {
        return endPoint;
    }

    public FastAliOSSConfig setEndPoint(String endPoint) {
        this.endPoint = endPoint;
        return this;
    }

    /**
     * 添加block
     *
     * @param blockName     名称
     * @param blockHttp     外网访问地址
     * @param blockSecurity 权限配置
     * @return 当前对象
     */
    public FastAliOSSConfig addBlock(String blockName, String blockHttp, FastAliOSSBlock.AliSecurityEnum blockSecurity) {
        this.blocks.add(new FastAliOSSBlock()
                .setBlockName(blockName)
                .setBlockHttp(blockHttp)
                .setBlockSecurity(blockSecurity));
        return this;
    }

    /**
     * 设置默认的block
     *
     * @param blockName     名称
     * @param blockHttp     外网访问地址
     * @param blockSecurity 权限配置
     * @return 当前对象
     */
    public FastAliOSSConfig setBlock(String blockName, String blockHttp, FastAliOSSBlock.AliSecurityEnum blockSecurity) {
        List waitRemove = new ArrayList<>();
        for (FastAliOSSBlock block : this.blocks) {
            if (block.isBlockDefault()) {
                waitRemove.add(block);
            }
        }
        this.blocks.removeAll(waitRemove);
        this.blocks.add(new FastAliOSSBlock()
                .setBlockName(blockName)
                .setBlockHttp(blockHttp)
                .setBlockDefault(true)
                .setBlockSecurity(blockSecurity));
        return this;
    }

    public FastAliOSSBlock getDefaultBlock() {
        for (FastAliOSSBlock block : blocks) {
            if (block.isBlockDefault()) {
                return block;
            }
        }
        throw new FastAliBlockException("not set default block !");
    }

    public FastAliOSSBlock getBlock(String blockName) {
        for (FastAliOSSBlock block : blocks) {
            if (block.getBlockName().equals(blockName)) {
                return block;
            }
        }
        throw new FastAliBlockException("not found block '" + blockName + "'!");
    }

    public int getMinute() {
        return minute;
    }

    public FastAliOSSConfig setMinute(int minute) {
        this.minute = minute;
        return this;
    }

    public boolean isDebug() {
        return debug;
    }

    public FastAliOSSConfig setDebug(boolean debug) {
        this.debug = debug;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy