| package com.qxueyou.scc.config; | 
|   | 
| import com.obs.services.ObsClient; | 
| import com.obs.services.exception.ObsException; | 
| import com.qxueyou.scc.teach.res.service.impl.HweiYunOBSServiceImpl; | 
| import lombok.Data; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.logging.log4j.LogManager; | 
| import org.apache.logging.log4j.Logger; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.context.annotation.Configuration; | 
|   | 
| import java.text.SimpleDateFormat; | 
| import java.util.Date; | 
|   | 
| /** | 
|  * @ClassName: HweiOBSConfig | 
|  * @Description: 华为云OBS配置类 | 
|  * @Author: wuhuiju | 
|  * @Date: 2021-12-21 15:56 | 
|  * @Version: 1.0 | 
|  */ | 
| //@Data | 
| //@Slf4j | 
| @Configuration | 
| public class HweiOBSConfig { | 
|   | 
|     private final Logger log = LogManager.getLogger(HweiOBSConfig.class); | 
|     public HweiOBSConfig() { | 
|     } | 
|   | 
|     public HweiOBSConfig(String accessKey, String securityKey, String endPoint, String bucketName) { | 
|         this.accessKey = accessKey; | 
|         this.securityKey = securityKey; | 
|         this.endPoint = endPoint; | 
|         this.bucketName = bucketName; | 
|     } | 
|   | 
|     public String getAccessKey() { | 
|         return accessKey; | 
|     } | 
|   | 
|     public void setAccessKey(String accessKey) { | 
|         this.accessKey = accessKey; | 
|     } | 
|   | 
|     public String getSecurityKey() { | 
|         return securityKey; | 
|     } | 
|   | 
|     public void setSecurityKey(String securityKey) { | 
|         this.securityKey = securityKey; | 
|     } | 
|   | 
|     public String getEndPoint() { | 
|         return endPoint; | 
|     } | 
|   | 
|     public void setEndPoint(String endPoint) { | 
|         this.endPoint = endPoint; | 
|     } | 
|   | 
|     public String getBucketName() { | 
|         return bucketName; | 
|     } | 
|   | 
|     public void setBucketName(String bucketName) { | 
|         this.bucketName = bucketName; | 
|     } | 
|   | 
|     /** | 
|      * 访问密钥AK | 
|      */ | 
|     @Value("${hwyun.obs.accessKey}") | 
|     private String accessKey; | 
|   | 
|     /** | 
|      * 访问密钥SK | 
|      */ | 
|     @Value("${hwyun.obs.securityKey}") | 
|     private String securityKey; | 
|   | 
|     /** | 
|      * 终端节点 | 
|      */ | 
|     @Value("${hwyun.obs.endPoint}") | 
|     private String endPoint; | 
|   | 
|     /** | 
|      * 桶 | 
|      */ | 
|     @Value("${hwyun.obs.bucketName}") | 
|     private String bucketName; | 
|   | 
|     /** | 
|      * @Description 获取OBS客户端实例 | 
|      * @author wuhuiju | 
|      * @date 2022/12/2 15:57 | 
|      * @return | 
|      * @return: com.obs.services.ObsClient | 
|      */ | 
|     public ObsClient getInstance() { | 
|         return new ObsClient(accessKey, securityKey, endPoint); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * @Description 销毁OBS客户端实例 | 
|      * @author wuhuiju | 
|      * @date 2022/12/2 17:32 | 
|      * @param: obsClient | 
|      * @return | 
|      */ | 
|     public void destroy(ObsClient obsClient){ | 
|         try { | 
|             obsClient.close(); | 
|         } catch (ObsException e) { | 
|             log.error("obs执行失败", e); | 
|         } catch (Exception e) { | 
|             log.error("执行失败", e); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * @Description 微服务文件存放路径 | 
|      * @author wuhuiju | 
|      * @date 2022/12/2 15:57 | 
|      * @return | 
|      * @return: java.lang.String | 
|      */ | 
|     public static String getObjectKey() { | 
|         // 项目或者服务名称 + 日期存储方式 | 
|         return "Hwei" + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date() )+ "/"; | 
|     } | 
| } |