Skip to content

Commit

Permalink
Filter blob by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaZhu committed Sep 3, 2024
1 parent 128ea41 commit f6ba562
Show file tree
Hide file tree
Showing 28 changed files with 2,390 additions and 184 deletions.
105 changes: 82 additions & 23 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
"request": "launch",
"name": "Azurite Service - Loki",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${workspaceFolder}/src/azurite.ts", "-d", "debug.log"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/azurite.ts",
"-d",
"debug.log"
],
"env": {
"AZURITE_ACCOUNTS": ""
},
"skipFiles": ["node_modules/*/**", "<node_internals>/*/**"],
"skipFiles": [
"node_modules/*/**",
"<node_internals>/*/**"
],
"outputCapture": "std"
},
{
Expand All @@ -35,8 +45,16 @@
"request": "launch",
"name": "Azurite Service - Loki, Loose",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${workspaceFolder}/src/azurite.ts", "-d", "debug.log", "-L"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/azurite.ts",
"-d",
"debug.log",
"-L"
],
"env": {
"AZURITE_ACCOUNTS": ""
},
Expand All @@ -47,7 +65,10 @@
"request": "launch",
"name": "Azurite Service - Loki, Loose, HTTPS, OAuth",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/azurite.ts",
"-L",
Expand All @@ -70,7 +91,10 @@
"request": "launch",
"name": "Azurite Queue Service - Loki, HTTPS, OAuth",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/queue/main.ts",
"-d",
Expand All @@ -92,7 +116,10 @@
"request": "launch",
"name": "Azurite Blob Service - Loki, HTTPS, OAuth",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/blob/main.ts",
"-d",
Expand All @@ -114,8 +141,15 @@
"request": "launch",
"name": "Azurite Blob Service - SQL",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${workspaceFolder}/src/blob/main.ts", "-d", "debug.log"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/blob/main.ts",
"-d",
"debug.log"
],
"env": {
"AZURITE_DB": "mysql://root:[email protected]:3306/azurite_blob",
"AZURITE_ACCOUNTS": ""
Expand All @@ -127,8 +161,15 @@
"request": "launch",
"name": "Azurite Table Service - Loki",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${workspaceFolder}/src/table/main.ts", "-d", "debug.log"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/table/main.ts",
"-d",
"debug.log"
],
"env": {
"AZURITE_ACCOUNTS": ""
},
Expand All @@ -139,16 +180,24 @@
"request": "launch",
"name": "Current TS File",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${workspaceFolder}/${relativeFile}"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/${relativeFile}"
],
"outputCapture": "std"
},
{
"type": "node",
"request": "launch",
"name": "Current Mocha TS File - Loki",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/node_modules/mocha/bin/_mocha",
"-u",
Expand All @@ -162,7 +211,7 @@
"AZURITE_ACCOUNTS": "",
"AZURE_TABLE_STORAGE": "",
"DATATABLES_ACCOUNT_NAME": "<name of your storage account>",
"DATATABLES_ACCOUNT_KEY" : "<account key for your storage account>",
"DATATABLES_ACCOUNT_KEY": "<account key for your storage account>",
"AZURE_DATATABLES_STORAGE_STRING": "https://<your account name>.table.core.windows.net",
"AZURE_DATATABLES_SAS": "?<sas query string>",
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
Expand All @@ -175,15 +224,18 @@
"request": "launch",
"name": "EXE Mocha TS File - Loki",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/node_modules/mocha/bin/_mocha",
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/tests/exe.test.ts",
"${workspaceFolder}/tests/exe.test.ts",
"--exit"
],
"env": {
Expand All @@ -199,7 +251,10 @@
"request": "launch",
"name": "Current Mocha TS File - SQL",
"cwd": "${workspaceFolder}",
"runtimeArgs": ["-r", "ts-node/register"],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/node_modules/mocha/bin/_mocha",
"-u",
Expand All @@ -211,7 +266,7 @@
],
"env": {
"AZURITE_ACCOUNTS": "",
"AZURITE_TEST_DB": "mysql://root:my-secret-pw@127.0.0.1:3306/azurite_blob_test",
"AZURITE_TEST_DB": "mysql://root:!!123abc@127.0.0.1:3306/azurite_blob",
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
},
"internalConsoleOptions": "openOnSessionStart",
Expand Down Expand Up @@ -250,9 +305,13 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
}
}
3 changes: 1 addition & 2 deletions src/blob/errors/StorageErrorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ export default class StorageErrorFactory {
{ ReceivedCopyStatus: copyStatus }
);
}


