-
Notifications
You must be signed in to change notification settings - Fork 300
Description
Hello team,
Thank you for developing and maintaining the MinIO JS SDK!
I've observed an inconsistent behavior when using the getBucketLifecycle method regarding the structure of the returned lifecycle rules.
Specifically, when a bucket has multiple lifecycle rules configured, the Rule property in the parsed JSON response is correctly returned as an array of rule objects.
However, when a bucket has only a single lifecycle rule, the Rule property is returned as a single rule object directly, instead of an array containing one object.
This inconsistency requires application code consuming the SDK to add checks for whether lifecycleConfig.Rule is an array or an object, adding complexity to handle both cases.
Here are examples demonstrating the difference in structure from calling getBucketLifecycle:
// Example call structure
try {
const lifecycleConfig = await s3Client.getBucketLifecycle('bucket1') // bucket1 has multiple rules
console.log('Bucket 1 config:', JSON.stringify(lifecycleConfig, null, 2))
} catch (err) {
console.log(err.message)
}
try {
const lifecycleConfig = await s3Client.getBucketLifecycle('bucket2') // bucket2 has a single rule
console.log('Bucket 2 config:', JSON.stringify(lifecycleConfig, null, 2))
} catch (err) {
console.log(err.message)
}
Output observed:
// Output for 'bucket1' (multiple rules)
{
"Rule": [ // This is an ARRAY
{
"ID": "r1",
"Status": "Enabled",
"Filter": {
"Prefix": "TEST1/"
},
"Expiration": {
"Days": 31
}
},
{
"ID": "r2",
"Status": "Enabled",
"Filter": {
"Prefix": "TEST2/"
},
"Expiration": {
"Days": 31
}
}
]
}
// Output for 'bucket2' (single rule)
{
"Rule": { // This is a SINGLE OBJECT
"ID": "retention_EVENT_30",
"Status": "Enabled",
"Filter": {
"Prefix": "EVENT/"
},
"Expiration": {
"Days": 30
}
}
}
It seems this might be a common issue related to how underlying XML parsers handle single versus multiple elements with the same tag name (like <Rule>). Refer to #1397, #1399, https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html
It would be very helpful if the Rule property consistently returned an array structure (even if empty when no rules exist, or containing a single object when only one rule exists).
Thank you for considering this for a future update!