diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ca058e7d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: php +php: + - 5.6 +script: phpunit -v \ No newline at end of file diff --git a/cos-autoloader.php b/cos-autoloader.php index 7d0efb83..97a84e69 100644 --- a/cos-autoloader.php +++ b/cos-autoloader.php @@ -248,6 +248,7 @@ 'Qcloud\Cos\Exception\ServiceResponseException' => 'src/Qcloud/Cos/Exception/ServiceResponseException.php', 'Qcloud\Cos\ExceptionListener' => 'src/Qcloud/Cos/ExceptionListener.php', 'Qcloud\Cos\ExceptionParser' => 'src/Qcloud/Cos/ExceptionParser.php', + 'Qcloud\Cos\Md5Listener' => 'src/Qcloud/Cos/Md5Listener.php', 'Qcloud\Cos\MultipartUpload' => 'src/Qcloud/Cos/MultipartUpload.php', 'Qcloud\Cos\Service' => 'src/Qcloud/Cos/Service.php', 'Qcloud\Cos\Signature' => 'src/Qcloud/Cos/Signature.php', @@ -277,4 +278,4 @@ if (isset($mapping[$class])) { require $mapping[$class]; } -}, true); +}, true); \ No newline at end of file diff --git a/sample.php b/sample.php index 8d4f00ce..b8896ac1 100644 --- a/sample.php +++ b/sample.php @@ -2,22 +2,20 @@ require(__DIR__ . DIRECTORY_SEPARATOR . 'cos-autoloader.php'); -$cosClient = new Qcloud\Cos\Client( - array( - 'region' => 'cn-north', - 'credentials'=> array( - 'appId' => '', - 'secretId' => '', - 'secretKey' => ''))); -#listBuckets -try { - $result = $cosClient->listBuckets(); - print_r($result); -} catch (\Exception $e) { - echo "$e\n"; -} - - +$cosClient = new Qcloud\Cos\Client(array('region' => getenv('COS_REGION'), + 'credentials'=> array( + 'appId' => getenv('COS_APPID'), + 'secretId' => getenv('COS_KEY'), + 'secretKey' => getenv('COS_SECRET')))); +//#listBuckets +//try { +// $result = $cosClient->listBuckets(); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +// #createBucket try { $result = $cosClient->createBucket(array('Bucket' => 'testbucket')); @@ -26,91 +24,257 @@ echo "$e\n"; } -#uploadbigfile -try { - $result = $cosClient->upload( - $bucket='testbucket', - '111.txt', - str_repeat('a', 5* 1024 * 1024)); - print_r($result); - } catch (\Exception $e) { - echo "$e\n"; -} - -#putObject +//#uploadbigfile +//try { +// $result = $cosClient->upload( +// $bucket='testbucket', +// '111.txt', +// str_repeat('a', 5* 1024 * 1024)); +// print_r($result);1 +// } catch (\Exception $e) { +// echo "$e\n"; +//} +// +//#putObject try { $result = $cosClient->putObject(array( 'Bucket' => 'testbucket', - 'Key' => '111', + 'Key' => '11', 'Body' => 'Hello World!')); print_r($result); } catch (\Exception $e) { echo "$e\n"; } - -#getObject -try { - $result = $cosClient->getObject(array( - 'Bucket' => 'testbucket', - 'Key' => '111', - 'Body' => 'Hello World!')); - print_r($result); -} catch (\Exception $e) { - echo "$e\n"; -} - -#deleteObject -try { - $result = $cosClient->deleteObject(array( - 'Bucket' => 'testbucket', - 'Key' => '111')); - print_r($result); -} catch (\Exception $e) { - echo "$e\n"; -} - - -#deleteBucket +// +//#getObject +//try { +// $result = $cosClient->getObject(array( +// 'Bucket' => 'testbucket', +// 'Key' => '111')); +// echo($result['Body']); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +//#deleteObject +//try { +// $result = $cosClient->deleteObject(array( +// 'Bucket' => 'testbucket', +// 'Key' => '111')); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +// +//#deleteBucket +//try { +// $result = $cosClient->deleteBucket(array( +// 'Bucket' => 'testbucket')); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +//#headObject +//try { +// $result = $cosClient->headObject(array( +// 'Bucket' => 'testbucket', +// 'Key' => 'hello.txt')); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +//#listObjects +//try { +// $result = $cosClient->listObjects(array( +// 'Bucket' => 'testbucket')); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#putObjectUrl +//try { +// $bucket = 'testbucket'; +// $key = 'hello.txt'; +// $region = 'cn-south'; +// $url = "/{$key}"; +// $request = $cosClient->get($url); +// $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes'); +// echo ($signedUrl); +// +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#putBucketACL +//try { +// $result = $cosClient->PutBucketAcl(array( +// 'Bucket' => 'testbucket', +// 'Grants' => array( +// array( +// 'Grantee' => array( +// 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', +// 'ID' => 'qcs::cam::uin/327874225:uin/327874225', +// 'Type' => 'CanonicalUser', +// ), +// 'Permission' => 'FULL_CONTROL', +// ), +// // ... repeated +// ), +// 'Owner' => array( +// 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', +// 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', +// ),)); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#getBucketACL +//try { +// $result = $cosClient->GetBucketAcl(array( +// 'Bucket' => 'testbucket',)); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +#putObjectACL try { - $result = $cosClient->deleteBucket(array( - 'Bucket' => 'testbucket')); - print_r($result); -} catch (\Exception $e) { - echo "$e\n"; -} - -#headObject -try { - $result = $cosClient->headObject(array( + $result = $cosClient->PutBucketAcl(array( 'Bucket' => 'testbucket', - 'Key' => 'hello.txt')); + 'Grants' => array( + array( + 'Grantee' => array( + 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', + 'ID' => 'qcs::cam::uin/327874225:uin/327874225', + 'Type' => 'CanonicalUser', + ), + 'Permission' => 'FULL_CONTROL', + ), + // ... repeated + ), + 'Owner' => array( + 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', + 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', + ),)); print_r($result); } catch (\Exception $e) { echo "$e\n"; } -#listObjects -try { - $result = $cosClient->listObjects(array( - 'Bucket' => 'testbucket')); - print_r($result); -} catch (\Exception $e) { - echo "$e\n"; -} - - -#getObjectUrl -try { - $bucket = 'testbucket'; - $key = 'hello.txt'; - $region = 'cn-south'; - $url = "/{$key}"; - $request = $cosClient->get($url); - $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes'); - echo ($signedUrl); - -} catch (\Exception $e) { - echo "$e\n"; -} - - +//#getObjectACL +//try { +// $result = $cosClient->getObjectAcl(array( +// 'Bucket' => 'testbucket', +// 'Key' => '11')); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#putBucketLifecycle +//try { +// $result = $cosClient->putBucketLifecycle(array( +// // Bucket is required +// 'Bucket' => 'lewzylu02', +// // Rules is required +// 'Rules' => array( +// array( +// 'Expiration' => array( +// 'Days' => 1, +// ), +// 'ID' => 'id1', +// 'Filter' => array( +// 'Prefix' => 'documents/' +// ), +// // Status is required +// 'Status' => 'Enabled', +// 'Transition' => array( +// 'Days' => 100, +// 'StorageClass' => 'NEARLINE', +// ), +// // ... repeated +// ), +// ))); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#getBucketLifecycle +//try { +// $result = $cosClient->getBucketLifecycle(array( +// // Bucket is required +// 'Bucket' =>'lewzylu02', +// )); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +// +//#deleteBucketLifecycle +//try { +// $result = $cosClient->deleteBucketLifecycle(array( +// // Bucket is required +// 'Bucket' =>'lewzylu02', +// )); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#putBucketCors +//try { +// $result = $cosClient->putBucketCors(array( +// // Bucket is required +// 'Bucket' => 'lewzylu02', +// // CORSRules is required +// 'CORSRules' => array( +// array( +// 'AllowedHeaders' => array('*',), +// // AllowedMethods is required +// 'AllowedMethods' => array('Put', ), +// // AllowedOrigins is required +// 'AllowedOrigins' => array('*', ), +// 'ExposeHeaders' => array('*', ), +// 'MaxAgeSeconds' => 1, +// ), +// // ... repeated +// ), +// )); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#getBucketCors +//try { +// $result = $cosClient->getBucketCors(array( +// // Bucket is required +// 'Bucket' => 'lewzylu02', +// )); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#deleteBucketCors +//try { +// $result = $cosClient->deleteBucketCors(array( +// // Bucket is required +// 'Bucket' => 'lewzylu02', +// )); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} +//#copyobject +//try { +// $result = $cosClient->copyObject(array( +// // Bucket is required +// 'Bucket' => 'lewzylu02', +// // CopySource is required +// 'CopySource' => 'lewzylu03-1252448703.cos.ap-guangzhou.myqcloud.com/tox.ini', +// // Key is required +// 'Key' => 'string', +// )); +// print_r($result); +//} catch (\Exception $e) { +// echo "$e\n"; +//} diff --git a/src/Qcloud/Cos/Client.php b/src/Qcloud/Cos/Client.php index dd0e7694..3baf872b 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -52,11 +52,12 @@ public function __construct($config) { $this->setUserAgent('cos-php-sdk-v5/' . Client::VERSION, true); $this->addSubscriber(new ExceptionListener()); +$this->addSubscriber(new Md5Listener($this->signature)); $this->addSubscriber(new TokenListener($this->token)); $this->addSubscriber(new SignatureListener($this->secretId, $this->secretKey)); $this->addSubscriber(new BucketStyleListener($this->appId)); - // Allow for specifying bodies with file paths and file handles +// Allow for specifying bodies with file paths and file handles $this->addSubscriber(new UploadBodyListener(array('PutObject', 'UploadPart'))); } diff --git a/src/Qcloud/Cos/Md5Listener.php b/src/Qcloud/Cos/Md5Listener.php new file mode 100644 index 00000000..95956000 --- /dev/null +++ b/src/Qcloud/Cos/Md5Listener.php @@ -0,0 +1,57 @@ + 'onCommandAfterPrepare'); + } + + public function __construct(Signature $signature) + { + $this->signature = $signature; + } + + public function onCommandAfterPrepare(Event $event) + { + $command = $event['command']; + $operation = $command->getOperation(); + + if ($operation->getData('contentMd5')) { + // Add the MD5 if it is required for all signers + $this->addMd5($command); + } elseif ($operation->hasParam('ContentMD5')) { + $value = $command['ContentMD5']; + // Add a computed MD5 if the parameter is set to true or if + // not using Signature V4 and the value is not set (null). + if ($value === true || + ($value === null && !($this->signature instanceof SignatureV4)) + ) { + $this->addMd5($command); + } + } + } + + private function addMd5(CommandInterface $command) + { + $request = $command->getRequest(); + $body = $request->getBody(); + if ($body && $body->getSize() > 0) { + if (false !== ($md5 = $body->getContentMd5(true, true))) { + $request->setHeader('Content-MD5', $md5); + } + } + } +} diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 3b3fa472..15a0bb37 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -11,19 +11,6 @@ public static function getService() { 'description' => 'Cos V5 API Service', 'operations' => array( - 'ListBuckets' => array( - 'httpMethod' => 'GET', - 'uri' => '/', - 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'ListBucketsOutput', - 'responseType' => 'model', - 'parameters' => array( - 'command.expects' => array( - 'static' => true, - 'default' => 'application/xml', - ), - ), - ), 'AbortMultipartUpload' => array( 'httpMethod' => 'DELETE', 'uri' => '/{Bucket}{/Key*}', @@ -73,6 +60,295 @@ public static function getService() { array( 'reason' => 'The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.', 'class' => 'BucketAlreadyExistsException'))), + 'CompleteMultipartUpload' => array( + 'httpMethod' => 'POST', + 'uri' => '/{Bucket}{/Key*}', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'CompleteMultipartUploadOutput', + 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'CompleteMultipartUpload')), + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri'), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), + 'Parts' => array( + 'type' => 'array', + 'location' => 'xml', + 'data' => array( + 'xmlFlattened' => true), + 'items' => array( + 'name' => 'CompletedPart', + 'type' => 'object', + 'sentAs' => 'Part', + 'properties' => array( + 'ETag' => array( + 'type' => 'string'), + 'PartNumber' => array( + 'type' => 'numeric')))), + 'UploadId' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'uploadId'), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml'))), + 'CreateMultipartUpload' => array( + 'httpMethod' => 'POST', + 'uri' => '/{Bucket}{/Key*}?uploads', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'CreateMultipartUploadOutput', + 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'CreateMultipartUploadRequest')), + 'parameters' => array( + 'ACL' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-acl'), + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri'), + 'CacheControl' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Cache-Control'), + 'ContentDisposition' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Disposition'), + 'ContentEncoding' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Encoding'), + 'ContentLanguage' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Language'), + 'ContentType' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Type'), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), + 'Metadata' => array( + 'type' => 'object', + 'location' => 'header', + 'sentAs' => 'x-cos-meta-', + 'additionalProperties' => array( + 'type' => 'string')), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml'))), + 'CopyObject' => array( + 'httpMethod' => 'PUT', + 'uri' => '/{Bucket}{/Key*}', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'CopyObjectOutput', + 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'CopyObjectRequest', + ), + ), + 'parameters' => array( + 'ACL' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-acl', + ), + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + 'CacheControl' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Cache-Control', + ), + 'ContentDisposition' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Disposition', + ), + 'ContentEncoding' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Encoding', + ), + 'ContentLanguage' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Language', + ), + 'ContentType' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'Content-Type', + ), + 'CopySource' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source', + ), + 'CopySourceIfMatch' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-if-match', + ), + 'CopySourceIfModifiedSince' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time-http', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-if-modified-since', + ), + 'CopySourceIfNoneMatch' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-if-none-match', + ), + 'CopySourceIfUnmodifiedSince' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time-http', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-if-unmodified-since', + ), + 'Expires' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time-http', + 'location' => 'header', + ), + 'GrantFullControl' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-grant-full-control', + ), + 'GrantRead' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-grant-read', + ), + 'GrantReadACP' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-grant-read-acp', + ), + 'GrantWriteACP' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-grant-write-acp', + ), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + ), + 'Metadata' => array( + 'type' => 'object', + 'location' => 'header', + 'sentAs' => 'x-cos-meta-', + 'additionalProperties' => array( + 'type' => 'string', + ), + ), + 'MetadataDirective' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-metadata-directive', + ), + 'ServerSideEncryption' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption', + ), + 'StorageClass' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-storage-class', + ), + 'WebsiteRedirectLocation' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-website-redirect-location', + ), + 'SSECustomerAlgorithm' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-algorithm', + ), + 'SSECustomerKey' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-key', + ), + 'CopySourceSSECustomerAlgorithm' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-server-side-encryption-customer-algorithm', + ), + 'CopySourceSSECustomerKey' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-server-side-encryption-customer-key', + ), + 'CopySourceSSECustomerKeyMD5' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-server-side-encryption-customer-key-MD5', + ), + 'RequestPayer' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-payer', + ), + 'ACP' => array( + 'type' => 'object', + 'additionalProperties' => true, + ), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml', + ), + ), + 'errorResponses' => array( + array( + 'reason' => 'The source object of the COPY operation is not in the active tier and is only stored in Amazon Glacier.', + 'class' => 'ObjectNotInActiveTierErrorException', + ), + ), + ), 'DeleteBucket' => array( 'httpMethod' => 'DELETE', 'uri' => '/{Bucket}', @@ -84,6 +360,52 @@ public static function getService() { 'required' => true, 'type' => 'string', 'location' => 'uri'))), + 'DeleteBucketCors' => array( + 'httpMethod' => 'DELETE', + 'uri' => '/{Bucket}?cors', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'DeleteBucketCorsOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + ), + ), + 'DeleteObject' => array( + 'httpMethod' => 'DELETE', + 'uri' => '/{Bucket}{/Key*}', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'DeleteObjectOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri'), + 'Key' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')))), + 'DeleteBucketLifecycle' => array( + 'httpMethod' => 'DELETE', + 'uri' => '/{Bucket}?lifecycle', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'DeleteBucketLifecycleOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + ), + ), 'PutBucketAcl' => array( 'httpMethod' => 'PUT', 'uri' => '/{Bucket}?acl', @@ -92,12 +414,15 @@ public static function getService() { 'responseType' => 'model', 'data' => array( 'xmlRoot' => array( - 'name' => 'AccessControlPolicy')), + 'name' => 'AccessControlPolicy', + ), + ), 'parameters' => array( 'ACL' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-cos-acl'), + 'sentAs' => 'x-cos-acl', + ), 'Grants' => array( 'type' => 'array', 'location' => 'xml', @@ -110,64 +435,82 @@ public static function getService() { 'type' => 'object', 'properties' => array( 'DisplayName' => array( - 'type' => 'string'), + 'type' => 'string', + ), 'EmailAddress' => array( - 'type' => 'string'), + 'type' => 'string', + ), 'ID' => array( - 'type' => 'string'), + 'type' => 'string', + ), + 'Type' => array( + 'required' => true, + 'type' => 'string', + 'sentAs' => 'xsi:type', + 'data' => array( + 'xmlAttribute' => true, + 'xmlNamespace' => 'http://www.w3.org/2001/XMLSchema-instance', + ), + ), 'URI' => array( - 'type' => 'string'))), + 'type' => 'string', + ), + ), + ), 'Permission' => array( - 'type' => 'string')))), + 'type' => 'string', + ), + ), + ), + ), 'Owner' => array( 'type' => 'object', 'location' => 'xml', 'properties' => array( 'DisplayName' => array( - 'type' => 'string'), + 'type' => 'string', + ), 'ID' => array( - 'type' => 'string'))), + 'type' => 'string', + ), + ), + ), 'Bucket' => array( 'required' => true, 'type' => 'string', - 'location' => 'uri'), + 'location' => 'uri', + ), 'GrantFullControl' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-cos-grant-full-control'), + 'sentAs' => 'x-cos-grant-full-control', + ), 'GrantRead' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-cos-grant-read'), + 'sentAs' => 'x-cos-grant-read', + ), 'GrantReadACP' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-cos-grant-read-acp'), + 'sentAs' => 'x-cos-grant-read-acp', + ), 'GrantWrite' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-cos-grant-write'), + 'sentAs' => 'x-cos-grant-write', + ), 'GrantWriteACP' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-cos-grant-write-acp'), + 'sentAs' => 'x-cos-grant-write-acp', + ), 'ACP' => array( 'type' => 'object', - 'additionalProperties' => true))), - 'GetBucketAcl' => array( - 'httpMethod' => 'GET', - 'uri' => '/{Bucket}?acl', - 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'GetBucketAclOutput', - 'responseType' => 'model', - 'parameters' => array( - 'Bucket' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'uri'), - 'command.expects' => array( - 'static' => true, - 'default' => 'application/xml'))), + 'additionalProperties' => true, + ), + ), + ), 'GetObject' => array( 'httpMethod' => 'GET', 'uri' => '/{Bucket}{/Key*}', @@ -243,71 +586,146 @@ public static function getService() { 'sentAs' => 'response-expires'), 'SaveAs' => array( 'location' => 'response_body')), - 'errorResponses' => array( - array( - 'reason' => 'The specified key does not exist.', - 'class' => 'NoSuchKeyException'))), - 'CompleteMultipartUpload' => array( - 'httpMethod' => 'POST', - 'uri' => '/{Bucket}{/Key*}', + 'errorResponses' => array( + array( + 'reason' => 'The specified key does not exist.', + 'class' => 'NoSuchKeyException'))), + 'GetObjectAcl' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}{/Key*}?acl', 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'CompleteMultipartUploadOutput', + 'responseClass' => 'GetObjectAclOutput', 'responseType' => 'model', - 'data' => array( - 'xmlRoot' => array( - 'name' => 'CompleteMultipartUpload')), 'parameters' => array( 'Bucket' => array( 'required' => true, 'type' => 'string', - 'location' => 'uri'), + 'location' => 'uri', + ), 'Key' => array( 'required' => true, 'type' => 'string', 'location' => 'uri', 'minLength' => 1, - 'filters' => array( - 'Qcloud\\Cos\\Client::explodeKey')), - 'Parts' => array( - 'type' => 'array', - 'location' => 'xml', - 'data' => array( - 'xmlFlattened' => true), - 'items' => array( - 'name' => 'CompletedPart', - 'type' => 'object', - 'sentAs' => 'Part', - 'properties' => array( - 'ETag' => array( - 'type' => 'string'), - 'PartNumber' => array( - 'type' => 'numeric')))), - 'UploadId' => array( - 'required' => true, + ), + 'VersionId' => array( 'type' => 'string', 'location' => 'query', - 'sentAs' => 'uploadId'), + 'sentAs' => 'versionId', + ), + 'RequestPayer' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-payer', + ), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml', + ), + ), + 'errorResponses' => array( + array( + 'reason' => 'The specified key does not exist.', + 'class' => 'NoSuchKeyException', + ), + ), + ), + 'GetBucketAcl' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}?acl', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'GetBucketAclOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri'), 'command.expects' => array( 'static' => true, 'default' => 'application/xml'))), - 'DeleteObject' => array( - 'httpMethod' => 'DELETE', + 'GetBucketCors' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}?cors', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'GetBucketCorsOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml', + ), + ), + ), + 'GetBucketLifecycle' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}?lifecycle', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'GetBucketLifecycleOutput', + 'responseType' => 'model', + 'parameters' => array( + 'Bucket' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'uri', + ), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml', + ), + ), + ), + 'UploadPart' => array( + 'httpMethod' => 'PUT', 'uri' => '/{Bucket}{/Key*}', 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'DeleteObjectOutput', + 'responseClass' => 'UploadPartOutput', 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'UploadPartRequest')), 'parameters' => array( + 'Body' => array( + 'type' => array( + 'string', + 'object'), + 'location' => 'body'), 'Bucket' => array( 'required' => true, 'type' => 'string', 'location' => 'uri'), + 'ContentLength' => array( + 'type' => 'numeric', + 'location' => 'header', + 'sentAs' => 'Content-Length'), + 'ContentMD5' => array( + 'type' => array( + 'string', + 'boolean'), + 'location' => 'header', + 'sentAs' => 'Content-MD5'), 'Key' => array( 'required' => true, 'type' => 'string', 'location' => 'uri', 'minLength' => 1, 'filters' => array( - 'Qcloud\\Cos\\Client::explodeKey')))), + 'Qcloud\\Cos\\Client::explodeKey')), + 'PartNumber' => array( + 'required' => true, + 'type' => 'numeric', + 'location' => 'query', + 'sentAs' => 'partNumber'), + 'UploadId' => array( + 'required' => true, + 'type' => 'string', + 'location' => 'query', + 'sentAs' => 'uploadId'))), 'PutObject' => array( 'httpMethod' => 'PUT', 'uri' => '/{Bucket}{/Key*}', @@ -400,22 +818,16 @@ public static function getService() { 'properties' => array( 'DisplayName' => array( 'type' => 'string'), - /* - 'EmailAddress' => array( - 'type' => 'string'), - */ 'ID' => array( 'type' => 'string'), - /* 'Type' => array( 'type' => 'string', 'sentAs' => 'xsi:type', 'data' => array( 'xmlAttribute' => true, 'xmlNamespace' => 'http://www.w3.org/2001/XMLSchema-instance')), - */ - /*'URI' => array( - 'type' => 'string') */)), + 'URI' => array( + 'type' => 'string') )), 'Permission' => array( 'type' => 'string', ), @@ -469,10 +881,6 @@ public static function getService() { 'type' => 'string', 'location' => 'uri', 'minLength' => 1, - #!!!!!!!!!!!!! -// 'filters' => array( -// 'Aws\\S3\\S3Client::explodeKey', -// ), ), 'RequestPayer' => array( 'type' => 'string', @@ -491,100 +899,230 @@ public static function getService() { ), ), ), - 'GetObjectAcl' => array( - 'httpMethod' => 'GET', - 'uri' => '/{Bucket}{/Key*}?acl', + 'PutBucketCors' => array( + 'httpMethod' => 'PUT', + 'uri' => '/{Bucket}?cors', 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'GetObjectAclOutput', + 'responseClass' => 'PutBucketCorsOutput', 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'CORSConfiguration', + ), + 'contentMd5' => true, + ), 'parameters' => array( 'Bucket' => array( 'required' => true, 'type' => 'string', 'location' => 'uri', ), - 'Key' => array( + 'CORSRules' => array( 'required' => true, - 'type' => 'string', - 'location' => 'uri', - 'minLength' => 1, + 'type' => 'array', + 'location' => 'xml', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'CORSRule', + 'type' => 'object', + 'sentAs' => 'CORSRule', + 'properties' => array( + 'AllowedHeaders' => array( + 'type' => 'array', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'AllowedHeader', + 'type' => 'string', + 'sentAs' => 'AllowedHeader', + ), + ), + 'AllowedMethods' => array( + 'required' => true, + 'type' => 'array', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'AllowedMethod', + 'type' => 'string', + 'sentAs' => 'AllowedMethod', + ), + ), + 'AllowedOrigins' => array( + 'required' => true, + 'type' => 'array', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'AllowedOrigin', + 'type' => 'string', + 'sentAs' => 'AllowedOrigin', + ), + ), + 'ExposeHeaders' => array( + 'type' => 'array', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'ExposeHeader', + 'type' => 'string', + 'sentAs' => 'ExposeHeader', + ), + ), + 'MaxAgeSeconds' => array( + 'type' => 'numeric', + ), + ), + ), ), - 'VersionId' => array( - 'type' => 'string', - 'location' => 'query', - 'sentAs' => 'versionId', + ), + ), + 'PutBucketLifecycle' => array( + 'httpMethod' => 'PUT', + 'uri' => '/{Bucket}?lifecycle', + 'class' => 'Qcloud\\Cos\\Command', + 'responseClass' => 'PutBucketLifecycleOutput', + 'responseType' => 'model', + 'data' => array( + 'xmlRoot' => array( + 'name' => 'LifecycleConfiguration', ), - 'RequestPayer' => array( + 'contentMd5' => true, + ), + 'parameters' => array( + 'Bucket' => array( + 'required' => true, 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'x-cos-request-payer', - ), - 'command.expects' => array( - 'static' => true, - 'default' => 'application/xml', + 'location' => 'uri', ), - ), - 'errorResponses' => array( - array( - 'reason' => 'The specified key does not exist.', - 'class' => 'NoSuchKeyException', + 'Rules' => array( + 'required' => true, + 'type' => 'array', + 'location' => 'xml', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'Rule', + 'type' => 'object', + 'sentAs' => 'Rule', + 'properties' => array( + 'Expiration' => array( + 'type' => 'object', + 'properties' => array( + 'Date' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time', + ), + 'Days' => array( + 'type' => 'numeric', + ), + ), + ), + 'ID' => array( + 'type' => 'string', + ), + 'Filter' => array( + 'type' => 'object', + 'require' => true, + 'properties' => array( + 'Prefix' => array( + 'type' => 'string', + 'require' => true, + ), + ), + ), + 'Status' => array( + 'required' => true, + 'type' => 'string', + ), + 'Transition' => array( + 'type' => 'object', + 'properties' => array( + 'Date' => array( + 'type' => array( + 'object', + 'string', + 'integer', + ), + 'format' => 'date-time', + ), + 'Days' => array( + 'type' => 'numeric', + ), + 'StorageClass' => array( + 'type' => 'string', + ), + ), + ), + 'NoncurrentVersionTransition' => array( + 'type' => 'object', + 'properties' => array( + 'NoncurrentDays' => array( + 'type' => 'numeric', + ), + 'StorageClass' => array( + 'type' => 'string', + ), + ), + ), + 'NoncurrentVersionExpiration' => array( + 'type' => 'object', + 'properties' => array( + 'NoncurrentDays' => array( + 'type' => 'numeric', + ), + ), + ), + ), + ), ), ), ), - 'CreateMultipartUpload' => array( - 'httpMethod' => 'POST', - 'uri' => '/{Bucket}{/Key*}?uploads', + 'ListParts' => array( + 'httpMethod' => 'GET', + 'uri' => '/{Bucket}{/Key*}', 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'CreateMultipartUploadOutput', + 'responseClass' => 'ListPartsOutput', 'responseType' => 'model', - 'data' => array( - 'xmlRoot' => array( - 'name' => 'CreateMultipartUploadRequest')), 'parameters' => array( - 'ACL' => array( - 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'x-cos-acl'), 'Bucket' => array( 'required' => true, 'type' => 'string', 'location' => 'uri'), - 'CacheControl' => array( + 'Key' => array( + 'required' => true, 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'Cache-Control'), - 'ContentDisposition' => array( + 'location' => 'uri', + 'minLength' => 1, + 'filters' => array( + 'Qcloud\\Cos\\Client::explodeKey')), + 'MaxParts' => array( + 'type' => 'numeric', + 'location' => 'query', + 'sentAs' => 'max-parts'), + 'PartNumberMarker' => array( + 'type' => 'numeric', + 'location' => 'query', + 'sentAs' => 'part-number-marker'), + 'UploadId' => array( + 'required' => true, 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'Content-Disposition'), - 'ContentEncoding' => array( - 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'Content-Encoding'), - 'ContentLanguage' => array( - 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'Content-Language'), - 'ContentType' => array( - 'type' => 'string', - 'location' => 'header', - 'sentAs' => 'Content-Type'), - 'Key' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'uri', - 'minLength' => 1, - 'filters' => array( - 'Qcloud\\Cos\\Client::explodeKey')), - 'Metadata' => array( - 'type' => 'object', - 'location' => 'header', - 'sentAs' => 'x-cos-meta-', - 'additionalProperties' => array( - 'type' => 'string')), + 'location' => 'query', + 'sentAs' => 'uploadId'), 'command.expects' => array( - 'static' => true, - 'default' => 'application/xml'))), + 'static' => true, + 'default' => 'application/xml'))), 'ListObjects' => array( 'httpMethod' => 'GET', 'uri' => '/{Bucket}', @@ -623,86 +1161,19 @@ public static function getService() { array( 'reason' => 'The specified bucket does not exist.', 'class' => 'NoSuchBucketException'))), - 'ListParts' => array( + 'ListBuckets' => array( 'httpMethod' => 'GET', - 'uri' => '/{Bucket}{/Key*}', - 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'ListPartsOutput', - 'responseType' => 'model', - 'parameters' => array( - 'Bucket' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'uri'), - 'Key' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'uri', - 'minLength' => 1, - 'filters' => array( - 'Qcloud\\Cos\\Client::explodeKey')), - 'MaxParts' => array( - 'type' => 'numeric', - 'location' => 'query', - 'sentAs' => 'max-parts'), - 'PartNumberMarker' => array( - 'type' => 'numeric', - 'location' => 'query', - 'sentAs' => 'part-number-marker'), - 'UploadId' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'query', - 'sentAs' => 'uploadId'), - 'command.expects' => array( - 'static' => true, - 'default' => 'application/xml'))), - 'UploadPart' => array( - 'httpMethod' => 'PUT', - 'uri' => '/{Bucket}{/Key*}', + 'uri' => '/', 'class' => 'Qcloud\\Cos\\Command', - 'responseClass' => 'UploadPartOutput', + 'responseClass' => 'ListBucketsOutput', 'responseType' => 'model', - 'data' => array( - 'xmlRoot' => array( - 'name' => 'UploadPartRequest')), 'parameters' => array( - 'Body' => array( - 'type' => array( - 'string', - 'object'), - 'location' => 'body'), - 'Bucket' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'uri'), - 'ContentLength' => array( - 'type' => 'numeric', - 'location' => 'header', - 'sentAs' => 'Content-Length'), - 'ContentMD5' => array( - 'type' => array( - 'string', - 'boolean'), - 'location' => 'header', - 'sentAs' => 'Content-MD5'), - 'Key' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'uri', - 'minLength' => 1, - 'filters' => array( - 'Qcloud\\Cos\\Client::explodeKey')), - 'PartNumber' => array( - 'required' => true, - 'type' => 'numeric', - 'location' => 'query', - 'sentAs' => 'partNumber'), - 'UploadId' => array( - 'required' => true, - 'type' => 'string', - 'location' => 'query', - 'sentAs' => 'uploadId'))), + 'command.expects' => array( + 'static' => true, + 'default' => 'application/xml', + ), + ), + ), 'HeadObject' => array( 'httpMethod' => 'HEAD', 'uri' => '/{Bucket}{/Key*}', @@ -733,60 +1204,6 @@ public static function getService() { 'RequestId' => array( 'location' => 'header', 'sentAs' => 'x-cos-request-id'))), - 'PutBucketAclOutput' => array( - 'type' => 'object', - 'additionalProperties' => true, - 'properties' => array( - 'RequestId' => array( - 'location' => 'header', - 'sentAs' => 'x-cos-request-id'))), - 'GetBucketAclOutput' => array( - 'type' => 'object', - 'additionalProperties' => true, - 'properties' => array( - 'Owner' => array( - 'type' => 'object', - 'location' => 'xml', - 'properties' => array( - 'DisplayName' => array( - 'type' => 'string'), - 'ID' => array( - 'type' => 'string'))), - 'Grants' => array( - 'type' => 'array', - 'location' => 'xml', - 'sentAs' => 'AccessControlList', - 'items' => array( - 'name' => 'Grant', - 'type' => 'object', - 'sentAs' => 'Grant', - 'properties' => array( - 'Grantee' => array( - 'type' => 'object', - 'properties' => array( - 'DisplayName' => array( - 'type' => 'string'), - /* - 'EmailAddress' => array( - 'type' => 'string'), - */ - 'ID' => array( - 'type' => 'string'), - /* - 'Type' => array( - 'type' => 'string', - 'sentAs' => 'xsi:type', - 'data' => array( - 'xmlAttribute' => true, - 'xmlNamespace' => 'http://www.w3.org/2001/XMLSchema-instance')), - */ - /*'URI' => array( - 'type' => 'string') */)), - 'Permission' => array( - 'type' => 'string')))), - 'RequestId' => array( - 'location' => 'header', - 'sentAs' => 'x-cos-request-id'))), 'CreateBucketOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -833,6 +1250,54 @@ public static function getService() { 'RequestId' => array( 'location' => 'header', 'sentAs' => 'x-cos-request-id'))), + 'CopyObjectOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'ETag' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'LastModified' => array( + 'type' => 'string', + 'location' => 'xml', + ), + 'Expiration' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-expiration', + ), + 'CopySourceVersionId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-copy-source-version-id', + ), + 'VersionId' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-version-id', + ), + 'ServerSideEncryption' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption', + ), + 'SSECustomerAlgorithm' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-server-side-encryption-customer-algorithm', + ), + 'RequestCharged' => array( + 'type' => 'string', + 'location' => 'header', + 'sentAs' => 'x-cos-request-charged', + ), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'DeleteBucketOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -840,6 +1305,33 @@ public static function getService() { 'RequestId' => array( 'location' => 'header', 'sentAs' => 'x-cos-request-id'))), + 'DeleteBucketCorsOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), + 'DeleteObjectOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id'))), + 'DeleteBucketLifecycleOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'GetObjectOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -966,6 +1458,207 @@ public static function getService() { ), ), ), + 'GetBucketAclOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'Owner' => array( + 'type' => 'object', + 'location' => 'xml', + 'properties' => array( + 'DisplayName' => array( + 'type' => 'string'), + 'ID' => array( + 'type' => 'string'))), + 'Grants' => array( + 'type' => 'array', + 'location' => 'xml', + 'sentAs' => 'AccessControlList', + 'items' => array( + 'name' => 'Grant', + 'type' => 'object', + 'sentAs' => 'Grant', + 'properties' => array( + 'Grantee' => array( + 'type' => 'object', + 'properties' => array( + 'DisplayName' => array( + 'type' => 'string'), + /* + 'EmailAddress' => array( + 'type' => 'string'), + */ + 'ID' => array( + 'type' => 'string'), + /* + 'Type' => array( + 'type' => 'string', + 'sentAs' => 'xsi:type', + 'data' => array( + 'xmlAttribute' => true, + 'xmlNamespace' => 'http://www.w3.org/2001/XMLSchema-instance')), + */ + /*'URI' => array( + 'type' => 'string') */)), + 'Permission' => array( + 'type' => 'string')))), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id'))), + 'GetBucketCorsOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'CORSRules' => array( + 'type' => 'array', + 'location' => 'xml', + 'sentAs' => 'CORSRule', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'CORSRule', + 'type' => 'object', + 'sentAs' => 'CORSRule', + 'properties' => array( + 'AllowedHeaders' => array( + 'type' => 'array', + 'sentAs' => 'AllowedHeader', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'AllowedHeader', + 'type' => 'string', + 'sentAs' => 'AllowedHeader', + ), + ), + 'AllowedMethods' => array( + 'type' => 'array', + 'sentAs' => 'AllowedMethod', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'AllowedMethod', + 'type' => 'string', + 'sentAs' => 'AllowedMethod', + ), + ), + 'AllowedOrigins' => array( + 'type' => 'array', + 'sentAs' => 'AllowedOrigin', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'AllowedOrigin', + 'type' => 'string', + 'sentAs' => 'AllowedOrigin', + ), + ), + 'ExposeHeaders' => array( + 'type' => 'array', + 'sentAs' => 'ExposeHeader', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'ExposeHeader', + 'type' => 'string', + 'sentAs' => 'ExposeHeader', + ), + ), + 'MaxAgeSeconds' => array( + 'type' => 'numeric', + ), + ), + ), + ), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), + 'GetBucketLifecycleOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'Rules' => array( + 'type' => 'array', + 'location' => 'xml', + 'sentAs' => 'Rule', + 'data' => array( + 'xmlFlattened' => true, + ), + 'items' => array( + 'name' => 'Rule', + 'type' => 'object', + 'sentAs' => 'Rule', + 'properties' => array( + 'Expiration' => array( + 'type' => 'object', + 'properties' => array( + 'Date' => array( + 'type' => 'string', + ), + 'Days' => array( + 'type' => 'numeric', + ), + ), + ), + 'ID' => array( + 'type' => 'string', + ), + 'Prefix' => array( + 'type' => 'string', + ), + 'Status' => array( + 'type' => 'string', + ), + 'Transition' => array( + 'type' => 'object', + 'properties' => array( + 'Date' => array( + 'type' => 'string', + ), + 'Days' => array( + 'type' => 'numeric', + ), + 'StorageClass' => array( + 'type' => 'string', + ), + ), + ), + 'NoncurrentVersionTransition' => array( + 'type' => 'object', + 'properties' => array( + 'NoncurrentDays' => array( + 'type' => 'numeric', + ), + 'StorageClass' => array( + 'type' => 'string', + ), + ), + ), + 'NoncurrentVersionExpiration' => array( + 'type' => 'object', + 'properties' => array( + 'NoncurrentDays' => array( + 'type' => 'numeric', + ), + ), + ), + ), + ), + ), + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'UploadPartOutput' => array( 'type' => 'object', 'additionalProperties' => true, @@ -976,7 +1669,7 @@ public static function getService() { 'RequestId' => array( 'location' => 'header', 'sentAs' => 'x-cos-request-id'))), - 'DeleteObjectOutput' => array( + 'PutBucketAclOutput' => array( 'type' => 'object', 'additionalProperties' => true, 'properties' => array( @@ -1010,6 +1703,26 @@ public static function getService() { ), ), ), + 'PutBucketCorsOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), + 'PutBucketLifecycleOutput' => array( + 'type' => 'object', + 'additionalProperties' => true, + 'properties' => array( + 'RequestId' => array( + 'location' => 'header', + 'sentAs' => 'x-cos-request-id', + ), + ), + ), 'ListPartsOutput' => array( 'type' => 'object', 'additionalProperties' => true, diff --git a/src/Qcloud/Cos/SignatureListener.php b/src/Qcloud/Cos/SignatureListener.php index 8cbfb3fe..a9795835 100644 --- a/src/Qcloud/Cos/SignatureListener.php +++ b/src/Qcloud/Cos/SignatureListener.php @@ -2,8 +2,6 @@ namespace Qcloud\Cos; -use Aws\Common\Credentials\CredentialsInterface; -use Aws\Common\Credentials\NullCredentials; use Guzzle\Common\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/src/Qcloud/Cos/Tests/BucketTest.php b/src/Qcloud/Cos/Tests/BucketTest.php index f103a619..1b8591a2 100644 --- a/src/Qcloud/Cos/Tests/BucketTest.php +++ b/src/Qcloud/Cos/Tests/BucketTest.php @@ -5,48 +5,45 @@ use Qcloud\Cos\Client; use Qcloud\Cos\Exception\CosException; -class BucketTest extends \PHPUnit_Framework_TestCase { +class BucketTest extends \PHPUnit_Framework_TestCase +{ private $cosClient; - protected function setUp() { + protected function setUp() + { TestHelper::nuke('testbucket'); $this->cosClient = new Client(array('region' => getenv('COS_REGION'), - 'credentials'=> array( - 'appId' => getenv('COS_APPID'), - 'secretId' => getenv('COS_KEY'), - 'secretKey' => getenv('COS_SECRET')))); + 'credentials' => array( + 'appId' => getenv('COS_APPID'), + 'secretId' => getenv('COS_KEY'), + 'secretKey' => getenv('COS_SECRET')))); } - protected function tearDown() { + protected function tearDown() + { TestHelper::nuke('testbucket'); + sleep(2); } - public function testCreateBucket() { + public function testCreateBucket() + { try { $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); var_dump($result); + sleep(2); } catch (\Exception $e) { $this->assertFalse(true, $e); } } - public function testCreateAlreadyExistedBucket() { - try { - $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); - var_dump($result); - $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); - var_dump($result); - } catch (CosException $e) { - $this->assertTrue($e->getExceptionCode() === 'BucketAlreadyExists'); - $this->assertTrue($e->getStatusCode() === 409); - } - } - public function testDeleteBucket() { + public function testDeleteBucket() + { try { $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); var_dump($result); + sleep(2); $result = $this->cosClient->deleteBucket(array('Bucket' => 'testbucket')); var_dump($result); } catch (\Exception $e) { @@ -54,26 +51,280 @@ public function testDeleteBucket() { } } - public function testDeleteNonexistedBucket() { + public function testDeleteNonexistedBucket() + { try { $result = $this->cosClient->deleteBucket(array('Bucket' => 'testbucket')); var_dump($result); + sleep(2); } catch (CosException $e) { $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket'); $this->assertTrue($e->getStatusCode() === 404); } } - public function testDeleteNonemptyBucket() { + public function testDeleteNonemptyBucket() + { try { $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); - $this->cosClient->putObject(array( - 'Bucket' => 'testbucket', 'Key' => 'hello.txt', 'Body' => 'Hello World!')); - $this->cosClient->deleteBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putObject(array( + 'Bucket' => 'testbucket', 'Key' => 'hello.txt', 'Body' => 'Hello World!')); + $result = $this->cosClient->deleteBucket(array('Bucket' => 'testbucket')); } catch (CosException $e) { echo "$e\n"; + echo $e->getExceptionCode(); $this->assertTrue($e->getExceptionCode() === 'BucketNotEmpty'); $this->assertTrue($e->getStatusCode() === 409); } } -} + + public function testPutBucketACL() + { + try { + $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(5); + $this->cosClient->PutBucketAcl(array( + 'Bucket' => 'testbucket', + 'Grants' => array( + array( + 'Grantee' => array( + 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', + 'ID' => 'qcs::cam::uin/327874225:uin/327874225', + 'Type' => 'CanonicalUser', + ), + 'Permission' => 'FULL_CONTROL', + ), + // ... repeated + ), + 'Owner' => array( + 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', + 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', + ),)); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + + } + + public function testGetBucketACL() + { + try { + $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(5); + $this->cosClient->PutBucketAcl(array( + 'Bucket' => 'testbucket', + 'Grants' => array( + array( + 'Grantee' => array( + 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', + 'ID' => 'qcs::cam::uin/327874225:uin/327874225', + 'Type' => 'CanonicalUser', + ), + 'Permission' => 'FULL_CONTROL', + ), + // ... repeated + ), + 'Owner' => array( + 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', + 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', + ),)); + + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } + + public function testPutBucketLifecycle() + { + try { + $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putBucketLifecycle(array( + // Bucket is required + 'Bucket' => 'testbucket', + // Rules is required + 'Rules' => array( + array( + 'Expiration' => array( + 'Days' => 1, + ), + 'ID' => 'id1', + 'Filter' => array( + 'Prefix' => 'documents/' + ), + // Status is required + 'Status' => 'Enabled', + 'Transition' => array( + 'Days' => 100, + 'StorageClass' => 'NEARLINE', + ), + // ... repeated + ), + ))); + var_dump($result); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } + + public function testGetBucketLifecycle() + { + try { + $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putBucketLifecycle(array( + // Bucket is required + 'Bucket' => 'testbucket', + // Rules is required + 'Rules' => array( + array( + 'Expiration' => array( + 'Days' => 1, + ), + 'ID' => 'id1', + 'Filter' => array( + 'Prefix' => 'documents/' + ), + // Status is required + 'Status' => 'Enabled', + 'Transition' => array( + 'Days' => 100, + 'StorageClass' => 'NEARLINE', + ), + // ... repeated + ), + ))); + sleep(5); + $result = $this->cosClient->getBucketLifecycle(array( + // Bucket is required + 'Bucket' => 'testbucket', + )); + var_dump($result); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } + + public function testDeleteBucketLifecycle() + { + try { + $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putBucketLifecycle(array( + // Bucket is required + 'Bucket' => 'testbucket', + // Rules is required + 'Rules' => array( + array( + 'Expiration' => array( + 'Days' => 1, + ), + 'ID' => 'id1', + 'Filter' => array( + 'Prefix' => 'documents/' + ), + // Status is required + 'Status' => 'Enabled', + 'Transition' => array( + 'Days' => 100, + 'StorageClass' => 'NEARLINE', + ), + // ... repeated + ), + ))); + sleep(5); + $result = $this->cosClient->deleteBucketLifecycle(array( + // Bucket is required + 'Bucket' => 'testbucket', + )); + var_dump($result); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } + + public function testPutBucketCors() + { + try { + $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putBucketCors(array( + // Bucket is required + 'Bucket' => 'testbucket', + // CORSRules is required + 'CORSRules' => array( + array( + 'AllowedHeaders' => array('*',), + // AllowedMethods is required + 'AllowedMethods' => array('Put',), + // AllowedOrigins is required + 'AllowedOrigins' => array('*',), + 'ExposeHeaders' => array('*',), + 'MaxAgeSeconds' => 1, + ), + // ... repeated + ), + )); + var_dump($result); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } + public function testGetBucketCors() { + try { + $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putBucketCors(array( + // Bucket is required + 'Bucket' => 'testbucket', + // CORSRules is required + 'CORSRules' => array( + array( + 'AllowedHeaders' => array('*',), + // AllowedMethods is required + 'AllowedMethods' => array('Put', ), + // AllowedOrigins is required + 'AllowedOrigins' => array('*', ), + 'ExposeHeaders' => array('*', ), + 'MaxAgeSeconds' => 1, + ), + // ... repeated + ), + )); + $result = $this->cosClient->getBucketCors(array( + 'Bucket' => 'testbucket', + )); + var_dump($result); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + }} + public function testDeleteBucketCors() { + try { + $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); + $result = $this->cosClient->putBucketCors(array( + // Bucket is required + 'Bucket' => 'testbucket', + // CORSRules is required + 'CORSRules' => array( + array( + 'AllowedHeaders' => array('*',), + // AllowedMethods is required + 'AllowedMethods' => array('Put', ), + // AllowedOrigins is required + 'AllowedOrigins' => array('*', ), + 'ExposeHeaders' => array('*', ), + 'MaxAgeSeconds' => 1, + ), + // ... repeated + ), + )); + $result = $this->cosClient->deleteBucketCors(array( + 'Bucket' => 'testbucket', + )); + var_dump($result); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + }} +} \ No newline at end of file diff --git a/src/Qcloud/Cos/Tests/ObjectTest.php b/src/Qcloud/Cos/Tests/ObjectTest.php index a055eae4..f1c73537 100644 --- a/src/Qcloud/Cos/Tests/ObjectTest.php +++ b/src/Qcloud/Cos/Tests/ObjectTest.php @@ -22,11 +22,13 @@ protected function setUp() { protected function tearDown() { TestHelper::nuke('testbucket'); + sleep(2); } public function testPutObject() { try { $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(2); $this->cosClient->putObject(array( 'Bucket' => 'testbucket', 'Key' => 'hello.txt', 'Body' => 'Hello World')); } catch (\Exception $e) { @@ -37,7 +39,7 @@ public function testPutObject() { public function testPutObjectIntoNonexistedBucket() { try { $this->cosClient->putObject(array( - 'Bucket' => '000testbucket', 'Key' => 'hello.txt', 'Body' => 'Hello World')); + 'Bucket' => 'testbucket', 'Key' => 'hello.txt', 'Body' => 'Hello World')); } catch (CosException $e) { $this->assertTrue($e->getExceptionCode() === 'NoSuchBucket'); $this->assertTrue($e->getStatusCode() === 404); @@ -48,6 +50,7 @@ public function testUploadSmallObject() { try { $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); var_dump($result); + sleep(2); $this->cosClient->upload('testbucket', '你好.txt', 'Hello World'); } catch (\Exception $e) { $this->assertFalse(true, $e); @@ -58,6 +61,7 @@ public function testUploadComplexObject() { try { $result = $this->cosClient->createBucket(array('Bucket' => 'testbucket')); var_dump($result); + sleep(2); $this->cosClient->upload('testbucket', '→↓←→↖↗↙↘! \"#$%&\'()*+,-./0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~', 'Hello World'); } catch (\Exception $e) { $this->assertFalse(true, $e); @@ -67,12 +71,26 @@ public function testUploadComplexObject() { public function testUploadLargeObject() { try { $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(5); $this->cosClient->upload('testbucket', 'hello.txt', str_repeat('a', 20 * 1024 * 1024)); } catch (\Exception $e) { $this->assertFalse(true, $e); } } + public function testGetObject() { + try { + $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(5); + $this->cosClient->upload('testbucket', '你好.txt', 'Hello World'); + $this->cosClient->getObject(array( + 'Bucket' => 'testbucket', + 'Key' => '你好.txt',)); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } + public function testGetObjectUrl() { try{ $this->cosClient->createBucket(array('Bucket' => 'testbucket')); @@ -81,4 +99,62 @@ public function testGetObjectUrl() { $this->assertFalse(true, $e); } } -} \ No newline at end of file + + public function testPutObjectACL() { + try { + $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(5); + $this->cosClient->upload('testbucket', '11', 'hello.txt'); + $this->cosClient->PutObjectAcl(array( + 'Bucket' => 'testbucket', + 'Key' => '11', + 'Grants' => array( + array( + 'Grantee' => array( + 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', + 'ID' => 'qcs::cam::uin/327874225:uin/327874225', + 'Type' => 'CanonicalUser', + ), + 'Permission' => 'FULL_CONTROL', + ), + // ... repeated + ), + 'Owner' => array( + 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', + 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', + ),)); + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + + } + public function testGetObjectACL() + { + try { + $this->cosClient->createBucket(array('Bucket' => 'testbucket')); + sleep(5); + $this->cosClient->upload('testbucket', '11', 'hello.txt'); + $this->cosClient->PutObjectAcl(array( + 'Bucket' => 'testbucket', + 'Key' => '11', + 'Grants' => array( + array( + 'Grantee' => array( + 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225', + 'ID' => 'qcs::cam::uin/327874225:uin/327874225', + 'Type' => 'CanonicalUser', + ), + 'Permission' => 'FULL_CONTROL', + ), + // ... repeated + ), + 'Owner' => array( + 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098', + 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098', + ),)); + + } catch (\Exception $e) { + $this->assertFalse(true, $e); + } + } +}