Skip to content

Commit

Permalink
Only include metadata when requested (#2472)
Browse files Browse the repository at this point in the history
* Only include metadata when requested

* Add test for listBlobHierarchySegment

---------

Co-authored-by: Frederik Rosenberg <[email protected]>
  • Loading branch information
frederikrosenberg and Frederik Rosenberg authored Oct 9, 2024
1 parent cd8cbd0 commit f2e1619
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
Blob:

- Fixed an issue where all blob APIs allowed metadata names which were not valid C# identifiers.
- Fixed always including metadata on blob list even when not requested

## 2024.08 Version 3.32.0

General:

- Bump mysql2 to resolve to 3.10.1 for security patches
- Fixed an issue where premature client disconnections led to all following requests failing with a 500 error. (issue #1346)
- Fixed an issue where premature client disconnections led to all following requests failing with a 500 error. (issue #1346)
- Bump up service API version to 2024-11-04

Blob:
Expand Down
10 changes: 10 additions & 0 deletions src/blob/handlers/ContainerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ export default class ContainerHandler extends BaseHandler
let includeSnapshots: boolean = false;
let includeUncommittedBlobs: boolean = false;
let includeTags: boolean = false;
let includeMetadata: boolean = false;
if (options.include !== undefined) {
options.include.forEach(element => {
if (Models.ListBlobsIncludeItem.Snapshots.toLowerCase() === element.toLowerCase()) {
Expand All @@ -616,6 +617,9 @@ export default class ContainerHandler extends BaseHandler
if (Models.ListBlobsIncludeItem.Tags.toLowerCase() === element.toLowerCase()) {
includeTags = true;
}
if (Models.ListBlobsIncludeItem.Metadata.toLowerCase() === element.toLowerCase()) {
includeMetadata = true;
}
})
}
if (
Expand Down Expand Up @@ -657,6 +661,7 @@ export default class ContainerHandler extends BaseHandler
deleted: item.deleted !== true ? undefined : true,
snapshot: item.snapshot || undefined,
blobTags: includeTags ? item.blobTags : undefined,
metadata: includeMetadata ? item.metadata : undefined,
properties: {
...item.properties,
etag: removeQuotationFromListBlobEtag(item.properties.etag),
Expand Down Expand Up @@ -705,6 +710,7 @@ export default class ContainerHandler extends BaseHandler
let includeSnapshots: boolean = false;
let includeUncommittedBlobs: boolean = false;
let includeTags: boolean = false;
let includeMetadata: boolean = false;
if (options.include !== undefined) {
options.include.forEach(element => {
if (Models.ListBlobsIncludeItem.Snapshots.toLowerCase() === element.toLowerCase()) {
Expand All @@ -716,6 +722,9 @@ export default class ContainerHandler extends BaseHandler
if (Models.ListBlobsIncludeItem.Tags.toLowerCase() === element.toLowerCase()) {
includeTags = true;
}
if (Models.ListBlobsIncludeItem.Metadata.toLowerCase() === element.toLowerCase()) {
includeMetadata = true;
}
}
)
}
Expand Down Expand Up @@ -760,6 +769,7 @@ export default class ContainerHandler extends BaseHandler
...item,
snapshot: item.snapshot || undefined,
blobTags: includeTags ? item.blobTags : undefined,
metadata: includeMetadata ? item.metadata : undefined,
properties: {
...item.properties,
etag: removeQuotationFromListBlobEtag(item.properties.etag),
Expand Down
26 changes: 24 additions & 2 deletions tests/blob/apis/container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,18 @@ describe("ContainerAPIs", () => {

it("listBlobHierarchySegment with default parameters @loki @sql", async () => {
const blobClients = [];
const metadata = {
keya: "a",
keyb: "c"
};
for (let i = 0; i < 3; i++) {
const blobClient = containerClient.getBlobClient(
getUniqueName(`blockblob${i}/${i}`)
);
const blockBlobClient = blobClient.getBlockBlobClient();
await blockBlobClient.upload("", 0);
await blockBlobClient.upload("", 0, {
metadata
});
blobClients.push(blobClient);
}

Expand All @@ -298,6 +304,15 @@ describe("ContainerAPIs", () => {
assert.ok(blob.url.indexOf(result.segment.blobPrefixes![i++].name));
}

for (const prefix of result.segment.blobPrefixes) {
const prefixResult = (
await containerClient.listBlobsByHierarchy(delimiter, { prefix: prefix.name }).byPage().next()
).value;

assert.deepStrictEqual(prefixResult.segment.blobItems!.length, 1);
assert.deepStrictEqual(prefixResult.segment.blobItems![0].metadata, undefined);
}

for (const blob of blobClients) {
await blob.delete();
}
Expand Down Expand Up @@ -548,12 +563,18 @@ describe("ContainerAPIs", () => {

it("should correctly list all blobs in the container using listBlobFlatSegment with default parameters @loki @sql", async () => {
const blobClients = [];
const metadata = {
keya: "a",
keyb: "c"
};
for (let i = 0; i < 3; i++) {
const blobClient = containerClient.getBlobClient(
getUniqueName(`blockblob${i}/${i}`)
);
const blockBlobClient = blobClient.getBlockBlobClient();
await blockBlobClient.upload("", 0);
await blockBlobClient.upload("", 0, {
metadata
});
blobClients.push(blobClient);
}

Expand Down Expand Up @@ -581,6 +602,7 @@ describe("ContainerAPIs", () => {
'"' + result.segment.blobItems![i].properties.etag + '"'
);
assert.deepStrictEqual(result.segment.blobItems![i].snapshot, undefined);
assert.deepStrictEqual(result.segment.blobItems![i].metadata, undefined);
i++;
}

Expand Down

0 comments on commit f2e1619

Please sign in to comment.