Skip to content

Commit 41add81

Browse files
authored
add bucket referer api
1 parent 016cef6 commit 41add81

14 files changed

+756
-0
lines changed

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

sample/PutBucketReferer.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\PutBucketRefererRequest($bucket,
41+
refererConfiguration: new Oss\Models\RefererConfiguration(
42+
allowEmptyReferer: false,
43+
refererList: new Oss\Models\RefererList([""]),
44+
)
45+
);
46+
$result = $client->putBucketReferer($request);
47+
48+
printf(
49+
'status code:' . $result->statusCode . PHP_EOL .
50+
'request id:' . $result->requestId
51+
);

src/Client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
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\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.
124+
* @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.
125+
* @method Models\GetBucketRefererResult getBucketReferer(Models\GetBucketRefererRequest $request, array $args = []) Queries the hotlink protection configurations for a bucket.
126+
* @method \GuzzleHttp\Promise\Promise getBucketRefererAsync(Models\GetBucketRefererRequest $request, array $args = []) Queries the hotlink protection configurations for a bucket.
123127
* @method Models\GetBucketWebsiteResult getBucketWebsite(Models\GetBucketWebsiteRequest $request, array $args = []) Queries the static website hosting status and redirection rules configured for a bucket.
124128
* @method \GuzzleHttp\Promise\Promise getBucketWebsiteAsync(Models\GetBucketWebsiteRequest $request, array $args = []) Queries the static website hosting status and redirection rules configured for a bucket.
125129
* @method Models\PutBucketWebsiteResult putBucketWebsite(Models\PutBucketWebsiteRequest $request, array $args = []) Enables the static website hosting mode for a bucket and configures redirection rules for the bucket.
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 GetBucketReferer operation.
12+
* Class GetBucketRefererRequest
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
final class GetBucketRefererRequest 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+
* GetBucketRefererRequest 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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 GetBucketReferer operation.
11+
* Class GetBucketRefererResult
12+
* @package AlibabaCloud\Oss\V2\Models
13+
*/
14+
final class GetBucketRefererResult extends ResultModel
15+
{
16+
17+
/**
18+
* The container that stores the hotlink protection configurations.
19+
* @var RefererConfiguration|null
20+
*/
21+
#[TagBody(rename: 'RefererConfiguration', type: RefererConfiguration::class, format: 'xml')]
22+
public ?RefererConfiguration $refererConfiguration;
23+
24+
/**
25+
* GetBucketRefererRequest constructor.
26+
* @param RefererConfiguration|null $refererConfiguration The container that stores the hotlink protection configurations.
27+
*/
28+
public function __construct(
29+
?RefererConfiguration $refererConfiguration = null
30+
)
31+
{
32+
$this->refererConfiguration = $refererConfiguration;
33+
}
34+
}
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 PutBucketReferer operation.
12+
* Class PutBucketRefererRequest
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
final class PutBucketRefererRequest 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 RefererConfiguration|null
28+
*/
29+
#[RequiredProperty()]
30+
#[TagProperty(tag: '', position: 'body', rename: 'RefererConfiguration', type: 'xml')]
31+
public ?RefererConfiguration $refererConfiguration;
32+
33+
/**
34+
* PutBucketRefererRequest constructor.
35+
* @param string|null $bucket The name of the bucket.
36+
* @param RefererConfiguration|null $refererConfiguration The request body schema.
37+
* @param array|null $options
38+
*/
39+
public function __construct(
40+
?string $bucket = null,
41+
?RefererConfiguration $refererConfiguration = null,
42+
?array $options = null
43+
)
44+
{
45+
$this->bucket = $bucket;
46+
$this->refererConfiguration = $refererConfiguration;
47+
parent::__construct($options);
48+
}
49+
}
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 PutBucketReferer operation.
10+
* Class PutBucketRefererResult
11+
* @package AlibabaCloud\Oss\V2\Models
12+
*/
13+
final class PutBucketRefererResult extends ResultModel
14+
{
15+
}

