Skip to content

Commit 6e1ec41

Browse files
committed
add bucket access monitor api and modify bucket lifecycle rule
1 parent 572d0f8 commit 6e1ec41

26 files changed

+2132
-208
lines changed

samples/Bucket.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// Get the info of bucket
3030
$info = $ossClient->getBucketInfo($bucket);
3131
Common::println("bucket name:".$info->getName()."\n");
32+
Common::println("bucket access monitor:".$info->getAccessMonitor()."\n");
3233
Common::println("bucket location:". $info->getLocation()."\n");
3334
Common::println("bucket creation time:".$info->getCreateDate()."\n");
3435
Common::println("bucket storage class:".$info->getStorageClass()."\n");
@@ -114,6 +115,7 @@ function getBucketInfo($ossClient, $bucket)
114115
try {
115116
$info = $ossClient->getBucketInfo($bucket);
116117
printf("bucket name:%s\n", $info->getName());
118+
printf("bucket access monitor:%s",$info->getAccessMonitor()."\n");
117119
printf("bucket location:%s\n", $info->getLocation());
118120
printf("bucket creation time:%s\n", $info->getCreateDate());
119121
printf("bucket storage class:%s\n", $info->getStorageClass());

samples/BucketAccessMonitor.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
require_once __DIR__ . '/Common.php';
4+
5+
use OSS\OssClient;
6+
use OSS\Core\OssException;
7+
8+
$ossClient = Common::getOssClient();
9+
if (is_null($ossClient)) exit(1);
10+
$bucket = Common::getBucketName();
11+
12+
//******************************* Simple Usage****************************************************************
13+
14+
// put access monitor
15+
$status = 'Enabled';
16+
$ossClient->putBucketAccessMonitor($bucket, $status);
17+
printf('Put Bucket Access Monitor Success' . "\n");
18+
19+
20+
// get access monitor
21+
$status = $ossClient->getBucketAccessMonitor($bucket);
22+
printf('Get Bucket Access Monitor Status:%s'."\n",$status);
23+
24+
25+
//******************************* For complete usage, see the following functions ****************************************************
26+
putBucketAccessMonitor($ossClient,$bucket);
27+
getBucketAccessMonitor($ossClient,$bucket);
28+
29+
/**
30+
* Put Bucket Access Monitor
31+
* @param $ossClient OssClient
32+
* @param string $bucket bucket_name string
33+
*/
34+
function putBucketAccessMonitor($ossClient, $bucket)
35+
{
36+
try{
37+
$status = 'Enabled'; // set Enabled to enable access monitor; set Disabled to disable access monitor
38+
$ossClient->putBucketAccessMonitor($bucket,$status);
39+
printf('Put Bucket Access Monitor Success' . "\n");
40+
} catch(OssException $e) {
41+
printf($e->getMessage() . "\n");
42+
return;
43+
}
44+
print(__FUNCTION__ . ": OK" . "\n");
45+
}
46+
47+
/**
48+
* Get Bucket Access Monitor
49+
* @param $ossClient OssClient
50+
* @param string $bucket bucket_name
51+
*/
52+
function getBucketAccessMonitor($ossClient, $bucket)
53+
{
54+
try{
55+
$status = $ossClient->getBucketAccessMonitor($bucket);
56+
printf('Get Bucket Access Monitor Status:%s'."\n",$status);
57+
} catch(OssException $e) {
58+
printf($e->getMessage() . "\n");
59+
return;
60+
}
61+
print(__FUNCTION__ . ": OK" . "\n");
62+
}

0 commit comments

Comments
 (0)