-
Notifications
You must be signed in to change notification settings - Fork 58
/
bucket_policy.js
71 lines (61 loc) · 1.99 KB
/
bucket_policy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 设置存储桶 Policy
function putBucketPolicy(assert) {
//.cssg-snippet-body-start:[put-bucket-policy]
cos.putBucketPolicy({
Bucket: 'examplebucket-1250000000', /* 必须 */
Region: 'COS_REGION', /* 存储桶所在地域,必须字段 */
Policy: {
"version": "2.0",
"Statement": [{
"Effect": "allow",
"Principal": {
"qcs": ["qcs::cam::uin/100000000001:uin/100000000001"]
},
"Action": [
"name/cos:PutObject",
"name/cos:InitiateMultipartUpload",
"name/cos:ListMultipartUploads",
"name/cos:ListParts",
"name/cos:UploadPart",
"name/cos:CompleteMultipartUpload"
],
"Resource": ["qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"],
}]
},
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
// 获取存储桶 Policy
function getBucketPolicy(assert) {
//.cssg-snippet-body-start:[get-bucket-policy]
cos.getBucketPolicy({
Bucket: 'examplebucket-1250000000', /* 必须 */
Region: 'COS_REGION', /* 存储桶所在地域,必须字段 */
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
// 删除存储桶 Policy
function deleteBucketPolicy(assert) {
//.cssg-snippet-body-start:[delete-bucket-policy]
cos.deleteBucketPolicy({
Bucket: 'examplebucket-1250000000', /* 必须 */
Region: 'COS_REGION', /* 存储桶所在地域,必须字段 */
}, function(err, data) {
console.log(err || data);
});
//.cssg-snippet-body-end
}
//.cssg-methods-pragma
test("BucketPolicy", async function(assert) {
// 设置存储桶 Policy
await putBucketPolicy(assert)
// 获取存储桶 Policy
await getBucketPolicy(assert)
// 删除存储桶 Policy
await deleteBucketPolicy(assert)
//.cssg-methods-pragma
})