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

added tags response from listObjectsV2WithMetadata #1298

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/internal/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -114,6 +118,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('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
Loading