Search in sources :

Example 6 with IClientProfile

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

the class ECSMain 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());
    }
// dur.setZoneId(zoneId);;
}
Also used : DefaultAcsClient(com.github.isdream.chameleon.vm.aliyun.adapters.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 7 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project sailfish-mfa by picos-io.

the class AliyunSmsSender method init.

@PostConstruct
private void init() {
    try {
        IClientProfile profile = DefaultProfile.getProfile(region, accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint(region, region, "Dysmsapi", endpoint);
        client = new DefaultAcsClient(profile);
    } catch (Throwable e) {
        throw new SmsException("Initialize the ALIYUN SMS client failed.", e);
    }
}
Also used : DefaultAcsClient(com.aliyuncs.DefaultAcsClient) IClientProfile(com.aliyuncs.profile.IClientProfile) SmsException(io.picos.sailfish.mfa.sms.exception.SmsException) PostConstruct(javax.annotation.PostConstruct)

Example 8 with IClientProfile

use of com.aliyuncs.profile.IClientProfile in project notes by KevinBlandy.

the class MainTest method main.

public static void main(String[] args) throws Exception {
    String endpoint = "sts.aliyuncs.com";
    String accessKeyId = "LTAI4GEya";
    String accessKeySecret = "3Di5yzv38";
    String roleArn = "acs:ram::17765";
    String roleSessionName = "myapp";
    JsonObject policy = new JsonObject();
    JsonArray statement = new JsonArray();
    policy.addProperty("Version", "1");
    JsonObject item = new JsonObject();
    item.addProperty("Effect", "Allow");
    item.addProperty("Action", "oss:GetObject");
    JsonArray resource = new JsonArray();
    resource.add("acs:oss:*:*:javaweb-community");
    item.add("Resource", resource);
    statement.add(item);
    policy.add("Statement", statement);
    try {
        DefaultProfile.addEndpoint("", "Sts", endpoint);
        IClientProfile profile = DefaultProfile.getProfile("", accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        final AssumeRoleRequest request = new AssumeRoleRequest();
        request.setSysMethod(MethodType.POST);
        request.setRoleArn(roleArn);
        request.setRoleSessionName(roleSessionName);
        // ��policyΪ�գ����û�����øý�ɫ������Ȩ��
        request.setPolicy(policy.toString());
        // ����ƾ֤��Чʱ��
        request.setDurationSeconds(1000L);
        final AssumeRoleResponse response = client.getAcsResponse(request);
        System.out.println("Expiration: " + response.getCredentials().getExpiration());
        System.out.println("Access Key Id: " + response.getCredentials().getAccessKeyId());
        System.out.println("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
        System.out.println("Security Token: " + response.getCredentials().getSecurityToken());
        System.out.println("RequestId: " + response.getRequestId());
        OSS ossClient = new OSSClientBuilder().build("oss-cn-beijing.aliyuncs.com", accessKeyId, accessKeySecret);
        // ����URL����ʱ��Ϊ1Сʱ��
        Date expiration = new Date(new Date().getTime() + (3600 * 1000));
        // ������GET�������ʵ�ǩ��URL���ÿͿ���ֱ��ͨ�����������������ݡ�
        URL url = ossClient.generatePresignedUrl("javaweb-community", "2020/07/06/36b91863ced64cce953cb312bce9e99d.jpg", expiration);
        // �ر�OSSClient��
        ossClient.shutdown();
        System.out.println(url);
    } catch (ClientException e) {
        System.out.println("Failed��");
        System.out.println("Error code: " + e.getErrorCode());
        System.out.println("Error message: " + e.getErrorCode());
        System.out.println("RequestId: " + e.getRequestId());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) AssumeRoleRequest(com.aliyuncs.auth.sts.AssumeRoleRequest) DefaultAcsClient(com.aliyuncs.DefaultAcsClient) AssumeRoleResponse(com.aliyuncs.auth.sts.AssumeRoleResponse) JsonObject(com.google.gson.JsonObject) ClientException(com.aliyun.oss.ClientException) IClientProfile(com.aliyuncs.profile.IClientProfile) OSS(com.aliyun.oss.OSS) OSSClientBuilder(com.aliyun.oss.OSSClientBuilder) Date(java.util.Date) URL(java.net.URL)

Aggregations

IClientProfile (com.aliyuncs.profile.IClientProfile)8 DefaultAcsClient (com.aliyuncs.DefaultAcsClient)7 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.aliyun.oss.ClientException)1 OSS (com.aliyun.oss.OSS)1 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)1 AssumeRoleRequest (com.aliyuncs.auth.sts.AssumeRoleRequest)1 AssumeRoleResponse (com.aliyuncs.auth.sts.AssumeRoleResponse)1 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 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 SmsException (io.picos.sailfish.mfa.sms.exception.SmsException)1 JsonObject (io.vertx.core.json.JsonObject)1