Skip to content

Commit 51cb55f

Browse files
authored
add bucket tags api
1 parent 41add81 commit 51cb55f

14 files changed

+758
-0
lines changed

sample/DeleteBucketTags.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
use AlibabaCloud\Oss\V2 as Oss;
6+
7+
// parse args
8+
$optsdesc = [
9+
"region" => ['help' => 'The region in which the bucket is located.', 'required' => True],
10+
"endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False],
11+
"bucket" => ['help' => 'The name of the bucket', 'required' => True],
12+
];
13+
$longopts = \array_map(function ($key) {
14+
return "$key:";
15+
}, array_keys($optsdesc));
16+
$options = getopt("", $longopts);
17+
foreach ($optsdesc as $key => $value) {
18+
if ($value['required'] === True && empty($options[$key])) {
19+
$help = $value['help'];
20+
echo "Error: the following arguments are required: --$key, $help";
21+
exit(1);
22+
}
23+
}
24+
25+
$region = $options["region"];
26+
$bucket = $options["bucket"];
27+
28+
// Loading credentials values from the environment variables
29+
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
30+
31+
// Using the SDK's default configuration
32+
$cfg = Oss\Config::loadDefault();
33+
$cfg->setCredentialsProvider($credentialsProvider);
34+
$cfg->setRegion($region);
35+
if (isset($options["endpoint"])) {
36+
$cfg->setEndpoint($options["endpoint"]);
37+
}
38+
39+
$client = new Oss\Client($cfg);
40+
$request = new Oss\Models\DeleteBucketTagsRequest($bucket);
41+
$result = $client->deleteBucketTags($request);
42+
43+
printf(
44+
'status code:' . $result->statusCode . PHP_EOL .
45+
'request id:' . $result->requestId
46+
);
47+

sample/GetBucketTags.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
use AlibabaCloud\Oss\V2 as Oss;
6+
7+
// parse args
8+
$optsdesc = [
9+
"region" => ['help' => 'The region in which the bucket is located.', 'required' => True],
10+
"endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False],
11+
"bucket" => ['help' => 'The name of the bucket', 'required' => True],
12+
];
13+
$longopts = \array_map(function ($key) {
14+
return "$key:";
15+
}, array_keys($optsdesc));
16+
$options = getopt("", $longopts);
17+
foreach ($optsdesc as $key => $value) {
18+
if ($value['required'] === True && empty($options[$key])) {
19+
$help = $value['help'];
20+
echo "Error: the following arguments are required: --$key, $help";
21+
exit(1);
22+
}
23+
}
24+
25+
$region = $options["region"];
26+
$bucket = $options["bucket"];
27+
28+
// Loading credentials values from the environment variables
29+
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
30+
31+
// Using the SDK's default configuration
32+
$cfg = Oss\Config::loadDefault();
33+
$cfg->setCredentialsProvider($credentialsProvider);
34+
$cfg->setRegion($region);
35+
if (isset($options["endpoint"])) {
36+
$cfg->setEndpoint($options["endpoint"]);
37+
}
38+
39+
$client = new Oss\Client($cfg);
40+
$request = new Oss\Models\GetBucketTagsRequest($bucket);
41+
$result = $client->getBucketTags($request);
42+
43+
printf(
44+
'status code:' . $result->statusCode . PHP_EOL .
45+
'request id:' . $result->requestId . PHP_EOL .
46+
'tags:' . var_export($result->tagging, true)
47+
);
48+

sample/PutBucketTags.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';
4+
5+
use AlibabaCloud\Oss\V2 as Oss;
6+
7+
// parse args
8+
$optsdesc = [
9+
"region" => ['help' => 'The region in which the bucket is located.', 'required' => True],
10+
"endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False],
11+
"bucket" => ['help' => 'The name of the bucket', 'required' => True],
12+
];
13+
$longopts = \array_map(function ($key) {
14+
return "$key:";
15+
}, array_keys($optsdesc));
16+
$options = getopt("", $longopts);
17+
foreach ($optsdesc as $key => $value) {
18+
if ($value['required'] === True && empty($options[$key])) {
19+
$help = $value['help'];
20+
echo "Error: the following arguments are required: --$key, $help";
21+
exit(1);
22+
}
23+
}
24+
25+
$region = $options["region"];
26+
$bucket = $options["bucket"];
27+
28+
// Loading credentials values from the environment variables
29+
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
30+
31+
// Using the SDK's default configuration
32+
$cfg = Oss\Config::loadDefault();
33+
$cfg->setCredentialsProvider($credentialsProvider);
34+
$cfg->setRegion($region);
35+
if (isset($options["endpoint"])) {
36+
$cfg->setEndpoint($options["endpoint"]);
37+
}
38+
39+
$client = new Oss\Client($cfg);
40+
$request = new Oss\Models\PutBucketTagsRequest($bucket, tagging: new Oss\Models\Tagging(
41+
tagSet: new Oss\Models\TagSet(
42+
[new Oss\Models\Tag(key: 'key1', value: 'value1'), new Oss\Models\Tag(key: 'key2', value: 'value2')])
43+
)
44+
);
45+
$result = $client->putBucketTags($request);
46+
47+
printf(
48+
'status code:' . $result->statusCode . PHP_EOL .
49+
'request id:' . $result->requestId
50+
);

