Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: putBucketLifecycle add ColdArchive and DeepColdArchive #1256

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,12 @@ parameters:
- [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z`
`createdBeforeDate` and `days` must have one.
- [transition] {Object} Specifies the time when an object is converted to the IA or archive storage class during a valid life cycle.
- storageClass {String} Specifies the storage class that objects that conform to the rule are converted into. allow values: `IA` or `Archive`
- storageClass {String} Specifies the storage class that objects that conform to the rule are converted into. allow values: `IA` or `Archive` or `ColdArchive` or `DeepColdArchive`
- [days] {Number|String} expire after the `days`
- [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z`
`createdBeforeDate` and `days` must have one.
- [noncurrentVersionTransition] {Object} Specifies the time when an object is converted to the IA or archive storage class during a valid life cycle.
- storageClass {String} Specifies the storage class that history objects that conform to the rule are converted into. allow values: `IA` or `Archive`
- storageClass {String} Specifies the storage class that history objects that conform to the rule are converted into. allow values: `IA` or `Archive` or `ColdArchive` or `DeepColdArchive`
- noncurrentDays {String} expire after the `noncurrentDays`
`expiration`、 `abortMultipartUpload`、 `transition`、 `noncurrentVersionTransition` must have one.
- [noncurrentVersionExpiration] {Object} specifies the expiration attribute of the lifecycle rules for the history object.
Expand Down
19 changes: 17 additions & 2 deletions lib/common/bucket/putBucketLifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ function checkDaysAndDate(obj, key) {
}
}

function checkNoncurrentDays(obj, key) {
const { noncurrentDays } = obj;
if (!noncurrentDays) {
throw new Error(`${key} must includes noncurrentDays`);
} else if (noncurrentDays && !/^[1-9][0-9]*$/.test(noncurrentDays)) {
throw new Error('noncurrentDays must be a positive integer');
}
}

function handleCheckTag(tag) {
if (!isArray(tag) && !isObject(tag)) {
throw new Error('tag must be Object or Array');
Expand All @@ -95,8 +104,8 @@ function checkRule(rule) {
if (!['Enabled', 'Disabled'].includes(rule.status)) throw new Error('Status must be Enabled or Disabled');

if (rule.transition) {
if (!['IA', 'Archive'].includes(rule.transition.storageClass))
throw new Error('StorageClass must be IA or Archive');
if (!['IA', 'Archive', 'ColdArchive', 'DeepColdArchive'].includes(rule.transition.storageClass))
throw new Error('StorageClass must be IAArchive、ColdArchive、DeepColdArchive');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

存储类型的检查提个方法出来,transition和noncurrentVersionTransition都要用;这个error message多了一个空格,而且存储类型间应该是或的关系,要用or

checkDaysAndDate(rule.transition, 'Transition');
}

Expand All @@ -118,6 +127,12 @@ function checkRule(rule) {
);
shungang marked this conversation as resolved.
Show resolved Hide resolved
}

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

shungang marked this conversation as resolved.
Show resolved Hide resolved
if (rule.tag) {
if (rule.abortMultipartUpload) {
throw new Error('Tag cannot be used with abortMultipartUpload');
Expand Down
2 changes: 1 addition & 1 deletion test/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { env } = process;

const config = module.exports;
const USWEST = 'oss-us-west-1'; // ONCI=true Using the region of Silicon Valley in the United States would be faster
const USWEST = 'oss-ap-southeast-1'; // ONCI=true Faster using oss-ap-outsoutheast-1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码注释拼写错误,且和签名的变量命名不一致,有办法同时支持美西和新加坡吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有必要同时支持 美西和新加坡吧,要加的话,改动有点大

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解只是在这里加一个新的配置,库增加一个变量,在UT里增加一个bucket就好吧,后面直接用就行


config.oss = {
accessKeyId: env.ALI_SDK_OSS_ID,
Expand Down
35 changes: 34 additions & 1 deletion test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,39 @@ describe('test/bucket.test.js', () => {
}
]);
assert.equal(putresult2.res.status, 200);
shungang marked this conversation as resolved.
Show resolved Hide resolved
const putresult3 = await store.putBucketLifecycle(bucket, [
{
id: 'transition3',
prefix: 'logs/',
status: 'Enabled',
transition: {
days: 20,
storageClass: 'ColdArchive'
},
tag: {
key: 'test3',
value: '123'
}
}
]);
assert.equal(putresult3.res.status, 200);
// Regions that need to support DeepColdArchive
const putresult4 = await store.putBucketLifecycle(bucket, [
{
id: 'transition4',
prefix: 'logs/',
status: 'Enabled',
transition: {
days: 20,
storageClass: 'DeepColdArchive'
},
tag: {
key: 'test4',
value: '123'
}
}
]);
assert.equal(putresult4.res.status, 200);
});

it('should put the lifecycle with expiration and Tag', async () => {
Expand Down Expand Up @@ -987,7 +1020,7 @@ describe('test/bucket.test.js', () => {
]);
assert(false);
} catch (error) {
assert(error.message.includes('IA or Archive'));
assert(error.message.includes('IAArchive'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

四种存储类型,这里就两个,而且是或的关系,上面的描述也要改吧

}
});

Expand Down
35 changes: 30 additions & 5 deletions test/node/multiversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('test/multiversion.test.js', () => {
expiration: {
expiredObjectDeleteMarker: 'true'
},
NoncurrentVersionExpiration: {
noncurrentVersionExpiration: {
shungang marked this conversation as resolved.
Show resolved Hide resolved
noncurrentDays: 1
}
}
Expand All @@ -156,24 +156,49 @@ describe('test/multiversion.test.js', () => {
});

it('should putBucketLifecycle with noncurrentVersionTransition', async () => {
const putresult1 = await store.putBucketLifecycle(bucket, [
const putresult = await store.putBucketLifecycle(bucket, [
{
id: 'expiration1',
prefix: 'logs/',
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'
}
}
]);
assert.equal(putresult1.res.status, 200);
assert.equal(putresult.res.status, 200);

const { rules } = await store.getBucketLifecycle(bucket);
const [
{
noncurrentVersionTransition: { noncurrentDays, storageClass }
}
] = rules;

assert(noncurrentDays === '10' && storageClass === 'IA');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里确定是对的吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对的

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面是四条呢,是不是都要检查一下

});
});
Expand Down