Search in sources :

Example 1 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project paascloud-master by paascloud.

the class AliyunSmsConfiguration method acsClient.

/**
 * Acs client acs client.
 *
 * @return the acs client
 *
 * @throws ClientException the client exception
 */
@Bean
public IAcsClient acsClient() throws ClientException {
    log.info("SMS Bean IAcsClient Start");
    IClientProfile profile = DefaultProfile.getProfile(paascloudProperties.getAliyun().getSms().getRegionId(), paascloudProperties.getAliyun().getKey().getAccessKeyId(), paascloudProperties.getAliyun().getKey().getAccessKeySecret());
    DefaultProfile.addEndpoint(paascloudProperties.getAliyun().getSms().getEndpointName(), paascloudProperties.getAliyun().getSms().getRegionId(), paascloudProperties.getAliyun().getSms().getProduct(), paascloudProperties.getAliyun().getSms().getDomain());
    DefaultAcsClient defaultAcsClient = new DefaultAcsClient(profile);
    log.info("加载SMS Bean IAcsClient OK");
    return defaultAcsClient;
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) Bean(org.springframework.context.annotation.Bean)

Example 2 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project jointware by isdream.

the class AliyunECSAPIExample method main.

/**
 * @param args
 * @throws ClientException
 * @throws ServerException
 */
public static void main(String[] args) throws ServerException, ClientException {
    IClientProfile profile = DefaultProfile.getProfile(REGINE_ID, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
    IAcsClient client = new DefaultAcsClient(profile);
    DescribeZonesRequest request = new DescribeZonesRequest();
    DescribeZonesResponse response = client.getAcsResponse(request);
    System.out.println(response.getZones().get(0).getZoneId());
    DescribeInstancesRequest dur = new DescribeInstancesRequest();
    for (Instance ins : client.getAcsResponse(dur).getInstances()) {
        System.out.println(ins.getInstanceName() + "\t:" + ins.getRegionId());
    }
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) Instance(com.aliyuncs.ecs.model.v20140526.DescribeInstancesResponse.Instance) DescribeZonesRequest(com.aliyuncs.ecs.model.v20140526.DescribeZonesRequest) DescribeZonesResponse(com.aliyuncs.ecs.model.v20140526.DescribeZonesResponse) IAcsClient(com.aliyuncs.IAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) DescribeInstancesRequest(com.aliyuncs.ecs.model.v20140526.DescribeInstancesRequest)

Example 3 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project vertx-zero by silentbalanceyh.

the class SmsClientImpl method initClient.

private void initClient() {
    // Extract data from config
    final JsonObject params = this.config.getConfig();
    Fn.safeNull(() -> {
        // Set default timeout
        final String connect = params.containsKey(SmsConfig.TIMEOUT_CONN) ? params.getInteger(SmsConfig.TIMEOUT_CONN).toString() : "10000";
        final String read = params.containsKey(SmsConfig.TIMEOUT_READ) ? params.getInteger(SmsConfig.TIMEOUT_READ).toString() : "10000";
        System.setProperty("sun.net.client.defaultConnectTimeout", connect);
        System.setProperty("sun.net.client.defaultReadTimeout", read);
        // AscClient initialized.
        final IClientProfile profile = DefaultProfile.getProfile(SmsConfig.DFT_REGION, this.config.getAccessId(), this.config.getAccessSecret());
        try {
            DefaultProfile.addEndpoint(SmsConfig.DFT_REGION, SmsConfig.DFT_REGION, SmsConfig.DFT_PRODUCT, this.config.getDomain());
        } catch (final ClientException ex) {
            Fn.flingWeb(true, LOGGER, _424ProfileEndPointException.class, this.getClass(), ex);
        }
        this.client = new DefaultAcsClient(profile);
    }, params);
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) JsonObject(io.vertx.core.json.JsonObject) io.vertx.up.exception._424ProfileEndPointException(io.vertx.up.exception._424ProfileEndPointException) ClientException(com.aliyuncs.exceptions.ClientException) IClientProfile(com.aliyuncs.profile.IClientProfile)

Example 4 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project fc-java-sdk by aliyun.

the class FunctionComputeClientTest method getAssumeRoleCredentials.

private Credentials getAssumeRoleCredentials(String policy) throws com.aliyuncs.exceptions.ClientException {
    IClientProfile profile = DefaultProfile.getProfile(REGION, ACCESS_KEY, SECRET_KEY);
    // DefaultProfile.addEndpoint("sts.us-west-1.aliyuncs.com", "us-west-1", "Sts", "sts.us-west-1.aliyuncs.com");
    DefaultAcsClient client = new DefaultAcsClient(profile);
    AssumeRoleRequest request = new AssumeRoleRequest();
    request.setVersion(STS_API_VERSION);
    request.setMethod(MethodType.POST);
    request.setProtocol(ProtocolType.HTTPS);
    request.setRoleArn(STS_ROLE);
    request.setRoleSessionName("test-session");
    if (policy != null) {
        request.setPolicy(policy);
    }
    AssumeRoleResponse stsResponse;
    try {
        stsResponse = client.getAcsResponse(request);
    } catch (com.aliyuncs.exceptions.ClientException e) {
        throw new RuntimeException(e);
    }
    String accessKey = stsResponse.getCredentials().getAccessKeyId();
    String secretKey = stsResponse.getCredentials().getAccessKeySecret();
    String stsToken = stsResponse.getCredentials().getSecurityToken();
    assertNotNull(accessKey);
    assertNotNull(secretKey);
    assertNotNull(stsToken);
    return stsResponse.getCredentials();
}
Also used : AssumeRoleRequest(com.aliyuncs.sts.model.v20150401.AssumeRoleRequest) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) AssumeRoleResponse(com.aliyuncs.sts.model.v20150401.AssumeRoleResponse) IClientProfile(com.aliyuncs.profile.IClientProfile)

