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

Update ⬆️ to newest Azure Storage SDK for blobs 🗄 #513

Merged
merged 18 commits into from
Dec 4, 2019
2,594 changes: 1,008 additions & 1,586 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@
"ms-vscode.azure-account"
],
"dependencies": {
"@azure/storage-blob": "^12.0.0",
"@types/mime": "^2.0.1",
"azure-arm-resource": "^3.1.1-preview",
"azure-arm-storage": "^5.1.1-preview",
Expand Down
45 changes: 28 additions & 17 deletions src/azureStorageExplorer/AzureStorageFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import * as querystring from "querystring";
import * as vscode from "vscode";
import { AzExtTreeItem, callWithTelemetryAndErrorHandling, IActionContext, parseError } from "vscode-azureextensionui";
import { ext } from "../extensionVariables";
import { BlobContainerTreeItem, IBlobContainerCreateChildContext } from "./blobContainers/blobContainerNode";
import { BlobDirectoryTreeItem } from "./blobContainers/BlobDirectoryTreeItem";
import { BlobContainerTreeItem } from "./blobContainers/blobContainerNode";
import { BlobDirectoryTreeItem } from "./blobContainers/blobDirectoryNode";
import { BlobTreeItem } from "./blobContainers/blobNode";
import { createBlockBlob, doesBlobExist, IBlobContainerCreateChildContext } from './blobContainers/blobUtils';
import { DirectoryTreeItem, IDirectoryDeleteContext } from "./fileShares/directoryNode";
import { FileTreeItem } from "./fileShares/fileNode";
import { FileShareTreeItem, IFileShareCreateChildContext } from "./fileShares/fileShareNode";
Expand Down Expand Up @@ -149,17 +150,9 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
});
});
} else {
let service: azureStorage.BlobService = treeItem.root.createBlobService();
let containerName: string = treeItem.container.name;
result = await new Promise<string | undefined>((resolve, reject) => {
service.getBlobToText(containerName, parsedUri.filePath, (error?: Error, text?: string) => {
if (!!error) {
reject(error);
} else {
resolve(text);
}
});
});
const blobClient = treeItem.root.createBlobClient(treeItem.container.name, parsedUri.filePath);
let downloaded = await blobClient.download();
result = await this.streamToString(downloaded.readableStreamBody);
}
} catch (error) {
let pe = parseError(error);
Expand Down Expand Up @@ -189,7 +182,7 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
if (treeItem instanceof FileShareTreeItem) {
childExists = await doesFileExist(parsedUri.baseName, treeItem, parsedUri.parentDirPath, treeItem.share);
} else {
childExists = await treeItem.doesBlobExist(parsedUri.filePath);
childExists = await doesBlobExist(treeItem, parsedUri.filePath);
}

if (!childExists && !options.create) {
Expand All @@ -204,7 +197,8 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
if (treeItem instanceof FileShareTreeItem) {
await updateFileFromText(parsedUri.parentDirPath, parsedUri.baseName, treeItem.share, treeItem.root, content.toString());
} else {
await treeItem.updateBlockBlobFromText(parsedUri.filePath, content.toString());
await createBlockBlob(treeItem, parsedUri.filePath, content.toString());

}
} else {
progress.report({ message: `Creating ${writeToFileShare ? 'file' : 'blob'} ${parsedUri.filePath}` });
Expand Down Expand Up @@ -240,7 +234,7 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
if (treeItem instanceof FileTreeItem || treeItem instanceof DirectoryTreeItem || treeItem instanceof BlobTreeItem || treeItem instanceof BlobDirectoryTreeItem) {
if (!(treeItem instanceof BlobDirectoryTreeItem)) {
// The deletion message from deleteTreeItem is not supressed for BlobDirectoryTreeItems so avoid duplicate notifications
// The deletion message from deleteTreeItem is not suppressed for BlobDirectoryTreeItems so avoid duplicate notifications
progress.report({ message: `Deleting ${parsedUri.filePath}` });
}

Expand All @@ -259,7 +253,7 @@ export class AzureStorageFS implements vscode.FileSystemProvider {

context.errorHandling.rethrow = true;
if (oldUriParsed.baseName === newUriParsed.baseName) {
// Set suppressDisplay true when trying to move the files because VS code will hanlde the error.
// Set suppressDisplay true when trying to move the files because VS code will handle the error.
context.errorHandling.suppressDisplay = true;
throw new Error('Moving folders or files not supported.');
} else {
Expand Down Expand Up @@ -408,6 +402,23 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
private isFileShareUri(uri: vscode.Uri): boolean {
return this.verifyUri(uri).query.indexOf('File Shares') > 0;
}

private async streamToString(readableStream: NodeJS.ReadableStream | undefined): Promise<string | undefined> {
if (!readableStream) {
return undefined;
}
return new Promise((resolve, reject) => {
const chunks: string[] = [];
readableStream.on("data", (data) => {
// tslint:disable-next-line: no-unsafe-any
chunks.push(data.toString());
});
readableStream.on("end", () => {
resolve(chunks.join(""));
});
readableStream.on("error", reject);
});
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/azureStorageExplorer/IStorageRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as azureStorageBlob from "@azure/storage-blob";
import * as azureStorage from "azure-storage";
import { ISubscriptionContext } from "vscode-azureextensionui";
import { StorageAccountWrapper } from "../components/storageWrappers";

export interface IStorageRoot extends ISubscriptionContext {
storageAccount: StorageAccountWrapper;
createBlobService(): azureStorage.BlobService;
createBlobServiceClient(): azureStorageBlob.BlobServiceClient;
createBlobContainerClient(containerName: string): azureStorageBlob.ContainerClient;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions seem like they shouldn't be here (except createBlobServiceClient) They all require specific information regarding the container and blob names, but this seems more like a general-purpose class for just leveraging the subscription information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to move them to blobUtils?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so. Eventually we'll have to have similar functions for File, Queue, and Table as well and this file seems like it'd get kind of messy in functionality.

createBlobClient(containerName: string, blobName: string): azureStorageBlob.BlobClient;
createBlockBlobClient(containerName: string, blobName: string): azureStorageBlob.BlockBlobClient;
createFileService(): azureStorage.FileService;
createQueueService(): azureStorage.QueueService;
createTableService(): azureStorage.TableService;
Expand Down
218 changes: 0 additions & 218 deletions src/azureStorageExplorer/blobContainers/BlobDirectoryTreeItem.ts

This file was deleted.

Loading