Skip to content

Commit 682b47c

Browse files
yangzong18huiguangjun
authored andcommitted
add bucket cname api
1 parent 6ef924f commit 682b47c

26 files changed

+1774
-0
lines changed

sample/CreateCnameToken.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\CreateCnameTokenRequest($bucket, new Oss\Models\BucketCnameConfiguration(
41+
new Oss\Models\Cname(
42+
'example.com'
43+
)
44+
));
45+
$result = $client->createCnameToken($request);
46+
47+
printf(
48+
'status code:' . $result->statusCode . PHP_EOL .
49+
'request id:' . $result->requestId . PHP_EOL .
50+
'cname token:' . var_export($result->cnameToken, true)
51+
);

sample/DeleteCname.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\DeleteCnameRequest($bucket, new Oss\Models\BucketCnameConfiguration(
41+
new Oss\Models\Cname(
42+
'example.com'
43+
)
44+
));
45+
$result = $client->deleteCname($request);
46+
47+
printf(
48+
'status code:' . $result->statusCode . PHP_EOL .
49+
'request id:' . $result->requestId
50+
);

sample/GetCnameToken.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\GetCnameTokenRequest($bucket, 'example.com');
41+
$result = $client->getCnameToken($request);
42+
43+
printf(
44+
'status code:' . $result->statusCode . PHP_EOL .
45+
'request id:' . $result->requestId . PHP_EOL .
46+
'cname token:' . var_export($result->cnameToken, true)
47+
);

sample/ListCname.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\ListCnameRequest($bucket);
41+
$result = $client->listCname($request);
42+
43+
printf(
44+
'status code:' . $result->statusCode . PHP_EOL .
45+
'request id:' . $result->requestId . PHP_EOL .
46+
'cnames:' . var_export($result->cnames, true)
47+
);

sample/PutCname.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\PutCnameRequest($bucket, new Oss\Models\BucketCnameConfiguration(
41+
new Oss\Models\Cname(
42+
'example.com'
43+
)
44+
));
45+
$result = $client->putCname($request);
46+
47+
printf(
48+
'status code:' . $result->statusCode . PHP_EOL .
49+
'request id:' . $result->requestId
50+
);

