Skip to content

Commit

Permalink
Fixes the following issues :
Browse files Browse the repository at this point in the history
	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
  • Loading branch information
rosanch committed Dec 12, 2018
1 parent 34b4060 commit 0b10d1a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 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
16 changes: 7 additions & 9 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 Down Expand Up @@ -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({
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

0 comments on commit 0b10d1a

Please sign in to comment.