package com.zhongshu.card.server.core.model.upLoadFile.oss;

import com.zhongshu.card.server.core.model.upLoadFile.ObjectStorageType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "oss")
public class ALiObjectStorage extends SuperObjectStorage {

    //Endpoint以成都为例，其它Region请按实际情况填写。
    private String endpoint = "oss-cn-chengdu.aliyuncs.com";

    //对象存储
    private String bucket = "zlnd-dev";


    // https://help.aliyun.com/document_detail/100624.htm 使用STS临时访问凭证访问OSS
    // sts 临时访问凭证
    // 1. https://ram.console.aliyun.com 创建RAM用户 , 勾选 "OpenApi 访问调用" , 获取 	AccessKeyId  & AccessKeySecret 注意 : 必须使用用户的 ak 和 sk
    // 2. 用户添加权限 AliyunSTSAssumeRoleAccess  AliyunOSSFullAccess
    // 3. 创建角色 , 单击复制，保存角色的ARN  acs:ram::xxxxxx:role/netdisk
    // 4. 设置角色权限 AliyunSTSAssumeRoleAccess  AliyunOSSFullAccess

    // 账户id
    private String accessKeyId;

    //密钥
    private String accessKeySecret;

    //角色id acs:ram::xxxxxx:role/netdisk
    private String arn;

    @Override
    public ObjectStorageType storageType() {
        return ObjectStorageType.ALi;
    }

    public String getShowEndpoint() {
        if (StringUtils.isNotEmpty(endpoint)) {
            return endpoint.replace(".aliyuncs.com", "");
        }
        return "";
    }
}