src/Models/RefererBlacklist.php

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 RefererBlacklist
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
#[XmlRoot(name: 'RefererBlacklist')]
16+
final class RefererBlacklist extends Model
17+
{
18+
/**
19+
* The addresses in the Referer blacklist.
20+
* @var array<string>|null
21+
*/
22+
#[XmlElement(rename: 'Referer', type: 'string')]
23+
public ?array $referers;
24+
25+
/**
26+
* RefererBlacklist constructor.
27+
* @param array<string>|null $referers The addresses in the Referer blacklist.
28+
*/
29+
public function __construct(
30+
?array $referers = null
31+
)
32+
{
33+
$this->referers = $referers;
34+
}
35+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 RefererConfiguration
13+
* @package AlibabaCloud\Oss\V2\Models
14+
*/
15+
#[XmlRoot(name: 'RefererConfiguration')]
16+
final class RefererConfiguration extends Model
17+
{
18+
/**
19+
* Specifies whether to allow a request whose Referer field is empty. Valid values:* true (default)* false
20+
* @var bool|null
21+
*/
22+
#[XmlElement(rename: 'AllowEmptyReferer', type: 'bool')]
23+
public ?bool $allowEmptyReferer;
24+
25+
/**
26+
* Specifies whether to truncate the query string in the URL when the Referer is matched. Valid values:* true (default)* false
27+
* @var bool|null
28+
*/
29+
#[XmlElement(rename: 'AllowTruncateQueryString', type: 'bool')]
30+
public ?bool $allowTruncateQueryString;
31+
32+
/**
33+
* Specifies whether to truncate the path and parts that follow the path in the URL when the Referer is matched. Valid values:* true* false
34+
* @var bool|null
35+
*/
36+
#[XmlElement(rename: 'TruncatePath', type: 'bool')]
37+
public ?bool $truncatePath;
38+
39+
/**
40+
* The container that stores the Referer whitelist. The PutBucketReferer operation overwrites the existing Referer whitelist with the Referer whitelist specified in RefererList. If RefererList is not specified in the request, which specifies that no Referer elements are included, the operation clears the existing Referer whitelist.
41+
* @var RefererList|null
42+
*/
43+
#[XmlElement(rename: 'RefererList', type: RefererList::class)]
44+
public ?RefererList $refererList;
45+
46+
/**
47+
* The container that stores the Referer blacklist.
48+
* @var RefererBlacklist|null
49+
*/
50+
#[XmlElement(rename: 'RefererBlacklist', type: RefererBlacklist::class)]
51+
public ?RefererBlacklist $refererBlacklist;
52+
53+
/**
54+
* RefererConfiguration constructor.
55+
* @param bool|null $allowEmptyReferer Specifies whether to allow a request whose Referer field is empty.
56+
* @param bool|null $allowTruncateQueryString Specifies whether to truncate the query string in the URL when the Referer is matched.
57+
* @param bool|null $truncatePath Specifies whether to truncate the path and parts that follow the path in the URL when the Referer is matched.
58+
* @param RefererList|null $refererList The container that stores the Referer whitelist.
59+
* @param RefererBlacklist|null $refererBlacklist The container that stores the Referer blacklist.
60+
*/
61+
public function __construct(
62+
?bool $allowEmptyReferer = null,
63+
?bool $allowTruncateQueryString = null,
64+
?bool $truncatePath = null,
65+
?RefererList $refererList = null,
66+
?RefererBlacklist $refererBlacklist = null
67+
)
68+
{
69+
$this->allowEmptyReferer = $allowEmptyReferer;
70+
$this->allowTruncateQueryString = $allowTruncateQueryString;
71+
$this->truncatePath = $truncatePath;
72+
$this->refererList = $refererList;
73+
$this->refererBlacklist = $refererBlacklist;
74+
}
75+
}

0 commit comments

Comments
 (0)