package org.springblade.modules.resource.builder.oss;

import com.obs.services.ObsClient;
import lombok.SneakyThrows;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.modules.resource.entity.Oss;
import org.springblade.modules.resource.template.ObsTemplate;

/**
 * @author: lianghanqiang
 * @description:
 * @since: 7/27/21 -- 3:01 PM
 */
public class ObsBuilder {
	@SneakyThrows
	public static OssTemplate template(Oss oss, OssRule ossRule) {
		// 创建配置类
		OssProperties ossProperties = new OssProperties();
		ossProperties.setEndpoint(oss.getEndpoint());
		ossProperties.setAccessKey(oss.getAccessKey());
		ossProperties.setSecretKey(oss.getSecretKey());
		ossProperties.setBucketName(oss.getBucketName());

		ObsClient obsClient = new ObsClient(ossProperties.getAccessKey(), ossProperties.getSecretKey(), ossProperties.getEndpoint());
		return new ObsTemplate(obsClient,ossProperties,ossRule);
	}
}
