Skip to content

Commit

Permalink
ACR Fixes (Logs & Docker Pull) (#705)
Browse files Browse the repository at this point in the history
* 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

* fixes #666

* PR #705 Fixes

* Adds telemitry to the ACR logs table listeners
  • Loading branch information
rosanch authored and StephenWeatherford committed Dec 13, 2018
1 parent 84ff3fb commit e1d6d42
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 35 deletions.
9 changes: 8 additions & 1 deletion commands/azureCommands/acr-logs-utils/logFileManager.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -55,9 +57,14 @@ function openLogInNewWindow(content: string, title: string): void {

export async function downloadLog(content: string, title: string): Promise<void> {
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,
Expand Down
67 changes: 39 additions & 28 deletions commands/azureCommands/acr-logs-utils/tableViewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,37 +30,48 @@ export class LogTableWebview {
private setupIncomingListeners(): void {
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) => {
if (url !== 'requesting') {
await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download);
}
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);
}
});
});
} 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);

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) {
const alreadyLoaded = this.logData.logs.length;
await this.logData.loadLogs({
webViewEvent: true,
loadNext: true
});
this.addLogsToWebView(alreadyLoaded);

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) {
await this.logData.loadLogs({
webViewEvent: true,
loadNext: false,
removeOld: true,
filter: message.loadFiltered.filterString
});
this.addLogsToWebView();
await callWithTelemetryAndErrorHandling(
'ACRLogs-filterTable',
async () => {
await this.logData.loadLogs({
webViewEvent: true,
loadNext: false,
removeOld: true,
filter: message.loadFiltered.filterString
});
this.addLogsToWebView();
});
}
});
}
Expand Down
7 changes: 3 additions & 4 deletions commands/azureCommands/pull-from-azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -59,8 +60,6 @@ async function pullFromAzure(context: AzureImageTagNode | AzureRepositoryNode, p

async function pullImage(loginServer: string, imageRequest: string, username: string, password: string): Promise<void> {
// 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) => {
Expand All @@ -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);
Expand All @@ -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;

Expand Down
10 changes: 9 additions & 1 deletion commands/utils/SourceArchiveUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion dockerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e1d6d42

Please sign in to comment.