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);;
}
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);
}
}
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());
}
}
Aggregations