com.eworkcloud.web.util.DnsDomainUtils Maven / Gradle / Ivy
package com.eworkcloud.web.util;
import com.aliyun.domain20180129.Client;
import com.aliyun.domain20180129.models.QueryDomainListRequest;
import com.aliyun.domain20180129.models.QueryDomainListResponse;
import com.aliyun.domain20180129.models.QueryDomainListResponseBody;
import com.aliyun.teaopenapi.models.Config;
import com.eworkcloud.dns.DnsConfiguration;
import com.eworkcloud.dns.model.AliDomain;
import lombok.SneakyThrows;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public abstract class DnsDomainUtils {
/**
* 获取客户端
*
* @param endpoint 访问端点
* @param accessKey 访问钥匙
* @param secretKey 安全密钥
* @return 客户端
*/
@SneakyThrows
public static Client getClient(String endpoint, String accessKey, String secretKey) {
Config config = new Config();
config.setEndpoint(endpoint);
config.setAccessKeyId(accessKey);
config.setAccessKeySecret(secretKey);
return new Client(config);
}
/**
* 获取客户端
*
* @return 客户端
*/
public static Client getClient() {
return getClient(DnsConfiguration.getEndpoint(),
DnsConfiguration.getAccessKey(), DnsConfiguration.getSecretKey());
}
/**
* 获取域名列表
*
* @param client 客户端
* @return 域名列表
*/
@SneakyThrows
public static List getDomains(Client client) {
QueryDomainListRequest request = new QueryDomainListRequest();
request.setPageSize(100);
request.setPageNum(1);
List aliDomains = new ArrayList<>();
QueryDomainListResponse response;
do {
response = client.queryDomainList(request);
for (QueryDomainListResponseBody.QueryDomainListResponseBodyDataDomain domain : response.body.data.domain) {
AliDomain aliDomain = new AliDomain();
aliDomain.setDomain(domain.domainName);
aliDomain.setEndTime(new Date(domain.expirationDateLong));
aliDomain.setStatus(Integer.parseInt(domain.domainStatus));
aliDomains.add(aliDomain);
}
request.setPageNum(response.body.currentPageNum + 1);
} while (response.body.nextPage);
return aliDomains;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy