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 Oct 18, 2023
1 parent f4a170b commit 65bd92a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
25 changes: 19 additions & 6 deletions lib/common/bucket/putBucketLifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ function handleCheckTag(tag) {
checkObjectTag(tagObj);
}

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

function checkRule(rule) {
if (rule.id && getStrBytesCount(rule.id) > 255) throw new Error('ID is composed of 255 bytes at most');

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

if (rule.transition) {
if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.transition.storageClass))
throw new Error('StorageClass must be IA、Archive、ColdArchive、DeepColdArchive');
checkStorageClass('StorageClass', rule.transition.storageClass);
checkDaysAndDate(rule.transition, 'Transition');
}

Expand All @@ -121,18 +125,27 @@ function checkRule(rule) {
checkDaysAndDate(rule.abortMultipartUpload, 'AbortMultipartUpload');
}

if (!rule.expiration && !rule.abortMultipartUpload && !rule.transition && !rule.noncurrentVersionTransition) {
if (
!rule.expiration &&
!rule.noncurrentVersionExpiration &&
!rule.abortMultipartUpload &&
!rule.transition &&
!rule.noncurrentVersionTransition
) {
throw new Error(
'Rule must includes expiration or abortMultipartUpload or transition or noncurrentVersionTransition'
'Rule must includes expiration or noncurrentVersionExpiration or abortMultipartUpload or transition or noncurrentVersionTransition'
);
}

if (rule.noncurrentVersionTransition) {
if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.noncurrentVersionTransition.storageClass))
throw new Error('noncurrentVersionTransition StorageClass must be IA、Archive、ColdArchive、DeepColdArchive');
checkStorageClass('noncurrentVersionTransition', rule.noncurrentVersionTransition.storageClass);
checkNoncurrentDays(rule.noncurrentVersionTransition, 'NoncurrentVersionTransition');
}

if (rule.noncurrentVersionExpiration) {
checkNoncurrentDays(rule.noncurrentVersionExpiration, 'NoncurrentVersionExpiration');
}

if (rule.tag) {
if (rule.abortMultipartUpload) {
throw new Error('Tag cannot be used with abortMultipartUpload');
Expand Down
3 changes: 1 addition & 2 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const { env } = process;

const config = module.exports;
const USWEST = 'oss-ap-southeast-1'; // ONCI=true Faster using oss-ap-outsoutheast-1

config.oss = {
accessKeyId: env.ALI_SDK_OSS_ID,
accessKeySecret: env.ALI_SDK_OSS_SECRET,
accountId: env.ALI_SDK_STS_ROLE.match(/^acs:ram::(\d+):role/i)[1], // Obtain the main account ID through roleRan
region: env.ALI_SDK_OSS_REGION,
endpoint: env.ONCI ? `https://${USWEST}.aliyuncs.com` : undefined,
endpoint: env.ONCI ? `https://${env.ALI_SDK_OSS_REGION}.aliyuncs.com` : undefined,
maxSocket: 50
};

Expand Down
4 changes: 2 additions & 2 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ describe('test/bucket.test.js', () => {
status: 'Enabled',
transition: {
createdBeforeDate: '2020-02-18T00:00:00.000Z',
storageClass: 'Archive'
storageClass: 'IA'
},
expiration: {
createdBeforeDate: '2020-02-17T00:00:00.000Z'
Expand Down Expand Up @@ -1020,7 +1020,7 @@ describe('test/bucket.test.js', () => {
]);
assert(false);
} catch (error) {
assert(error.message.includes('IAArchive'));
assert(error.message.includes('IA or Archive or ColdArchive or DeepColdArchive'));
}
});

Expand Down
13 changes: 10 additions & 3 deletions test/node/multiversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ describe('test/multiversion.test.js', () => {
});

describe('putBucketLifecycle() getBucketLifecycle()', async () => {
it('should putBucketLifecycle with NoncurrentVersionExpiration', async () => {
it('should putBucketLifecycle with noncurrentVersionExpiration', async () => {
const putresult1 = await store.putBucketLifecycle(
bucket,
[
{
id: 'expiration1',
prefix: 'logs/',
status: 'Enabled',
expiration: {
Expand All @@ -125,6 +124,13 @@ describe('test/multiversion.test.js', () => {
noncurrentVersionExpiration: {
noncurrentDays: 1
}
},
{
prefix: 'logss/',
status: 'Enabled',
noncurrentVersionExpiration: {
noncurrentDays: 1
}
}
],
{
Expand All @@ -136,6 +142,7 @@ describe('test/multiversion.test.js', () => {
const { rules } = await store.getBucketLifecycle(bucket);
assert.strictEqual(rules[0].noncurrentVersionExpiration.noncurrentDays, '1');
});

it('should putBucketLifecycle with expiredObjectDeleteMarker', async () => {
const putresult1 = await store.putBucketLifecycle(bucket, [
{
Expand Down Expand Up @@ -199,7 +206,7 @@ describe('test/multiversion.test.js', () => {
}
] = rules;

assert(noncurrentDays === '10' && storageClass === 'IA');
assert(noncurrentDays === '10' && storageClass === 'IA' && rules.length === 4);
});
});

Expand Down

0 comments on commit 65bd92a

Please sign in to comment.