Example 5 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project ranch by heisedebaise.

the class AliyunSmsSenderImpl method onContextRefreshed.

@Override
public void onContextRefreshed() {
    if (validator.isEmpty(key) || validator.isEmpty(secret))
        return;
    try {
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", key, secret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Dysmsapi", "dysmsapi.aliyuncs.com");
        acsClient = new DefaultAcsClient(profile);
        if (logger.isInfoEnable())
            logger.info("初始化阿里云短信接口[{}]完成。", key);
    } catch (Exception e) {
        logger.warn(e, "初始化阿里云短信接口时发生异常!");
    }
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile)

Aggregations

IClientProfile (com.aliyuncs.profile.IClientProfile)7 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)6 IAcsClient (com.aliyuncs.IAcsClient)2 DescribeInstancesRequest (com.aliyuncs.ecs.model.v20140526.DescribeInstancesRequest)2 Instance (com.aliyuncs.ecs.model.v20140526.DescribeInstancesResponse.Instance)2 DescribeZonesRequest (com.aliyuncs.ecs.model.v20140526.DescribeZonesRequest)2 DescribeZonesResponse (com.aliyuncs.ecs.model.v20140526.DescribeZonesResponse)2 ClientException (com.aliyuncs.exceptions.ClientException)1 AssumeRoleRequest (com.aliyuncs.sts.model.v20150401.AssumeRoleRequest)1 AssumeRoleResponse (com.aliyuncs.sts.model.v20150401.AssumeRoleResponse)1 DefaultAcsClient (com.github.isdream.chameleon.vm.aliyun.adapters.DefaultAcsClient)1 SmsException (io.picos.sailfish.mfa.sms.exception.SmsException)1 JsonObject (io.vertx.core.json.JsonObject)1 io.vertx.up.exception._424ProfileEndPointException (io.vertx.up.exception._424ProfileEndPointException)1 PostConstruct (javax.annotation.PostConstruct)1 Bean (org.springframework.context.annotation.Bean)1