src/Client.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@
120120
* @method \GuzzleHttp\Promise\Promise putBucketTransferAccelerationAsync(Models\PutBucketTransferAccelerationRequest $request, array $args = []) Configures transfer acceleration for a bucket. After you enable transfer acceleration for a bucket, the object access speed is accelerated for users worldwide. The transfer acceleration feature is applicable to scenarios where data needs to be transferred over long geographical distances. This feature can also be used to download or upload objects that are gigabytes or terabytes in size.
121121
* @method Models\GetBucketTransferAccelerationResult getBucketTransferAcceleration(Models\GetBucketTransferAccelerationRequest $request, array $args = []) Queries the transfer acceleration configurations of a bucket.
122122
* @method \GuzzleHttp\Promise\Promise getBucketTransferAccelerationAsync(Models\GetBucketTransferAccelerationRequest $request, array $args = []) Queries the transfer acceleration configurations of a bucket.
123+
* @method Models\PutBucketTagsResult putBucketTags(Models\PutBucketTagsRequest $request, array $args = []) Adds tags to or modifies the existing tags of a bucket.
124+
* @method \GuzzleHttp\Promise\Promise putBucketTagsAsync(Models\PutBucketTagsRequest $request, array $args = []) Adds tags to or modifies the existing tags of a bucket.
125+
* @method Models\GetBucketTagsResult getBucketTags(Models\GetBucketTagsRequest $request, array $args = []) Queries the tags of a bucket.
126+
* @method \GuzzleHttp\Promise\Promise getBucketTagsAsync(Models\GetBucketTagsRequest $request, array $args = []) Queries the tags of a bucket.
127+
* @method Models\DeleteBucketTagsResult deleteBucketTags(Models\DeleteBucketTagsRequest $request, array $args = []) Deletes tags configured for a bucket.
128+
* @method \GuzzleHttp\Promise\Promise deleteBucketTagsAsync(Models\DeleteBucketTagsRequest $request, array $args = []) Deletes tags configured for a bucket.
123129
* @method Models\PutBucketRefererResult putBucketReferer(Models\PutBucketRefererRequest $request, array $args = []) Configures a Referer whitelist for an Object Storage Service (OSS) bucket. You can specify whether to allow the requests whose Referer field is empty or whose query strings are truncated.
124130
* @method \GuzzleHttp\Promise\Promise putBucketRefererAsync(Models\PutBucketRefererRequest $request, array $args = []) Configures a Referer whitelist for an Object Storage Service (OSS) bucket. You can specify whether to allow the requests whose Referer field is empty or whose query strings are truncated.
125131
* @method Models\GetBucketRefererResult getBucketReferer(Models\GetBucketRefererRequest $request, array $args = []) Queries the hotlink protection configurations for a bucket.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace AlibabaCloud\Oss\V2\Models;
5+
6+
use AlibabaCloud\Oss\V2\Types\RequestModel;
7+
use AlibabaCloud\Oss\V2\Annotation\TagProperty;
8+
use AlibabaCloud\Oss\V2\Annotation\RequiredProperty;
9+
10+
/**
11+
* The request for the DeleteBucketTags operation.
12+
* Class DeleteBucketTagsRequest
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
final class DeleteBucketTagsRequest extends RequestModel
16+
{
17+
/**
18+
* The name of the bucket.
19+
* @var string|null
20+
*/
21+
#[RequiredProperty()]
22+
#[TagProperty(tag: '', position: 'host', rename: 'bucket', type: 'string')]
23+
public ?string $bucket;
24+
25+
/**
26+
* @var string|null
27+
*/
28+
#[TagProperty(tag: '', position: 'query', rename: 'tagging', type: 'string')]
29+
public ?string $tagging;
30+
31+
/**
32+
* DeleteBucketTagsRequest constructor.
33+
* @param string|null $bucket The name of the bucket.
34+
* @param string|null $tagging
35+
* @param array|null $options
36+
*/
37+
public function __construct(
38+
?string $bucket = null,
39+
?string $tagging = null,
40+
?array $options = null
41+
)
42+
{
43+
$this->bucket = $bucket;
44+
$this->tagging = $tagging;
45+
parent::__construct($options);
46+
}
47+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace AlibabaCloud\Oss\V2\Models;
5+
6+
use AlibabaCloud\Oss\V2\Types\ResultModel;
7+
8+
/**
9+
* The result for the DeleteBucketTags operation.
10+
* Class DeleteBucketTagsResult
11+
* @package AlibabaCloud\Oss\V2\Models
12+
*/
13+
final class DeleteBucketTagsResult extends ResultModel
14+
{
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace AlibabaCloud\Oss\V2\Models;
5+
6+
use AlibabaCloud\Oss\V2\Types\RequestModel;
7+
use AlibabaCloud\Oss\V2\Annotation\TagProperty;
8+
use AlibabaCloud\Oss\V2\Annotation\RequiredProperty;
9+
10+
/**
11+
* The request for the GetBucketTags operation.
12+
* Class GetBucketTagsRequest
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
final class GetBucketTagsRequest extends RequestModel
16+
{
17+
/**
18+
* The name of the bucket.
19+
* @var string|null
20+
*/
21+
#[RequiredProperty()]
22+
#[TagProperty(tag: '', position: 'host', rename: 'bucket', type: 'string')]
23+
public ?string $bucket;
24+
25+
/**
26+
* GetBucketTagsRequest constructor.
27+
* @param string|null $bucket The name of the bucket.
28+
* @param array|null $options
29+
*/
30+
public function __construct(
31+
?string $bucket = null,
32+
?array $options = null
33+
)
34+
{
35+
$this->bucket = $bucket;
36+
parent::__construct($options);
37+
}
38+
}

