use of com.qcloud.cos.model.CreateBucketRequest in project jeesuite-libs by vakinge.
the class QcloudProvider method createBucket.
@Override
public void createBucket(String bucketName, boolean isPrivate) {
bucketName = buildBucketName(bucketName);
if (cosclient.doesBucketExist(bucketName)) {
throw new JeesuiteBaseException(406, "bucketName[" + bucketName + "]已存在");
}
CreateBucketRequest request = new CreateBucketRequest(bucketName);
if (isPrivate) {
request.setCannedAcl(CannedAccessControlList.Private);
} else {
request.setCannedAcl(CannedAccessControlList.PublicRead);
}
cosclient.createBucket(request);
}
use of com.qcloud.cos.model.CreateBucketRequest in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method createBucket.
private static void createBucket() throws Exception {
try {
// 避免有查询缓存,导致创建bucket失败
Thread.sleep(5000L);
String bucketName = bucket;
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
Bucket createdBucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, createdBucket.getName());
Thread.sleep(5000L);
assertTrue(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
use of com.qcloud.cos.model.CreateBucketRequest in project cos-java-sdk-v5 by tencentyun.
the class AclTest method GetAclForNewPubReadBucket.
@Test
public void GetAclForNewPubReadBucket() throws InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
String aclTestBucketName = null;
try {
aclTestBucketName = "javasdkacltest-" + appid;
CreateBucketRequest createBucketRequest = new CreateBucketRequest(aclTestBucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
cosclient.createBucket(createBucketRequest);
AccessControlList aclGet = cosclient.getBucketAcl(aclTestBucketName);
assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.PublicRead);
assertNotNull(aclGet.getOwner());
assertNotNull(aclGet.getOwner().getId());
assertNotNull(aclGet.getOwner().getDisplayName());
assertEquals(2, aclGet.getGrantsAsList().size());
Grant firstGrant = aclGet.getGrantsAsList().get(0);
assertEquals(Permission.Read.toString(), firstGrant.getPermission().toString());
assertTrue(firstGrant.getGrantee() instanceof GroupGrantee);
Grant secondGrant = aclGet.getGrantsAsList().get(1);
assertEquals(Permission.FullControl.toString(), secondGrant.getPermission().toString());
assertTrue(secondGrant.getGrantee() instanceof UinGrantee);
// set to PublicReadWrite acl and get canned acl compare
Thread.sleep(5000);
cosclient.setBucketAcl(aclTestBucketName, CannedAccessControlList.PublicReadWrite);
aclGet = cosclient.getBucketAcl(aclTestBucketName);
assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.PublicReadWrite);
// set to private and get canned acl compare
Thread.sleep(5000);
cosclient.setBucketAcl(aclTestBucketName, CannedAccessControlList.Private);
aclGet = cosclient.getBucketAcl(aclTestBucketName);
assertEquals(aclGet.getCannedAccessControl(), CannedAccessControlList.Private);
} finally {
if (aclTestBucketName != null) {
cosclient.deleteBucket(aclTestBucketName);
aclTestBucketName = null;
}
}
}
use of com.qcloud.cos.model.CreateBucketRequest in project cos-java-sdk-v5 by tencentyun.
the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPublicRead.
@Test
public void testCreateDeleteBucketPublicRead() throws Exception {
if (!judgeUserInfoValid()) {
return;
}
try {
String bucketName = String.format("java-pubr-%s", appid);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicRead);
Bucket bucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, bucket.getName());
cosclient.headBucket(new HeadBucketRequest(bucketName));
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
cosclient.deleteBucket(bucketName);
// 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
Thread.sleep(5000L);
assertFalse(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
use of com.qcloud.cos.model.CreateBucketRequest in project cos-java-sdk-v5 by tencentyun.
the class CreateDeleteHeadBucketTest method testCreateDeleteBucketPublicReadWrite.
@Test
public void testCreateDeleteBucketPublicReadWrite() throws Exception {
if (!judgeUserInfoValid()) {
return;
}
try {
String bucketName = String.format("java-pubrw-%s", appid);
CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
createBucketRequest.setCannedAcl(CannedAccessControlList.PublicReadWrite);
AccessControlList accessControlList = new AccessControlList();
Grantee grantee = new UinGrantee("730123456");
accessControlList.grantPermission(grantee, Permission.Write);
createBucketRequest.setAccessControlList(accessControlList);
Bucket bucket = cosclient.createBucket(createBucketRequest);
assertEquals(bucketName, bucket.getName());
assertTrue(cosclient.doesBucketExist(bucketName));
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(bucketName);
assertEquals(BucketVersioningConfiguration.OFF, bucketVersioningConfiguration.getStatus());
cosclient.deleteBucket(bucketName);
// 删除bucket后, 由于server端有缓存 需要稍后查询, 这里sleep 5 秒
Thread.sleep(5000L);
assertFalse(cosclient.doesBucketExist(bucketName));
} catch (CosServiceException cse) {
fail(cse.toString());
}
}
Aggregations