Skip to content

Commit c0801bb

Browse files
authored
Feature inventory/logging/tagging (#127)
* update Test * feature of inventory/logging/tagging
1 parent d4ef6f6 commit c0801bb

File tree

10 files changed

+764
-71
lines changed

10 files changed

+764
-71
lines changed

sample/deleteBucketTagging.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->deleteBucketTagging(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/getBucketInventory.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->getBucketInvnetory(array(
17+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
18+
'Id' => 'string',
19+
));
20+
// 请求成功
21+
print_r($result);
22+
} catch (\Exception $e) {
23+
// 请求失败
24+
echo($e);
25+
}
26+

sample/getBucketLogging.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->getBucketLogging(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/getBucketTagging.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->getBucketTagging(array(
17+
'Bucket' => 'examplebucket-125000000' //格式:BucketName-APPID
18+
));
19+
// 请求成功
20+
print_r($result);
21+
} catch (\Exception $e) {
22+
// 请求失败
23+
echo($e);
24+
}
25+

sample/putBucketInventory.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->putBucketInventory(array(
17+
'Bucket'=>$bucket,
18+
//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
19+
'Id' => 'string',
20+
'Destination' => array(
21+
'COSBucketDestination'=>array(
22+
'Format' => 'CSV',
23+
'AccountId' => '125000000',
24+
'Bucket' => 'qcs::cos:ap-chengdu::examplebucket-125000000',
25+
'Prefix' => 'string',
26+
)
27+
),
28+
'IsEnabled' => 'True',
29+
'Schedule' => array(
30+
'Frequency' => 'Daily',
31+
),
32+
'Filter' => array(
33+
'Prefix' => 'string',
34+
),
35+
'IncludedObjectVersions' => 'Current',
36+
'OptionalFields' => array(
37+
'Size',
38+
'ETag',
39+
)
40+
));
41+
// 请求成功
42+
print_r($result);
43+
} catch (\Exception $e) {
44+
// 请求失败
45+
echo "$e\n";
46+
}
47+

sample/putBucketLogging.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->putBucketLogging(array(
17+
//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
18+
'Bucket'=>$bucket,
19+
'LoggingEnabled' => array(
20+
'TargetBucket' => 'lewzylucd-1251668577',
21+
'TargetPrefix' => '',
22+
)
23+
));
24+
// 请求成功
25+
print_r($result);
26+
} catch (\Exception $e) {
27+
// 请求失败
28+
echo "$e\n";
29+
}
30+

sample/putBucketTagging.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
$result = $cosClient->putBucketTagging(array(
17+
//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
18+
'Bucket'=>$bucket,
19+
'TagSet' => array(
20+
array('Key'=>'key1',
21+
'Value'=>'value1',
22+
),
23+
array('Key'=>'key2',
24+
'Value'=>'value2',
25+
),
26+
),
27+
));
28+
// 请求成功
29+
print_r($result);
30+
} catch (\Exception $e) {
31+
// 请求失败
32+
echo "$e\n";
33+
}
34+

src/Qcloud/Cos/Client.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ public function __construct($cosConfig) {
6767
$this->signature = new Signature($this->cosConfig['secretId'], $this->cosConfig['secretKey']);
6868
$this->httpClient = new HttpClient([
6969
'base_uri' => $this->cosConfig['schema'].'://cos.' . $this->cosConfig['region'] . '.myqcloud.com/',
70+
'timeout' => $this->cosConfig['timeout'],
7071
'handler' => $handler,
71-
'proxy' => $this->cosConfig['proxy']
72+
'proxy' => $this->cosConfig['proxy'],
7273
]);
7374
$this->desc = new Description($service);
7475
$this->api = (array)($this->desc->getOperations());
@@ -87,6 +88,7 @@ public function commandToRequestTransformer(CommandInterface $command)
8788
$request = $transformer->bucketStyleTransformer($command, $request);
8889
$request = $transformer->uploadBodyTransformer($command, $request);
8990
$request = $transformer->md5Transformer($command, $request);
91+
$request = $transformer->specialParamTransformer($command, $request);
9092
return $request;
9193
}
9294

src/Qcloud/Cos/CosTransformer.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public function bucketStyleTransformer(CommandInterface $command, RequestInterfa
6666
}
6767
$path = $this->config['schema'].'://'. $host . $uri;
6868
$uri = new Uri($path);
69-
$uri = $uri->withQuery($request->getUri()->getQuery());
69+
$query = $request->getUri()->getQuery();
70+
if ($uri->getQuery() != $query && $uri->getQuery() != "") {
71+
$query = $uri->getQuery() . "&" . $request->getUri()->getQuery();
72+
}
73+
$uri = $uri->withQuery($query);
7074
return $request->withUri($uri);
7175
}
7276

@@ -119,6 +123,19 @@ private function addMd5($request) {
119123
return $request;
120124
}
121125

126+
// count md5
127+
public function specialParamTransformer(CommandInterface $command, $request) {
128+
$action = $command->getName();
129+
if ($action == 'PutBucketInventory') {
130+
$id = $command['Id'];
131+
$uri = $request->getUri();
132+
$query = $uri->getQuery();
133+
$uri = $uri->withQuery($query . "&Id=".$id);
134+
return $request->withUri($uri);
135+
}
136+
return $request;
137+
}
138+
122139
public function __destruct() {
123140
}
124141

0 commit comments

Comments
 (0)