src/Models/GetBucketTagsResult.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace AlibabaCloud\Oss\V2\Models;
5+
6+
use AlibabaCloud\Oss\V2\Types\ResultModel;
7+
use AlibabaCloud\Oss\V2\Annotation\TagBody;
8+
9+
/**
10+
* The result for the GetBucketTags operation.
11+
* Class GetBucketTagsResult
12+
* @package AlibabaCloud\Oss\V2\Models
13+
*/
14+
final class GetBucketTagsResult extends ResultModel
15+
{
16+
/**
17+
* The container that stores the returned tags of the bucket. If no tags are configured for the bucket, an XML message body is returned in which the Tagging element is empty.
18+
* @var Tagging|null
19+
*/
20+
#[TagBody(rename: 'Tagging', type: Tagging::class, format: 'xml')]
21+
public ?Tagging $tagging;
22+
23+
/**
24+
* GetBucketTagsRequest constructor.
25+
* @param Tagging|null $tagging The container that stores the returned tags of the bucket.
26+
*/
27+
public function __construct(
28+
?Tagging $tagging = null
29+
)
30+
{
31+
$this->tagging = $tagging;
32+
}
33+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace AlibabaCloud\Oss\V2\Models;
5+
6+
use AlibabaCloud\Oss\V2\Types\RequestModel;
7+
use AlibabaCloud\Oss\V2\Annotation\TagProperty;
8+
use AlibabaCloud\Oss\V2\Annotation\RequiredProperty;
9+
10+
/**
11+
* The request for the PutBucketTags operation.
12+
* Class PutBucketTagsRequest
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
final class PutBucketTagsRequest extends RequestModel
16+
{
17+
/**
18+
* The name of the bucket.
19+
* @var string|null
20+
*/
21+
#[RequiredProperty()]
22+
#[TagProperty(tag: '', position: 'host', rename: 'bucket', type: 'string')]
23+
public ?string $bucket;
24+
25+
/**
26+
* The request body schema.
27+
* @var Tagging|null
28+
*/
29+
#[RequiredProperty()]
30+
#[TagProperty(tag: '', position: 'body', rename: 'Tagging', type: 'xml')]
31+
public ?Tagging $tagging;
32+
33+
/**
34+
* PutBucketTagsRequest constructor.
35+
* @param string|null $bucket The name of the bucket.
36+
* @param Tagging|null $tagging The request body schema.
37+
* @param array|null $options
38+
*/
39+
public function __construct(
40+
?string $bucket = null,
41+
?Tagging $tagging = null,
42+
?array $options = null
43+
)
44+
{
45+
$this->bucket = $bucket;
46+
$this->tagging = $tagging;
47+
parent::__construct($options);
48+
}
49+
}

src/Models/PutBucketTagsResult.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace AlibabaCloud\Oss\V2\Models;
5+
6+
use AlibabaCloud\Oss\V2\Types\ResultModel;
7+
8+
/**
9+
* The result for the PutBucketTags operation.
10+
* Class PutBucketTagsResult
11+
* @package AlibabaCloud\Oss\V2\Models
12+
*/
13+
final class PutBucketTagsResult extends ResultModel
14+
{
15+
}

0 commit comments

Comments
 (0)