This API configures a default WORM policy and retention period for a bucket.
With the bucket's default WORM policy, if you do not specify a WORM policy or a retention period when you upload an object to the bucket, the default policy will be automatically applied to the newly uploaded object. An object-level WORM policy requires configuring a specific date, which indicates an object will be protected until that date. For a default bucket-level WORM policy, a retention period is required, and the protection for an object starts when the object is uploaded to the bucket.
To perform this operation, you must have the PutBucketObjectLockConfiguration permission. By default, only the bucket owner can perform this operation. The bucket owner can grant the permission to other users by configuring the bucket policy or user policy.
Other restrictions on the WORM retention configuration:
PUT /?object-lock HTTP/1.1
Host: bucketname.obs.region.example.com
Date: date
Authorization: authorization
Content-Type: application/xml
Content-Length: length
<ObjectLockConfiguration xmlns="http://obs.region.example.com/doc/2015-06-30/">
<ObjectLockEnabled>Enabled</ObjectLockEnabled>
<Rule>
<DefaultRetention>
<Days>integer</Days>
<Mode>COMPLIANCE</Mode>
<Years>integer</Years>
</DefaultRetention>
</Rule>
</ObjectLockConfiguration>
This request contains no message parameters.
This request uses common headers. For details, see Table 3.
Element |
Description |
Mandatory (Yes/No) |
|---|---|---|
ObjectLockConfiguration |
Container for configuring WORM for a bucket. Type: container |
Yes |
ObjectLockEnabled |
Indicates whether the bucket has WORM enabled. The value can only be Enabled. Type: string Example: Enabled |
No |
Rule |
Rule container for the default bucket-level WORM policy. Type: container |
This header is mandatory for configuring the default WORM policy for a bucket. If it is not contained, the existing default WORM policy will be deleted. |
DefaultRetention |
Container for the default WORM retention policy for the bucket. Type: container |
Yes if Rule is specified |
Mode |
Default protection mode. It can only be set to COMPLIANCE now. Type: string Example: COMPLIANCE |
Yes if DefaultRetention is specified |
Days |
Default protection period, in days. The value is from 1 to 36500. Type: integer Example: 1 |
If the DefaultRetention container is included, you must specify either Days or Years, but you cannot specify both at the same time. |
Years |
Default protection period, in years. The value is from 1 to 100. In a leap year, only 365 days are calculated. Type: integer Example: 1 |
If the DefaultRetention container is included, you must specify either Years or Days, but you cannot specify both at the same time. |
HTTP/1.1 status_code Date: date Content-Length: length
This response uses common headers. For details, see Table 1.
This response contains no elements.
Table 2 describes possible special errors in this request.
Error Code |
Description |
HTTP Status Code |
|---|---|---|
InvalidRequest |
The object lock is disabled for the bucket. |
400 |
MalformedXML |
Invalid policy configuration format. The XML you provided was not well-formed or did not validate against our published schema. |
400 |
For other errors, see Table 2.
Configure the default bucket-level WORM policy with a retention period of 2 years.
PUT /?object-lock HTTP/1.1
Host: bucketname.obs.region.example.com
Date: WED, 01 Jul 2015 02:25:05 GMT
Authorization: OBS H4IPJX0TQTHTHEBQQCEC:75/Y4Ng1izvzc1nTGxpMXTE6ynw=
Content-Type: application/xml
Content-Length: 157
<ObjectLockConfiguration xmlns="http://obs.region.example.com/doc/2015-06-30/">
<ObjectLockEnabled>Enabled</ObjectLockEnabled>
<Rule>
<DefaultRetention>
<Mode>COMPLIANCE</Mode>
<Years>2</Years>
</DefaultRetention>
</Rule>
</ObjectLockConfiguration>
HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF260000016435CE298386946AE4C482 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCT9W2tcvLmMJ+plfdopaD62S0npbaRUz Date: WED, 01 Jul 2015 02:25:06 GMT Content-Length: 0
Delete the configuration of the default bucket-level WORM policy.
PUT /?object-lock HTTP/1.1 Host: bucketname.obs.region.example.com Date: WED, 01 Jul 2015 02:25:05 GMT Authorization: OBS H4IPJX0TQTHTHEBQQCEC:75/Y4Ng1izvzc1nTGxpMXTE6ynw= Content-Type: application/xml Content-Length: 157 <ObjectLockConfiguration xmlns="http://obs.region.example.com/doc/2015-06-30/"> </ObjectLockConfiguration>
HTTP/1.1 200 OK Server: OBS x-obs-request-id: BF260000016435CE298386946AE4C482 x-obs-id-2: 32AAAQAAEAABSAAgAAEAABAAAQAAEAABCT9W2tcvLmMJ+plfdopaD62S0npbaRUz Date: WED, 01 Jul 2015 02:25:06 GMT Content-Length: 0