Managing Bucket Policies

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

Besides bucket ACLs, bucket owners can use bucket policies to centrally control access to buckets and objects in buckets.

For more information, see Bucket Policy.

Setting a Bucket Policy

You can call ObsClient->setBucketPolicy to set a bucket policy. Sample code is as follows:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://your-endpoint'
]);

$resp = $obsClient->setBucketPolicy([
       'Bucket' => 'bucketname',
       'Policy' => 'your policy'
]);

printf("RequestId:%s\n",$resp['RequestId']);

For details about the format (JSON character string) of bucket policies, see the Object Storage Service API Reference.

Obtaining a Bucket Policy

You can call ObsClient->getBucketPolicy to obtain a bucket policy. Sample code is as follows:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://your-endpoint'
]);

$resp = $obsClient->getBucketPolicy([
       'Bucket' => 'bucketname'
]);

printf("RequestId:%s\n",$resp['RequestId']);
printf("Policy:%s\n",$resp['Policy']);

Deleting a Bucket Policy

You can call ObsClient->deleteBucketPolicy to delete a bucket policy. Sample code is as follows:

// Import the dependency library.
require 'vendor/autoload.php';
// Import the SDK code library during source code installation.
// require 'obs-autoloader.php';
// Declare the namespace.
use Obs\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://your-endpoint'
]);

$resp = $obsClient->deleteBucketPolicy([
       'Bucket' => 'bucketname'
]);

printf("RequestId:%s\n",$resp['RequestId']);