Skip to content

Commit

Permalink
fix: putBucketLifecycle add ColdArchive and DeepColdArchive
Browse files Browse the repository at this point in the history
  • Loading branch information
csg01123119 committed Aug 7, 2024
1 parent 3bf8abf commit de7aefe
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
8 changes: 4 additions & 4 deletions lib/common/bucket/putBucketLifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ function handleCheckTag(tag) {
checkObjectTag(tagObj);
}

function checkStorageClass(name, storageClass) {
function checkStorageClass(storageClass) {
if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(storageClass))
throw new Error(`${name} must be IA or Archive or ColdArchive or DeepColdArchive`);
throw new Error(`StorageClass must be IA or Archive or ColdArchive or DeepColdArchive`);
}

function checkRule(rule) {
Expand All @@ -109,7 +109,7 @@ function checkRule(rule) {
if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled');

if (rule.transition) {
checkStorageClass('StorageClass', rule.transition.storageClass);
checkStorageClass(rule.transition.storageClass);
checkDaysAndDate(rule.transition, 'Transition');
}

Expand Down Expand Up @@ -138,7 +138,7 @@ function checkRule(rule) {
}

if (rule.noncurrentVersionTransition) {
checkStorageClass('noncurrentVersionTransition', rule.noncurrentVersionTransition.storageClass);
checkStorageClass(rule.noncurrentVersionTransition.storageClass);
checkNoncurrentDays(rule.noncurrentVersionTransition, 'NoncurrentVersionTransition');
}

Expand Down
21 changes: 20 additions & 1 deletion test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,25 @@ describe('test/bucket.test.js', () => {
});

describe('putBucketLifecycle()', () => {
// todo delete
it('should put the lifecycle throw error', async () => {
try {
await store.putBucketLifecycle(bucket, [
{
id: 'expiration1',
prefix: 'logs/',
status: 'Enabled',
day: 1
}
]);
assert.fail('expected an error to be thrown');
} catch (e) {
assert.equal(
e.message,
'Rule must includes expiration or noncurrentVersionExpiration or abortMultipartUpload or transition or noncurrentVersionTransition'
);
}
});

it('should put the lifecycle with old api', async () => {
const putresult1 = await store.putBucketLifecycle(bucket, [
{
Expand All @@ -774,6 +792,7 @@ describe('test/bucket.test.js', () => {
days: 1
}
]);

assert.equal(putresult1.res.status, 200);

const putresult2 = await store.putBucketLifecycle(bucket, [
Expand Down
73 changes: 39 additions & 34 deletions test/node/multiversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('test/multiversion.test.js', () => {
].forEach((moreConfigs, idx) => {
describe(`test multiversion in iterate ${idx}`, () => {
before(async () => {
store = oss({ ...config, ...moreConfigs });
// oss-ap-southeast-1 suport PutBucketLifecycle DeepColdArchive
store = oss({ ...config, ...moreConfigs, region: 'oss-ap-southeast-1' });
bucket = `ali-oss-test-bucket-version-${prefix.replace(/[/.]/g, '-')}${idx}`;

const result = await store.putBucket(bucket);
Expand Down Expand Up @@ -170,40 +171,44 @@ describe('test/multiversion.test.js', () => {
});

it('should putBucketLifecycle with noncurrentVersionTransition', async () => {
const putresult = await store.putBucketLifecycle(bucket, [
{
prefix: 'log/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'IA'
}
},
{
prefix: 'logs/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'Archive'
}
},
{
prefix: 'logss/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'ColdArchive'
}
},
{
prefix: 'logsss/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'DeepColdArchive'
const putresult = await store.putBucketLifecycle(
bucket,
[
{
prefix: 'log/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'IA'
}
},
{
prefix: 'log/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'Archive'
}
},
{
prefix: 'log/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'ColdArchive'
}
},
{
prefix: 'log/',
status: 'Enabled',
noncurrentVersionTransition: {
noncurrentDays: '10',
storageClass: 'DeepColdArchive'
}
}
}
]);
],
{ headers: { 'x-oss-allow-same-action-overlap': 'true' } }
);
assert.equal(putresult.res.status, 200);
await utils.sleep(1000);

Expand Down

0 comments on commit de7aefe

Please sign in to comment.