• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Versioning Management
  5. Setting or Obtaining a Versioning Object ACL

Setting or Obtaining a Versioning Object ACL

Directly Setting a Versioning Object ACL

You can call ObsClient->setObjectAcl to set the ACL for a versioning object by specifying the version ID (VersionId). Sample code is as follows:

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

$resp = $obsClient -> setObjectAcl([
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       'VersionId' => 'versionid',
       // Set the versioning object ACL to public-read by specifying the pre-defined access control policy.
       'ACL' => ObsClient::AclPublicRead
]);

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

$resp = $obsClient -> setObjectAcl([
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'VersionId' => 'versionid',
              // Set the object owner.  
              'Owner' => ['ID' => 'ownerid', 'DisplayName' => 'ownername'],
              'Grants' => [
                     // Grant the READ permission to all users.
                     ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupAllUsers], 'Permission' => ObsClient::PermissionRead],              
                     // Grant the FULL-CONTROL permission to authorized users.
                     ['Grantee' => ['Type' => 'Group', 'URI' => ObsClient::GroupAuthenticatedUsers], 'Permission' => ObsClient::PermissionFullControl]
              ]
]);

printf("RequestId:%s\n", $resp['RequestId']);
NOTE:
  • Use the Owner parameter to specify the object owner and the Grants parameter to specify information about the authorized users.
  • The owner or grantee ID needed in the ACL indicates the account ID, which can be viewed on the My Credential page of OBS Console.
  • OBS objects support two types of grantee group:
    • Authorized users: ObsClient::GroupAuthenticatedUsers
    • All users: ObsClient::GroupAllUsers

Obtaining a Versioning Object ACL

You can call ObsClient->getObjectAcl to obtain the ACL of a versioning object by specifying the version ID (VersionId). Sample code is as follows:

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

$resp = $obsClient->getObjectAcl ( [ 
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       'VersionId' => 'versionid' 
] );

printf ( "RequestId:%s\n", $resp ['RequestId'] );
printf ( "Owner[ID]:%s\n", $resp ['Owner'] ['ID'] );
printf ( "Owner[DisplayName]:%s\n", $resp ['Owner'] ['DisplayName'] );
foreach ( $resp ['Grants'] as $index => $grant ) {
       printf ( "Grants[%d]\n", $index + 1 );
       printf ( "Grantee[ID]:%s\n", $grant ['Grantee'] ['ID'] );
       printf ( "Grantee[URI]:%s\n", $grant ['Grantee'] ['URI'] );
       printf ( "Permission:%s\n", $grant ['Permission'] );
}