mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 17:23:02 -05:00
* linting * added flags * remove testing values * format * format doc * tested in linux * remove unused interface * comments * review comments * clean imports * pr comments * format doc * changed promise location * insiders december * pr comments * test ado change * fix test * comment out code for hygiene * remove unused imports * test creds from client only * remove unused import * trying enabling keytar * trying enabling keytar * disable in correct script * print statements * remove print statements * check mock output * add linux check * remove print statements
58 lines
2.1 KiB
TypeScript
58 lines
2.1 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { SqlOpsDataClient, ClientOptions } from 'dataprotocol-client';
|
|
import { IConfig } from '@microsoft/ads-service-downloader';
|
|
import { ServerOptions, TransportKind } from 'vscode-languageclient';
|
|
import * as Constants from './constants';
|
|
import * as Utils from '../utils';
|
|
import { SqlCredentialService } from './sqlCredentialService';
|
|
import { AppContext } from '../appContext';
|
|
|
|
/**
|
|
* Implements a credential storage for Windows, Mac (darwin), or Linux.
|
|
*
|
|
* Allows a single credential to be stored per service (that is, one username per service);
|
|
*/
|
|
export class CredentialStore {
|
|
private _client: SqlOpsDataClient;
|
|
private _config: IConfig;
|
|
private _logPath: string;
|
|
|
|
constructor(
|
|
private context: AppContext,
|
|
baseConfig: IConfig
|
|
) {
|
|
if (baseConfig) {
|
|
this._config = JSON.parse(JSON.stringify(baseConfig));
|
|
this._config.executableFiles = ['MicrosoftSqlToolsCredentials.exe', 'MicrosoftSqlToolsCredentials'];
|
|
}
|
|
this.context = context;
|
|
this._logPath = this.context.extensionContext.logPath;
|
|
}
|
|
|
|
public async start(): Promise<void> {
|
|
let clientOptions: ClientOptions = {
|
|
providerId: Constants.providerId,
|
|
features: [SqlCredentialService.asFeature(this.context)]
|
|
};
|
|
const serverPath = await Utils.getOrDownloadServer(this._config);
|
|
const serverOptions = this.generateServerOptions(serverPath);
|
|
this._client = new SqlOpsDataClient(Constants.serviceName, serverOptions, clientOptions);
|
|
this._client.start();
|
|
}
|
|
|
|
async dispose(): Promise<void> {
|
|
if (this._client) {
|
|
await this._client.stop();
|
|
}
|
|
}
|
|
|
|
private generateServerOptions(executablePath: string): ServerOptions {
|
|
let launchArgs = Utils.getCommonLaunchArgsAndCleanupOldLogFiles(this._logPath, 'credentialstore.log', executablePath);
|
|
return { command: executablePath, args: launchArgs, transport: TransportKind.stdio };
|
|
}
|
|
}
|