public static getInvalidMetadata(contextID: string): StorageError {
return new StorageError(
Expand Down Expand Up @@ -825,7 +824,7 @@ export default class StorageErrorFactory {
"The tags specified are invalid. It contains characters that are not permitted.",
contextID
);
}
}

public static getInvalidXmlDocument(
contextID: string = ""
Expand Down
43 changes: 42 additions & 1 deletion src/blob/handlers/ContainerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,48 @@ export default class ContainerHandler extends BaseHandler

public async filterBlobs(options: Models.ContainerFilterBlobsOptionalParams, context: Context
): Promise<Models.ContainerFilterBlobsResponse> {
throw new NotImplementedError(context.contextId!);
const blobCtx = new BlobStorageContext(context);
const accountName = blobCtx.account!;
const containerName = blobCtx.container!;
await this.metadataStore.checkContainerExist(
context,
accountName,
containerName
);

const request = context.request!;
const marker = options.marker;
options.marker = options.marker || "";
if (
options.maxresults === undefined ||
options.maxresults > DEFAULT_LIST_BLOBS_MAX_RESULTS
) {
options.maxresults = DEFAULT_LIST_BLOBS_MAX_RESULTS;
}

const [blobs, nextMarker] = await this.metadataStore.filterBlobs(
context,
accountName,
containerName,
options.where,
options.maxresults,
marker,
);

const serviceEndpoint = `${request.getEndpoint()}/${accountName}`;
const response: Models.ContainerFilterBlobsResponse = {
statusCode: 200,
requestId: context.contextId,
version: BLOB_API_VERSION,
date: context.startTime,
serviceEndpoint,
where: options.where!,
blobs: blobs,
clientRequestId: options.requestId,
nextMarker: `${nextMarker || ""}`
};

return response;
}

/**
Expand Down
42 changes: 38 additions & 4 deletions src/blob/handlers/ServiceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import IServiceHandler from "../generated/handlers/IServiceHandler";
import { parseXML } from "../generated/utils/xml";
import {
BLOB_API_VERSION,
DEFAULT_LIST_BLOBS_MAX_RESULTS,
DEFAULT_LIST_CONTAINERS_MAX_RESULTS,
EMULATOR_ACCOUNT_ISHIERARCHICALNAMESPACEENABLED,
EMULATOR_ACCOUNT_KIND,
Expand All @@ -22,8 +23,7 @@ import { Readable } from "stream";
import { OAuthLevel } from "../../common/models";
import { BEARER_TOKEN_PREFIX } from "../../common/utils/constants";
import { decode } from "jsonwebtoken";
import { getUserDelegationKeyValue } from "../utils/utils";
import NotImplementedError from "../errors/NotImplementedError";
import { getUserDelegationKeyValue } from "../utils/utils"

/**
* ServiceHandler handles Azure Storage Blob service related requests.
Expand Down Expand Up @@ -373,10 +373,44 @@ export default class ServiceHandler extends BaseHandler
return this.getAccountInfo(context);
}

public filterBlobs(
public async filterBlobs(
options: Models.ServiceFilterBlobsOptionalParams,
context: Context
): Promise<Models.ServiceFilterBlobsResponse> {
throw new NotImplementedError(context.contextId);
const blobCtx = new BlobStorageContext(context);
const accountName = blobCtx.account!;

const request = context.request!;
const marker = options.marker;
options.marker = options.marker || "";
if (
options.maxresults === undefined ||
options.maxresults > DEFAULT_LIST_BLOBS_MAX_RESULTS
) {
options.maxresults = DEFAULT_LIST_BLOBS_MAX_RESULTS;
}

const [blobs, nextMarker] = await this.metadataStore.filterBlobs(
context,
accountName,
undefined,
options.where,
options.maxresults,
marker,
);

const serviceEndpoint = `${request.getEndpoint()}/${accountName}`;
const response: Models.ServiceFilterBlobsResponse = {
statusCode: 200,
requestId: context.contextId,
version: BLOB_API_VERSION,
date: context.startTime,
serviceEndpoint,
where: options.where!,
blobs: blobs,
clientRequestId: options.requestId,
nextMarker: `${nextMarker || ""}`
};
return response;
}
}
Loading

0 comments on commit f6ba562

Please sign in to comment.