src/Client.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@
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\PutCnameResult putCname(Models\PutCnameRequest $request, array $args = []) Maps a CNAME record to a bucket.
124+
* @method \GuzzleHttp\Promise\Promise putCnameAsync(Models\PutCnameRequest $request, array $args = []) Maps a CNAME record to a bucket.
125+
* @method Models\ListCnameResult listCname(Models\ListCnameRequest $request, array $args = []) Queries all CNAME records that are mapped to a bucket.
126+
* @method \GuzzleHttp\Promise\Promise listCnameAsync(Models\ListCnameRequest $request, array $args = []) Queries all CNAME records that are mapped to a bucket.
127+
* @method Models\DeleteCnameResult deleteCname(Models\DeleteCnameRequest $request, array $args = []) Deletes a CNAME record that is mapped to a bucket.
128+
* @method \GuzzleHttp\Promise\Promise deleteCnameAsync(Models\DeleteCnameRequest $request, array $args = []) Deletes a CNAME record that is mapped to a bucket.
129+
* @method Models\GetCnameTokenResult getCnameToken(Models\GetCnameTokenRequest $request, array $args = []) Queries the created CNAME tokens.
130+
* @method \GuzzleHttp\Promise\Promise getCnameTokenAsync(Models\GetCnameTokenRequest $request, array $args = []) Queries the created CNAME tokens.
131+
* @method Models\CreateCnameTokenResult createCnameToken(Models\CreateCnameTokenRequest $request, array $args = []) Creates a CNAME token to verify the ownership of a domain name.
132+
* @method \GuzzleHttp\Promise\Promise createCnameTokenAsync(Models\CreateCnameTokenRequest $request, array $args = []) Creates a CNAME token to verify the ownership of a domain name.
123133
* @method Models\PutBucketCorsResult putBucketCors(Models\PutBucketCorsRequest $request, array $args = []) Configures cross-origin resource sharing (CORS) rules for a bucket.
124134
* @method \GuzzleHttp\Promise\Promise putBucketCorsAsync(Models\PutBucketCorsRequest $request, array $args = []) Configures cross-origin resource sharing (CORS) rules for a bucket.
125135
* @method Models\GetBucketCorsResult getBucketCors(Models\GetBucketCorsRequest $request, array $args = []) Queries the cross-origin resource sharing (CORS) rules that are configured for a bucket.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AlibabaCloud\Oss\V2\Models;
6+
7+
use AlibabaCloud\Oss\V2\Types\Model;
8+
use AlibabaCloud\Oss\V2\Annotation\XmlElement;
9+
use AlibabaCloud\Oss\V2\Annotation\XmlRoot;
10+
11+
/**
12+
* Class BucketCnameConfiguration
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
#[XmlRoot(name: 'BucketCnameConfiguration')]
16+
final class BucketCnameConfiguration extends Model
17+
{
18+
/**
19+
* The container that stores the CNAME information.
20+
* @var Cname|null
21+
*/
22+
#[XmlElement(rename: 'Cname', type: Cname::class)]
23+
public ?Cname $cname;
24+
25+
/**
26+
* BucketCnameConfiguration constructor.
27+
* @param Cname|null $cname The container that stores the CNAME information.
28+
*/
29+
public function __construct(
30+
?Cname $cname = null
31+
)
32+
{
33+
$this->cname = $cname;
34+
}
35+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AlibabaCloud\Oss\V2\Models;
6+
7+
use AlibabaCloud\Oss\V2\Types\Model;
8+
use AlibabaCloud\Oss\V2\Annotation\XmlElement;
9+
use AlibabaCloud\Oss\V2\Annotation\XmlRoot;
10+
11+
/**
12+
* Class CertificateConfiguration
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
#[XmlRoot(name: 'CertificateConfiguration')]
16+
final class CertificateConfiguration extends Model
17+
{
18+
/**
19+
* Specifies whether to overwrite the certificate. Valid values:- true: overwrites the certificate.- false: does not overwrite the certificate.
20+
* @var bool|null
21+
*/
22+
#[XmlElement(rename: 'Force', type: 'bool')]
23+
public ?bool $force;
24+
25+
/**
26+
* Specifies whether to delete the certificate. Valid values:- true: deletes the certificate.- false: does not delete the certificate.
27+
* @var bool|null
28+
*/
29+
#[XmlElement(rename: 'DeleteCertificate', type: 'bool')]
30+
public ?bool $deleteCertificate;
31+
32+
/**
33+
* The ID of the certificate.
34+
* @var string|null
35+
*/
36+
#[XmlElement(rename: 'CertId', type: 'string')]
37+
public ?string $certId;
38+
39+
/**
40+
* The public key of the certificate.
41+
* @var string|null
42+
*/
43+
#[XmlElement(rename: 'Certificate', type: 'string')]
44+
public ?string $certificate;
45+
46+
/**
47+
* The private key of the certificate.
48+
* @var string|null
49+
*/
50+
#[XmlElement(rename: 'PrivateKey', type: 'string')]
51+
public ?string $privateKey;
52+
53+
/**
54+
* The ID of the certificate. If the Force parameter is not set to true, the OSS server checks whether the value of the Force parameter matches the current certificate ID. If the value does not match the certificate ID, an error is returned.noticeIf you do not specify the PreviousCertId parameter when you bind a certificate, you must set the Force parameter to true./notice
55+
* @var string|null
56+
*/
57+
#[XmlElement(rename: 'PreviousCertId', type: 'string')]
58+
public ?string $previousCertId;
59+
60+
61+
/**
62+
* CertificateConfiguration constructor.
63+
* @param bool|null $force Specifies whether to overwrite the certificate.
64+
* @param bool|null $deleteCertificate Specifies whether to delete the certificate.
65+
* @param string|null $certId The ID of the certificate.
66+
* @param string|null $certificate The public key of the certificate.
67+
* @param string|null $privateKey The private key of the certificate.
68+
* @param string|null $previousCertId The ID of the certificate.
69+
*/
70+
public function __construct(
71+
?bool $force = null,
72+
?bool $deleteCertificate = null,
73+
?string $certId = null,
74+
?string $certificate = null,
75+
?string $privateKey = null,
76+
?string $previousCertId = null
77+
)
78+
{
79+
$this->force = $force;
80+
$this->deleteCertificate = $deleteCertificate;
81+
$this->certId = $certId;
82+
$this->certificate = $certificate;
83+
$this->privateKey = $privateKey;
84+
$this->previousCertId = $previousCertId;
85+
}
86+
}

0 commit comments

Comments
 (0)