package com.muyu.cloud.vehicle.gateway.aliyun;

import com.aliyun.ecs20140526.Client;
import com.aliyun.teaopenapi.models.Config;
import com.muyu.cloud.vehicle.gateway.config.AliProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ：Ali客户端
 */
@Configuration
public class AliYunConfig {

    @Autowired
    private AliProperties aliProperties;

    @Bean
    public Client createClient() {
        // 工程代码泄露可能会导致 AccessKey 泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        Config config = new Config()
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId(aliProperties.getAccessKeyId())
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret(aliProperties.getAccessKeySecret());
        // Endpoint 请参考 https://api.aliyun.com/product/Ecs
        config.endpoint = aliProperties.getEndpoint();
        try {
            return new Client(config);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
