Search in sources :

Example 1 with BucketDomainConfiguration

use of com.qcloud.cos.model.BucketDomainConfiguration in project cos-java-sdk-v5 by tencentyun.

the class BucketDomainDemo method SetGetDeleteBucketDomainDemo.

public static void SetGetDeleteBucketDomainDemo() {
    // 1 初始化用户身份信息(secretId, secretKey)
    COSCredentials cred = new BasicCOSCredentials("AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
    // 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));
    // 3 生成cos客户端
    COSClient cosclient = new COSClient(cred, clientConfig);
    // bucket名需包含appid
    String bucketName = "mybucket-1251668577";
    BucketDomainConfiguration bucketDomainConfiguration = new BucketDomainConfiguration();
    DomainRule domainRule = new DomainRule();
    domainRule.setStatus(DomainRule.ENABLED);
    domainRule.setType(DomainRule.REST);
    domainRule.setName("test.com");
    // domainRule.setForcedReplacement(DomainRule.TXT);
    bucketDomainConfiguration.getDomainRules().add(domainRule);
    cosclient.setBucketDomainConfiguration(bucketName, bucketDomainConfiguration);
    BucketDomainConfiguration bucketDomainConfiguration1 = cosclient.getBucketDomainConfiguration(bucketName);
    System.out.println(bucketDomainConfiguration1.getDomainTxtVerification());
    for (DomainRule rule : bucketDomainConfiguration1.getDomainRules()) {
        System.out.println(rule.getName());
        System.out.println(rule.getStatus());
        System.out.println(rule.getType());
        System.out.println(rule.getClass());
    }
    cosclient.deleteBucketDomainConfiguration(bucketName);
    BucketDomainConfiguration bucketDomainConfiguration2 = cosclient.getBucketDomainConfiguration(bucketName);
    assert (bucketDomainConfiguration2 == null);
}
Also used : COSClient(com.qcloud.cos.COSClient) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Region(com.qcloud.cos.region.Region) ClientConfig(com.qcloud.cos.ClientConfig) BucketDomainConfiguration(com.qcloud.cos.model.BucketDomainConfiguration) DomainRule(com.qcloud.cos.model.DomainRule)

Aggregations

COSClient (com.qcloud.cos.COSClient)1 ClientConfig (com.qcloud.cos.ClientConfig)1 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)1 COSCredentials (com.qcloud.cos.auth.COSCredentials)1 BucketDomainConfiguration (com.qcloud.cos.model.BucketDomainConfiguration)1 DomainRule (com.qcloud.cos.model.DomainRule)1 Region (com.qcloud.cos.region.Region)1