mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Kusto extension for ADS (#11752)
* Kusto extension * Add kusto to extensions.ts * Remove objectExplorerNodeProvider * Removed some BDC items + CR cleanup * Cleanup unused strings in package.nls.json * Remove unused svgs, and some cleanup * Bringing objectExplorerNode back and hygiene changes * rename to KustoObjectExplorerNodeProvider * rename to KustoIconProvider * Cleanup SQL code * Fix compilation error * Clean up in objectExplorerNodeProvider folder * Some more clean up based on comments * apiWrapper add * changed to camelCase * Remove unused functions/files * Removed AgentServicesFeature * dacfx, cms, schemacompare clean up * Clean up and addressed few comments * Remove apWrapper from kusto extension * Addressed few comments * credentialstore and escapeexception changes * Added strict check for Kusto extension * Fix error and addressed comment * Saving Kusto files shoulf default to .kql * package.json changes * Fix objectExplorerNodeProvider * Amir/kusto fix (#11972) * Add the compiled extensions.js * Fix strict compile rules Co-authored-by: Monica Gupta <mogupt@microsoft.com> Co-authored-by: Amir Omidi <amomidi@microsoft.com>
This commit is contained in:
141
extensions/kusto/src/utils.ts
Normal file
141
extensions/kusto/src/utils.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
//TODO: This is the same file from mssql. Move this into a common place.
|
||||
import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as findRemoveSync from 'find-remove';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
const configTracingLevel = 'tracingLevel';
|
||||
const configLogRetentionMinutes = 'logRetentionMinutes';
|
||||
const configLogFilesRemovalLimit = 'logFilesRemovalLimit';
|
||||
const extensionConfigSectionName = 'kusto';
|
||||
|
||||
export function removeOldLogFiles(logPath: string, prefix: string): JSON {
|
||||
return findRemoveSync(logPath, { age: { seconds: getConfigLogRetentionSeconds() }, limit: getConfigLogFilesRemovalLimit() });
|
||||
}
|
||||
|
||||
export function getConfiguration(config: string = extensionConfigSectionName): vscode.WorkspaceConfiguration {
|
||||
return vscode.workspace.getConfiguration(extensionConfigSectionName);
|
||||
}
|
||||
|
||||
export function getConfigLogFilesRemovalLimit(): number | undefined {
|
||||
let config = getConfiguration();
|
||||
if (config && config[configLogFilesRemovalLimit]) {
|
||||
return Number((config[configLogFilesRemovalLimit]).toFixed(0));
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getConfigLogRetentionSeconds(): number | undefined {
|
||||
let config = getConfiguration();
|
||||
if (config && config[configLogRetentionMinutes]) {
|
||||
return Number((config[configLogRetentionMinutes] * 60).toFixed(0));
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getConfigTracingLevel(): string | undefined {
|
||||
let config = getConfiguration();
|
||||
if (config) {
|
||||
return config[configTracingLevel];
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function getLogFileName(prefix: string, pid: number): string {
|
||||
return `${prefix}_${pid}.log`;
|
||||
}
|
||||
|
||||
export function getCommonLaunchArgsAndCleanupOldLogFiles(logPath: string, fileName: string, executablePath: string): string[] {
|
||||
let launchArgs: string[] = [];
|
||||
launchArgs.push('--log-file');
|
||||
let logFile = path.join(logPath, fileName);
|
||||
launchArgs.push(logFile);
|
||||
|
||||
console.log(`logFile for ${path.basename(executablePath)} is ${logFile}`);
|
||||
console.log(`This process (ui Extenstion Host) is pid: ${process.pid}`);
|
||||
// Delete old log files
|
||||
let deletedLogFiles = removeOldLogFiles(logPath, fileName);
|
||||
console.log(`Old log files deletion report: ${JSON.stringify(deletedLogFiles)}`);
|
||||
let config = getConfigTracingLevel();
|
||||
if (config) {
|
||||
launchArgs.push('--tracing-level');
|
||||
launchArgs.push(config);
|
||||
}
|
||||
return launchArgs;
|
||||
}
|
||||
|
||||
export function ensure(target: object, key: string): any {
|
||||
if (target[key] === void 0) {
|
||||
target[key] = {} as any;
|
||||
}
|
||||
return target[key];
|
||||
}
|
||||
|
||||
export interface IPackageInfo {
|
||||
name: string;
|
||||
version: string;
|
||||
aiKey: string;
|
||||
}
|
||||
|
||||
export function getPackageInfo(packageJson: IPackageInfo): IPackageInfo | undefined {
|
||||
if (packageJson) {
|
||||
return {
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
aiKey: packageJson.aiKey
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function verifyPlatform(): Thenable<boolean> {
|
||||
if (os.platform() === 'darwin' && parseFloat(os.release()) < 16) {
|
||||
return Promise.resolve(false);
|
||||
} else {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
export function getErrorMessage(error: Error | any, removeHeader: boolean = false): string {
|
||||
let errorMessage: string = (error instanceof Error) ? error.message : error.toString();
|
||||
if (removeHeader) {
|
||||
errorMessage = removeErrorHeader(errorMessage);
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
export function removeErrorHeader(errorMessage: string): string {
|
||||
if (errorMessage && errorMessage !== '') {
|
||||
let header: string = 'Error:';
|
||||
if (errorMessage.startsWith(header)) {
|
||||
errorMessage = errorMessage.substring(header.length);
|
||||
}
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
export function isObjectExplorerContext(object: any): object is azdata.ObjectExplorerContext {
|
||||
return 'connectionProfile' in object && 'isConnectionNode' in object;
|
||||
}
|
||||
|
||||
export async function exists(path: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user