From 0b10d1a3519edb1cbdefb18c67e58fee42b75041 Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Tue, 11 Dec 2018 17:15:26 -0800 Subject: [PATCH 1/6] Fixes the following issues : Unhandled error if you cancel saving Azure log #639 Save Azure log dialog shows "log..log" as the filename extension #640 docker.acr.pullimage issue #648 --- .../acr-logs-utils/logFileManager.ts | 9 ++++++++- .../acr-logs-utils/tableViewManager.ts | 16 +++++++--------- commands/azureCommands/pull-from-azure.ts | 7 +++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/commands/azureCommands/acr-logs-utils/logFileManager.ts b/commands/azureCommands/acr-logs-utils/logFileManager.ts index 93bb31810f..07147b0e4e 100644 --- a/commands/azureCommands/acr-logs-utils/logFileManager.ts +++ b/commands/azureCommands/acr-logs-utils/logFileManager.ts @@ -1,6 +1,8 @@ import { BlobService, createBlobServiceWithSas } from 'azure-storage'; import * as fse from 'fs-extra'; +import { isNullOrUndefined } from 'util'; import * as vscode from 'vscode'; +import { UserCancelledError } from 'vscode-azureextensionui'; import { getBlobInfo, getBlobToText, IBlobInfo } from '../../../utils/Azure/acrTools'; export class LogContentProvider implements vscode.TextDocumentContentProvider { @@ -55,9 +57,14 @@ function openLogInNewWindow(content: string, title: string): void { export async function downloadLog(content: string, title: string): Promise { let uri = await vscode.window.showSaveDialog({ - filters: { 'Log': ['.log', '.txt'] }, + filters: { 'Log': ['log', 'txt'] }, defaultUri: vscode.Uri.file(`${title}.log`) }); + + if (isNullOrUndefined(uri)) { + throw new UserCancelledError("Operation cancelled."); + } + fse.writeFile( uri.fsPath, content, diff --git a/commands/azureCommands/acr-logs-utils/tableViewManager.ts b/commands/azureCommands/acr-logs-utils/tableViewManager.ts index 94ee74c34f..5eddcd1a3e 100644 --- a/commands/azureCommands/acr-logs-utils/tableViewManager.ts +++ b/commands/azureCommands/acr-logs-utils/tableViewManager.ts @@ -3,7 +3,7 @@ import { ImageDescriptor, Run } from "azure-arm-containerregistry/lib/models"; import * as clipboardy from 'clipboardy' import * as path from 'path'; import * as vscode from "vscode"; -import { parseError } from "vscode-azureextensionui"; +import { callWithTelemetryAndErrorHandling } from "vscode-azureextensionui"; import { ext } from "../../../extensionVariables"; import { accessLog } from './logFileManager'; import { Filter, LogData } from './tableDataManager' @@ -31,20 +31,18 @@ export class LogTableWebview { this.panel.webview.onDidReceiveMessage(async (message: IMessage) => { if (message.logRequest) { const itemNumber: number = +message.logRequest.id; - try { - await this.logData.getLink(itemNumber).then(async (url) => { + await callWithTelemetryAndErrorHandling( + 'accessLogFromTable', + async () => await this.logData.getLink(itemNumber).then(async (url) => { if (url !== 'requesting') { await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download); } - }); - } catch (err) { - const error = parseError(err); - vscode.window.showErrorMessage(`Error '${error.errorType}': ${error.message}`); - } + }) + ); } else if (message.copyRequest) { // tslint:disable-next-line:no-unsafe-any clipboardy.writeSync(message.copyRequest.text); - + vscode.window.showInformationMessage("The digest was successfully copied to the clipboard."); } else if (message.loadMore) { const alreadyLoaded = this.logData.logs.length; await this.logData.loadLogs({ diff --git a/commands/azureCommands/pull-from-azure.ts b/commands/azureCommands/pull-from-azure.ts index 666c384510..0445742b42 100644 --- a/commands/azureCommands/pull-from-azure.ts +++ b/commands/azureCommands/pull-from-azure.ts @@ -7,6 +7,7 @@ import * as assert from 'assert'; import { Registry } from "azure-arm-containerregistry/lib/models"; import { exec } from 'child_process'; import * as fse from 'fs-extra'; +import os = require('os'); import * as path from "path"; import vscode = require('vscode'); import { callWithTelemetryAndErrorHandling, IActionContext } from 'vscode-azureextensionui'; @@ -59,8 +60,6 @@ async function pullFromAzure(context: AzureImageTagNode | AzureRepositoryNode, p async function pullImage(loginServer: string, imageRequest: string, username: string, password: string): Promise { // We can't know if the key is still active. So we login into Docker and send appropriate commands to terminal - let dockerConfigPath: string = path.join(process.env.HOMEPATH, '.docker', 'config.json'); - await new Promise((resolve, reject) => { const dockerLoginCmd = `docker login ${loginServer} --username ${username} --password-stdin`; let childProcess = exec(dockerLoginCmd, (err, stdout, stderr) => { @@ -71,7 +70,7 @@ async function pullImage(loginServer: string, imageRequest: string, username: st // Temporary work-around for this error- same as Azure CLI // See https://github.com/Azure/azure-cli/issues/4843 ext.outputChannel.show(); - reject(new Error(`In order to log in to the Docker CLI using tokens, you currently need to go to \n${dockerConfigPath} and remove "credsStore": "wincred" from the config.json file, then try again. \nDoing this will disable wincred and cause Docker to store credentials directly in the .docker/config.json file. All registries that are currently logged in will be effectly logged out.`)); + reject(new Error(`In order to log in to the Docker CLI using tokens, you currently need to go to \nOpen your Docker config file and remove "credsStore": "wincred" from the config.json file, then try again. \nDoing this will disable wincred and cause Docker to store credentials directly in the .docker/config.json file. All registries that are currently logged in will be effectly logged out.`)); } else if (err) { ext.outputChannel.show(); reject(err); @@ -94,7 +93,7 @@ async function pullImage(loginServer: string, imageRequest: string, username: st } async function isLoggedIntoDocker(loginServer: string): Promise<{ configPath: string, loggedIn: boolean }> { - let home = process.env.HOMEPATH; + const home = os.homedir(); let configPath: string = path.join(home, '.docker', 'config.json'); let buffer: Buffer; From 01f877fc53528742decfd22edcb553977f9cb236 Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Wed, 12 Dec 2018 11:35:09 -0800 Subject: [PATCH 2/6] fixes #666 --- commands/utils/SourceArchiveUtility.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/commands/utils/SourceArchiveUtility.ts b/commands/utils/SourceArchiveUtility.ts index 7523aa1985..c9aa60d203 100644 --- a/commands/utils/SourceArchiveUtility.ts +++ b/commands/utils/SourceArchiveUtility.ts @@ -98,7 +98,15 @@ async function uploadSourceCode(client: ContainerRegistryManagementClient, regis ext.outputChannel.appendLine(" Creating blob service "); let blob: BlobService = createBlobServiceWithSas(blobInfo.host, blobInfo.sasToken); ext.outputChannel.appendLine(" Creating block blob "); - blob.createBlockBlobFromLocalFile(blobInfo.containerName, blobInfo.blobName, tarFilePath, (): void => { }); + await new Promise((resolve, reject) => { + blob.createBlockBlobFromLocalFile(blobInfo.containerName, blobInfo.blobName, tarFilePath, (error, result, response): void => { + if (error) { + reject(error); + } else { + resolve({ result, response }); + } + }); + }); return relative_path; } From 4aa514dc0376d4bb82c12bcd51d2b579809462e9 Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Wed, 12 Dec 2018 12:11:52 -0800 Subject: [PATCH 3/6] PR #705 Fixes --- .../acr-logs-utils/tableViewManager.ts | 59 ++++++++++--------- dockerExtension.ts | 2 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/commands/azureCommands/acr-logs-utils/tableViewManager.ts b/commands/azureCommands/acr-logs-utils/tableViewManager.ts index 5eddcd1a3e..f75d832fd7 100644 --- a/commands/azureCommands/acr-logs-utils/tableViewManager.ts +++ b/commands/azureCommands/acr-logs-utils/tableViewManager.ts @@ -29,37 +29,38 @@ export class LogTableWebview { /** Setup communication with the webview sorting out received mesages from its javascript file */ private setupIncomingListeners(): void { this.panel.webview.onDidReceiveMessage(async (message: IMessage) => { - if (message.logRequest) { - const itemNumber: number = +message.logRequest.id; - await callWithTelemetryAndErrorHandling( - 'accessLogFromTable', - async () => await this.logData.getLink(itemNumber).then(async (url) => { - if (url !== 'requesting') { - await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download); - } - }) - ); - } else if (message.copyRequest) { - // tslint:disable-next-line:no-unsafe-any - clipboardy.writeSync(message.copyRequest.text); - vscode.window.showInformationMessage("The digest was successfully copied to the clipboard."); - } else if (message.loadMore) { - const alreadyLoaded = this.logData.logs.length; - await this.logData.loadLogs({ - webViewEvent: true, - loadNext: true - }); - this.addLogsToWebView(alreadyLoaded); + await callWithTelemetryAndErrorHandling( + 'ACR-logsTableListeners', + async () => { + if (message.logRequest) { + const itemNumber: number = +message.logRequest.id; + await this.logData.getLink(itemNumber).then(async (url) => { + if (url !== 'requesting') { + await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download); + } + }); + } else if (message.copyRequest) { + // tslint:disable-next-line:no-unsafe-any + clipboardy.writeSync(message.copyRequest.text); + vscode.window.showInformationMessage("The digest was successfully copied to the clipboard."); + } else if (message.loadMore) { + const alreadyLoaded = this.logData.logs.length; + await this.logData.loadLogs({ + webViewEvent: true, + loadNext: true + }); + this.addLogsToWebView(alreadyLoaded); - } else if (message.loadFiltered) { - await this.logData.loadLogs({ - webViewEvent: true, - loadNext: false, - removeOld: true, - filter: message.loadFiltered.filterString + } else if (message.loadFiltered) { + await this.logData.loadLogs({ + webViewEvent: true, + loadNext: false, + removeOld: true, + filter: message.loadFiltered.filterString + }); + this.addLogsToWebView(); + } }); - this.addLogsToWebView(); - } }); } diff --git a/dockerExtension.ts b/dockerExtension.ts index c367f60ec9..19a2079eb0 100644 --- a/dockerExtension.ts +++ b/dockerExtension.ts @@ -10,7 +10,7 @@ import { CoreOptions } from 'request'; import * as request from 'request-promise-native'; import { RequestPromise } from 'request-promise-native'; import * as vscode from 'vscode'; -import { AzureUserInput, callWithTelemetryAndErrorHandling, callWithTelemetryAndErrorHandlingSync, createTelemetryReporter, IActionContext, registerCommand as uiRegisterCommand, registerUIExtensionVariables, TelemetryProperties, UserCancelledError } from 'vscode-azureextensionui'; +import { AzureUserInput, callWithTelemetryAndErrorHandling, createTelemetryReporter, IActionContext, registerCommand as uiRegisterCommand, registerUIExtensionVariables, TelemetryProperties, UserCancelledError } from 'vscode-azureextensionui'; import { ConfigurationParams, DidChangeConfigurationNotification, DocumentSelector, LanguageClient, LanguageClientOptions, Middleware, ServerOptions, TransportKind } from 'vscode-languageclient/lib/main'; import { viewACRLogs } from "./commands/azureCommands/acr-logs"; import { LogContentProvider } from "./commands/azureCommands/acr-logs-utils/logFileManager"; From 0011f46ea6ca1903774da8999f265542a06d8347 Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Wed, 12 Dec 2018 17:23:22 -0800 Subject: [PATCH 4/6] Adds telemitry to the ACR logs table listeners --- .../acr-logs-utils/tableViewManager.ts | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/commands/azureCommands/acr-logs-utils/tableViewManager.ts b/commands/azureCommands/acr-logs-utils/tableViewManager.ts index f75d832fd7..6e8c163629 100644 --- a/commands/azureCommands/acr-logs-utils/tableViewManager.ts +++ b/commands/azureCommands/acr-logs-utils/tableViewManager.ts @@ -29,29 +29,41 @@ export class LogTableWebview { /** Setup communication with the webview sorting out received mesages from its javascript file */ private setupIncomingListeners(): void { this.panel.webview.onDidReceiveMessage(async (message: IMessage) => { - await callWithTelemetryAndErrorHandling( - 'ACR-logsTableListeners', - async () => { - if (message.logRequest) { + if (message.logRequest) { + await callWithTelemetryAndErrorHandling( + 'ACRLogs-accessLogs', + async () => { + const itemNumber: number = +message.logRequest.id; await this.logData.getLink(itemNumber).then(async (url) => { if (url !== 'requesting') { await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download); } }); - } else if (message.copyRequest) { + }); + } else if (message.copyRequest) { + await callWithTelemetryAndErrorHandling( + 'ACRLogs-copyDigest', + async () => { // tslint:disable-next-line:no-unsafe-any clipboardy.writeSync(message.copyRequest.text); vscode.window.showInformationMessage("The digest was successfully copied to the clipboard."); - } else if (message.loadMore) { + }); + } else if (message.loadMore) { + await callWithTelemetryAndErrorHandling( + 'ACRLogs-loadMore', + async () => { const alreadyLoaded = this.logData.logs.length; await this.logData.loadLogs({ webViewEvent: true, loadNext: true }); this.addLogsToWebView(alreadyLoaded); - - } else if (message.loadFiltered) { + }); + } else if (message.loadFiltered) { + await callWithTelemetryAndErrorHandling( + 'ACRLogs-filterTable', + async () => { await this.logData.loadLogs({ webViewEvent: true, loadNext: false, @@ -59,8 +71,8 @@ export class LogTableWebview { filter: message.loadFiltered.filterString }); this.addLogsToWebView(); - } - }); + }); + } }); } From fd9b688465983271879d1fe89fcd29fab7b1fd69 Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Fri, 14 Dec 2018 17:32:28 -0800 Subject: [PATCH 5/6] Fixes #662 --- style/acr-logs/stylesheet.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/style/acr-logs/stylesheet.css b/style/acr-logs/stylesheet.css index 112a760315..a61c338b53 100644 --- a/style/acr-logs/stylesheet.css +++ b/style/acr-logs/stylesheet.css @@ -324,8 +324,8 @@ main { .tooltip .tooltiptext { box-sizing: border-box; display: none; - background-color: var(--vscode-editor-foreground); - color: var(--vscode-activityBar-background); + background-color: var(--vscode-list-hoverBackground); + color: var(--vscode-list-foreground); text-align: center; padding: 5px 16px; position: absolute; From d82fe9988c2e7b2caa58420a94a8949ae70f187a Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Thu, 31 Jan 2019 15:45:23 -0800 Subject: [PATCH 6/6] Minor ACR casing fixes --- commands/azureCommands/delete-image.ts | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commands/azureCommands/delete-image.ts b/commands/azureCommands/delete-image.ts index a92a3b8576..a09104c2ec 100644 --- a/commands/azureCommands/delete-image.ts +++ b/commands/azureCommands/delete-image.ts @@ -33,13 +33,14 @@ export async function untagAzureImage(context?: AzureImageTagNode): Promise