Skip to content

Commit

Permalink
added tags response from listObjectsV2WithMetadata (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
TzachiSh authored Oct 16, 2024
1 parent e556d26 commit 66dab2c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/internal/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export interface ItemBucketMetadata {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any
}
export interface ItemBucketTags {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any
}

export interface BucketItemFromList {
name: string
Expand Down Expand Up @@ -120,6 +124,7 @@ export type BucketItem =

export type BucketItemWithMetadata = BucketItem & {
metadata?: ItemBucketMetadata | ItemBucketMetadataList
tags?: ItemBucketTags
}

export interface BucketStream<T> extends ReadableStream {
Expand Down
14 changes: 13 additions & 1 deletion src/internal/xml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
CopyObjectResultV1,
ObjectLockInfo,
ReplicationConfig,
Tags,
} from './type.ts'
import { RETENTION_VALIDITY_UNITS } from './type.ts'

Expand Down Expand Up @@ -129,13 +130,24 @@ export function parseListObjectsV2WithMetadata(xml: string) {
const lastModified = new Date(content.LastModified)
const etag = sanitizeETag(content.ETag)
const size = content.Size

let tags: Tags = {}
if (content.UserTags != null) {
toArray(content.UserTags.split('&')).forEach((tag) => {
const [key, value] = tag.split('=')
tags[key] = value
})
} else {
tags = {}
}

let metadata
if (content.UserMetadata != null) {
metadata = toArray(content.UserMetadata)[0]
} else {
metadata = null
}
result.objects.push({ name, lastModified, etag, size, metadata })
result.objects.push({ name, lastModified, etag, size, metadata, tags })
})
}

Expand Down
59 changes: 59 additions & 0 deletions tests/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3620,6 +3620,65 @@ describe('functional tests', function () {
)
})
})
describe('listObjectsV2WithMetadata with tags and metadata', function () {
const bucketName = 'minio-js-test-tags-' + uuid.v4()
const fdObjectName = 'datafile-100-kB'
const fdObject = dataDir ? fs.readFileSync(dataDir + '/' + fdObjectName) : Buffer.alloc(100 * 1024, 0)
const objectName = 'objectwithtags'
const tags = { key1: 'value1', key2: 'value2' }
const metadata = { 'X-Amz-Meta-Test': 'test-value' }

before(() => {
return client.makeBucket(bucketName, '').then((res) => {

Check warning on line 3632 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'res' is defined but never used
return client.putObject(bucketName, objectName, fdObject, fdObject.length, metadata).then((res) => {

Check warning on line 3633 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'res' is defined but never used
return client.setObjectTagging(bucketName, objectName, tags)
})
})
})
after(() => client.removeObject(bucketName, objectName).then((_) => client.removeBucket(bucketName)))

Check warning on line 3638 in tests/functional/functional-tests.js

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used

step(
`extensions.listObjectsV2WithMetadata(bucketName, prefix, recursive)_bucketName:${bucketName}, prefix:"", recursive:true`,
function (done) {
const listStream = client.extensions.listObjectsV2WithMetadata(bucketName, '', true)
let listedObject = null

listStream.on('data', function (obj) {
listedObject = obj
})

listStream.on('end', function () {
if (!listedObject) {
return done(new Error('No objects were listed'))
}

if (listedObject.name !== objectName) {
return done(new Error(`Expected object name: ${objectName}, received: ${listedObject.name}`))
}

if (!_.isEqual(listedObject.tags, tags)) {
return done(
new Error(`Expected tags: ${JSON.stringify(tags)}, received: ${JSON.stringify(listedObject.tags)}`),
)
}

if (!_.isEqual(listedObject.metadata['X-Amz-Meta-Test'], metadata['X-Amz-Meta-Test'])) {
return done(
new Error(
`Expected metadata: ${JSON.stringify(metadata)}, received: ${JSON.stringify(listedObject.metadata)}`,
),
)
}

done()
})

listStream.on('error', function (e) {
done(e)
})
},
)
})
describe('Object Name special characters test with a Prefix', () => {
// Isolate the bucket/object for easy debugging and tracking.
const bucketNameForSpCharObjects = 'minio-js-test-obj-spnpre-' + uuid.v4()
Expand Down

0 comments on commit 66dab2c

Please sign in to comment.