From 435fb27cc10a18e7ef5b2cf76f421eb33bc2c4fd Mon Sep 17 00:00:00 2001 From: nickyinluo Date: Mon, 8 Jan 2024 17:51:25 +0800 Subject: [PATCH] 1.introduce the context to get ext version and provider version. 2.adjust the getShell and getIntegratedShell to async to get the reqcli with provider version. 3.refactor the queryUserInfo method. 4.deactivate clear user when close vscode. 5.add warn msg when use without login. 6.reset terminal env when aksk is null. --- package.nls.json | 2 +- src/autocomplete/TerraformTipsProvider.ts | 28 +--- src/client/runner/terraformRunner.ts | 36 +++-- src/client/terminal/integratedShell.ts | 4 + src/client/terminal/terraformShellManager.ts | 44 +++--- src/commons/context.ts | 38 ++++- src/commons/customCmdRegister.ts | 12 +- src/commons/tencent/user/auth/credentail.ts | 1 - src/commons/tencent/user/index.ts | 138 ++++++++----------- src/extension.ts | 31 +++-- src/utils/settingUtils.ts | 2 +- src/views/login/loginExplorer.ts | 4 +- 12 files changed, 176 insertions(+), 164 deletions(-) diff --git a/package.nls.json b/package.nls.json index 60d4f54..582ee44 100644 --- a/package.nls.json +++ b/package.nls.json @@ -20,7 +20,7 @@ "TcTerraform.pickup.aksk.placeholder": "Tencent Cloud {0}", "TcTerraform.pickup.aksk.verify.empty": "{0} can not be empty", "TcTerraform.welcome": "Welcome to use Tencent Cloud Terraform extension, please wait for the page loading...", - "TcTerraform.msg.aksk.notfound": "Cannot find TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY, please sign in first!", + "TcTerraform.msg.aksk.notfound": "Cannot find user info, please sign in first!", "TcTerraform.login": "Login Tencent Cloud...", "TcTerraform.login.msg.success": "Logged into Tencent Cloud successfully.", "TcTerraform.login.msg.need.login": "Please log in Tencent Cloud first.", diff --git a/src/autocomplete/TerraformTipsProvider.ts b/src/autocomplete/TerraformTipsProvider.ts index 5293ff9..b9d6817 100644 --- a/src/autocomplete/TerraformTipsProvider.ts +++ b/src/autocomplete/TerraformTipsProvider.ts @@ -2,13 +2,10 @@ import { CompletionItemProvider, TextDocument, Position, CancellationToken, Comp // import resources from '../../config/tips/tiat-resources.json'; import * as _ from "lodash"; import * as vscode from 'vscode'; -import { executeCommandByExec } from "@/utils/cpUtils"; import * as fs from "fs"; import * as path from "path"; -import * as workspaceUtils from "@/utils/workspaceUtils"; -import * as TelemetryWrapper from "vscode-extension-telemetry-wrapper"; +import * as context from "@/commons/context"; -const LATEST_VERSION = "latest"; const versionPattern = /^v\d+(\.\d+){2}\.json$/; let topLevelTypes = ["output", "provider", "resource", "variable", "data"]; let topLevelRegexes = topLevelTypes.map(o => { @@ -422,26 +419,7 @@ function compareVersions(a, b) { // load resource config from json files based on the appropriate version async function loadResource(extPath: string): Promise { - let tfVersion: string; - const cwd = workspaceUtils.getActiveEditorPath(); - if (!cwd) { - TelemetryWrapper.sendError(Error("noWorkspaceSelected")); - console.error(`can not get path from active editor`); - } - - await executeCommandByExec("terraform version", cwd).then(output => { - let match = RegExp(/tencentcloudstack\/tencentcloud (v\d+\.\d+\.\d+)/).exec(output); - - if (match) { - tfVersion = match[1]; - } else { - // gives the latest JSON if not tf provider version found - tfVersion = LATEST_VERSION; - } - console.log(`tf provider version:[${tfVersion}], cwd:[${cwd}]`); - }).catch(error => { - console.error(`execute terraform version failed: ${error}`); - }); + const tfVersion = await context.getTfVersion(); let result: Tips | null = null; const tipsDir = path.join(extPath, 'config', 'tips'); @@ -461,4 +439,4 @@ async function loadResource(extPath: string): Promise { // vscode.window.showInformationMessage(`Loaded json. tf version:[${tfVersion}], json version:[${result.version}]`); return result; -} +} \ No newline at end of file diff --git a/src/client/runner/terraformRunner.ts b/src/client/runner/terraformRunner.ts index 5c8bdce..f5d75af 100644 --- a/src/client/runner/terraformRunner.ts +++ b/src/client/runner/terraformRunner.ts @@ -13,6 +13,7 @@ import { terraformShellManager } from "../terminal/terraformShellManager"; import { executeCommand } from "../../utils/cpUtils"; import * as settingUtils from "../../utils/settingUtils"; import { openUrlHintOrNotShowAgain } from "../../utils/uiUtils"; +import { localize } from "vscode-nls-i18n"; export class TerraformRunner extends BaseRunner { @@ -32,10 +33,12 @@ export class TerraformRunner extends BaseRunner { public async init(): Promise { console.debug("[DEBUG]#### TerraformRunner init begin."); - // this.setAKSK(); + if (!checkAKSK()) { + return "plan abort"; + } - terraformShellManager.getShell().runTerraformCmd(TerraformCommand.Version); - terraformShellManager.getShell().runTerraformCmd(TerraformCommand.Init); + (await terraformShellManager.getShell()).runTerraformCmd(TerraformCommand.Version); + (await terraformShellManager.getShell()).runTerraformCmd(TerraformCommand.Init); return "init success"; } @@ -43,9 +46,11 @@ export class TerraformRunner extends BaseRunner { public async executePlan(cwd: string, args: any): Promise { console.debug("[DEBUG]#### TerraformRunner executePlan begin."); - // this.setAKSK(); + if (!checkAKSK()) { + return "plan abort"; + } - terraformShellManager.getShell().runTerraformCmd(TerraformCommand.Plan); + (await terraformShellManager.getShell()).runTerraformCmd(TerraformCommand.Plan); return "plan success"; } @@ -112,7 +117,6 @@ export class TerraformRunner extends BaseRunner { setCheckTerraformCmd(false); }); } - return; } private async resetFileContent(tfFile: string, defaultContents: string) { @@ -126,15 +130,9 @@ export class TerraformRunner extends BaseRunner { public async resetTFState(resAddress: string) { console.debug("[DEBUG]#### TerraformRunner resetTFState begin."); - await terraformShellManager.getIntegratedShell(TerraformRunner.getInstance()) + await (await terraformShellManager.getIntegratedShell(TerraformRunner.getInstance())) .runTerraformCmd(TerraformCommand.State, ['rm', '-lock=false', resAddress]); } - - private setAKSK(runner?: any) { - const [ak, sk, region] = settingUtils.getAKSKandRegion(); - terraformShellManager.getIntegratedShell(runner).runNormalCmd("export TENCENTCLOUD_SECRET_ID=" + ak); - terraformShellManager.getIntegratedShell(runner).runNormalCmd("export TENCENTCLOUD_SECRET_KEY=" + sk); - } } export function getCheckTerraformCmd(): boolean { @@ -144,3 +142,15 @@ export function getCheckTerraformCmd(): boolean { export function setCheckTerraformCmd(checked: boolean): void { vscode.workspace.getConfiguration().update("tcTerraform.checkTerraformCmd", checked); } + +export function checkAKSK(): boolean { + const [secretId, secretKey, _] = settingUtils.getAKSKandRegion(); + + if (secretId === undefined || secretKey === undefined || secretId === null || secretKey === null || secretId === '' || secretKey === '') { + let msg = localize("TcTerraform.msg.aksk.notfound"); + console.error(msg); + vscode.window.showInformationMessage(msg); + return false; + } + return true; +} \ No newline at end of file diff --git a/src/client/terminal/integratedShell.ts b/src/client/terminal/integratedShell.ts index 6b07176..473e805 100644 --- a/src/client/terminal/integratedShell.ts +++ b/src/client/terminal/integratedShell.ts @@ -37,6 +37,10 @@ export class IntegratedShell extends BaseShell { this.env = ee; } + public getEnv() { + return this.env; + } + // Creates a png of terraform resource graph to visualize the resources under management. public async visualize(): Promise { console.debug("[DEBUG]#### IntegratedShell visualize begin."); diff --git a/src/client/terminal/terraformShellManager.ts b/src/client/terminal/terraformShellManager.ts index 4072fcf..028fc46 100644 --- a/src/client/terminal/terraformShellManager.ts +++ b/src/client/terminal/terraformShellManager.ts @@ -16,19 +16,17 @@ import * as settingUtils from "../../utils/settingUtils"; import { Constants } from "../../commons/constants"; export interface ITerraformShellManager { - getShell(): BaseShell; + getShell(): Promise; // getCloudShell(): TCCloudShell; - getIntegratedShell(runner?: any): IntegratedShell; + getIntegratedShell(runner?: any): Promise; dispose(): void; } - - class TerraformShellManager implements ITerraformShellManager { private static cloudShell = new TencentCloudShell(); private static integratedShell: IntegratedShell; - public getShell(): BaseShell { + public async getShell(): Promise { const isCloudShell: boolean = isTerminalSetToCloudShell(); TelemetryWrapper.addContextProperty("isCloudShell", isCloudShell.toString()); @@ -42,26 +40,36 @@ class TerraformShellManager implements ITerraformShellManager { return TerraformShellManager.cloudShell; } - public getIntegratedShell(runner?: any): IntegratedShell { + public async getIntegratedShell(runner?: any): Promise { if (!TerraformShellManager.integratedShell) { // set TencentCloud AKSK, Region and Client info - const [ak, sk, region] = settingUtils.getAKSKandRegion(); - const tfEnv = { - [Constants.REQUEST_CLIENT]: context.genRequestClient(), - [Constants.TENCENTCLOUD_SECRET_ID]: ak, - [Constants.TENCENTCLOUD_SECRET_KEY]: sk, - [Constants.TENCENTCLOUD_REGION]: region, - }; - // default runner is Terraformer - TerraformShellManager.integratedShell = new IntegratedShell(TerraformerRunner.getInstance(), tfEnv); - // specify runner - if (runner) { - TerraformShellManager.integratedShell = new IntegratedShell(runner, tfEnv); + await this.initIntegratedShell(runner); + } else { + const curEnv = TerraformShellManager.integratedShell.getEnv(); + // need to be reset if the current AKSK is undefined + if (!curEnv[Constants.TENCENTCLOUD_SECRET_ID] || !curEnv[Constants.TENCENTCLOUD_SECRET_KEY]) { + await this.initIntegratedShell(runner); } } return TerraformShellManager.integratedShell; } + private async initIntegratedShell(runner: any) { + const [ak, sk, region] = settingUtils.getAKSKandRegion(); + const reqCli = await context.genRequestClient(); + const tfEnv = { + [Constants.REQUEST_CLIENT]: reqCli, // set ReqCli for TIC Terminal + [Constants.TENCENTCLOUD_SECRET_ID]: ak, + [Constants.TENCENTCLOUD_SECRET_KEY]: sk, + [Constants.TENCENTCLOUD_REGION]: region, + }; + // default runner is Terraformer + TerraformShellManager.integratedShell = new IntegratedShell(TerraformerRunner.getInstance(), tfEnv); + if (runner) { + TerraformShellManager.integratedShell = new IntegratedShell(runner, tfEnv); + } + } + public dispose(): void { TerraformShellManager.cloudShell.dispose(); TerraformShellManager.integratedShell.dispose(); diff --git a/src/commons/context.ts b/src/commons/context.ts index ed78b8c..7b722bc 100644 --- a/src/commons/context.ts +++ b/src/commons/context.ts @@ -1,8 +1,13 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import { container } from './container'; import * as vscode from 'vscode'; +import * as workspaceUtils from "@/utils/workspaceUtils"; +import * as cpUtils from "@/utils/cpUtils"; +import * as TelemetryWrapper from "vscode-extension-telemetry-wrapper"; export const Context = Symbol('ExtensionContext'); -export const REQUEST_CLIENT_PREFIX = "Terraform-Vscode-";//Terraform-1.81.61@vscode"; +export const REQUEST_CLIENT_PREFIX = "Terraform-";//Terraform-1.81.61@vscode"; +const LATEST_VERSION = "latest"; export function bindExtensionContext(ctx: vscode.ExtensionContext) { container.bind(Context).toConstantValue(ctx); @@ -14,8 +19,33 @@ export function getExtensionVersion(): string { return currentVersion; } -export function genRequestClient(): string { - const currentVersion = getExtensionVersion(); - const reqCli = `${REQUEST_CLIENT_PREFIX}v${currentVersion}`; +export async function genRequestClient(): Promise { + const extVersion = getExtensionVersion(); + const tfVersion = await getTfVersion() || LATEST_VERSION; + const reqCli = `${REQUEST_CLIENT_PREFIX}${tfVersion}@vscode-v${extVersion}`; return reqCli; +} + +export async function getTfVersion(): Promise { + let tfVersion = ''; + const cwd = workspaceUtils.getActiveEditorPath(); + if (!cwd) { + TelemetryWrapper.sendError(Error("noWorkspaceSelected")); + console.error(`can not get path from active editor`); + } + + await cpUtils.executeCommandByExec("terraform version", cwd).then(output => { + let match = RegExp(/tencentcloudstack\/tencentcloud (v\d+\.\d+\.\d+)/).exec(output); + + if (match) { + tfVersion = match[1]; + } else { + // gives the latest JSON if not tf provider version found + tfVersion = LATEST_VERSION; + } + console.log(`[DEBUG]getTfVersion tf provider version:[${tfVersion}], cwd:[${cwd}]`); + }).catch(error => { + console.error(`execute terraform version failed: ${error}`); + }); + return tfVersion; } \ No newline at end of file diff --git a/src/commons/customCmdRegister.ts b/src/commons/customCmdRegister.ts index c23df1b..00c9d36 100644 --- a/src/commons/customCmdRegister.ts +++ b/src/commons/customCmdRegister.ts @@ -42,16 +42,16 @@ export function regHelpCommands() { } export function regResourceRelatedCommands() { - commands.registerCommand(cmds.executeTferImport, function (param: any) { - terraformShellManager.getIntegratedShell(TerraformerRunner.getInstance()).import(param, param.fileName); + commands.registerCommand(cmds.executeTferImport, async function (param: any) { + (await terraformShellManager.getIntegratedShell(TerraformerRunner.getInstance())).import(param, param.fileName); }); - commands.registerCommand("tcTerraform.init", function (param: any) { - terraformShellManager.getIntegratedShell(TerraformRunner.getInstance()).init(); + commands.registerCommand("tcTerraform.init", async function (param: any) { + (await terraformShellManager.getIntegratedShell(TerraformRunner.getInstance())).init(); }); - commands.registerCommand("tcTerraform.plan", function (param: any) { - terraformShellManager.getIntegratedShell(TerraformRunner.getInstance()).plan(param); + commands.registerCommand("tcTerraform.plan", async function (param: any) { + (await terraformShellManager.getIntegratedShell(TerraformRunner.getInstance())).plan(param); }); commands.registerCommand(resourceRefresh, function (param: any) { diff --git a/src/commons/tencent/user/auth/credentail.ts b/src/commons/tencent/user/auth/credentail.ts index eaddd8a..c948d50 100644 --- a/src/commons/tencent/user/auth/credentail.ts +++ b/src/commons/tencent/user/auth/credentail.ts @@ -2,7 +2,6 @@ import MultiStepInput from "../../../multiStepInput"; import { Credential } from "tencentcloud-sdk-nodejs/tencentcloud/common/interface"; import { localize } from "vscode-nls-i18n"; import constant from "../index"; -import * as vscode from "vscode"; export async function getCredentailByInput() { const defaultRegion = "ap-guangzhou"; diff --git a/src/commons/tencent/user/index.ts b/src/commons/tencent/user/index.ts index 5dff4ca..e19a40e 100644 --- a/src/commons/tencent/user/index.ts +++ b/src/commons/tencent/user/index.ts @@ -40,85 +40,15 @@ export namespace user { // only support aksk way right now if (aksk === pick) { const credential = await getCredentailByInput(); - const accessKey = credential.secretId; - const secretKey = credential.secretKey; - const region = credential.region; - - // get configuration - const config = workspace.getConfiguration(); - - // set in vscode configuration(setting.json) - await config.update('tcTerraform.properties.secretId', accessKey, ConfigurationTarget.Global) - .then(() => { - }, (error) => { - window.showErrorMessage('set secretId failed: ' + error); - }); - await config.update('tcTerraform.properties.secretKey', secretKey, ConfigurationTarget.Global) - .then(() => { - }, (error) => { - window.showErrorMessage('set secretKey failed: ' + error); - }); - await config.update('tcTerraform.properties.region', region, ConfigurationTarget.Global) - .then(() => { - }, (error) => { - window.showErrorMessage('set region failed: ' + error); - }); // set in system environment - process.env.TENCENTCLOUD_SECRET_ID = accessKey; - process.env.TENCENTCLOUD_SECRET_KEY = secretKey; - process.env.TENCENTCLOUD_REGION = region; + process.env.TENCENTCLOUD_SECRET_ID = credential.secretId; + process.env.TENCENTCLOUD_SECRET_KEY = credential.secretKey; + process.env.TENCENTCLOUD_REGION = credential.region; try { // query user info - const stsClient = await getStsClient(); - const reqCli = context.genRequestClient(); - stsClient.sdkVersion = reqCli; - console.log('[DEBUG]--------------------getStsClient:', stsClient); - // const stsClient = await getCommonClient("sts.tencentcloudapi.com", "2018-08-13"); - // const stsResp = await stsClient.request("GetCallerIdentity", req). - const stsResp = await stsClient?.GetCallerIdentity(null). - then( - (result) => { - console.debug('[DEBUG]--------------------------------GetCallerIdentity result:', result); - if (!result) { - throw new Error('[Warn] GetCallerIdentity result.TotalCount is 0.'); - } - return result; - }, - (err) => { - throw new Error(err); - } - ); - // ) as stsModels.GetCallerIdentityResponse; - - const camClient = await getCamClient(); - camClient.sdkVersion = reqCli; - console.log('[DEBUG]--------------------getCamClient:', camClient); - const camResp = await camClient?.GetUserAppId(null). - then( - (result) => { - console.debug('[DEBUG]--------------------------------GetUserAppId result:', result); - if (!result) { - throw new Error('[Warn] GetUserAppId result.TotalCount is 0.'); - } - return result; - }, - (err) => { - throw new Error(err); - } - ); - - // set user info - let userinfo: UserInfo = { - secretId: accessKey, - secretKey: secretKey, - uin: stsResp.PrincipalId ?? stsResp.UserId ?? "-", - type: stsResp.Type ?? "unknow", - appid: String(camResp.AppId) ?? "-", - arn: stsResp.Arn, - region: region ?? "unknow", - }; + const userinfo = await queryUserInfo(credential); setInfo(userinfo); } catch (err) { @@ -146,8 +76,6 @@ export namespace user { } await clearInfo(); - loginMgt.clearStatusBar(); - settingUtils.clearAKSKandRegion(); tree.refreshTreeData(); } @@ -227,8 +155,11 @@ export namespace user { export async function clearInfo() { const { secrets } = container.get(Context); - await secrets.delete(USER_INFO); + + loginMgt.clearStatusBar(); + settingUtils.clearAKSKandRegion(); + tree.refreshTreeData(); } @@ -242,6 +173,57 @@ export namespace user { return undefined; } + + export async function queryUserInfo(credential: any): Promise { + const stsClient = await getStsClient(); + const reqCli = await context.genRequestClient(); // set ReqCli for login scenario + stsClient.sdkVersion = reqCli; + console.log('[DEBUG]--------------------getStsClient:', stsClient); + // const stsClient = await getCommonClient("sts.tencentcloudapi.com", "2018-08-13"); + // const stsResp = await stsClient.request("GetCallerIdentity", req). + const stsResp = await stsClient?.GetCallerIdentity(null). + then( + (result) => { + console.debug('[DEBUG]--------------------------------GetCallerIdentity result:', result); + if (!result) { + throw new Error('[Warn] GetCallerIdentity result.TotalCount is 0.'); + } + return result; + }, + (err) => { + throw new Error(err); + } + ); + // ) as stsModels.GetCallerIdentityResponse; + const camClient = await getCamClient(); + camClient.sdkVersion = reqCli; + console.log('[DEBUG]--------------------getCamClient:', camClient); + const camResp = await camClient?.GetUserAppId(null). + then( + (result) => { + console.debug('[DEBUG]--------------------------------GetUserAppId result:', result); + if (!result) { + throw new Error('[Warn] GetUserAppId result.TotalCount is 0.'); + } + return result; + }, + (err) => { + throw new Error(err); + } + ); + + // set user info + let userinfo: user.UserInfo = { + secretId: credential.secretId, + secretKey: credential.secretKey, + uin: stsResp.PrincipalId ?? stsResp.UserId ?? "-", + type: stsResp.Type ?? "unknow", + appid: String(camResp.AppId ?? "-"), + arn: stsResp.Arn, + region: credential.region ?? "unknow", + }; + return userinfo; + } } -export default user; +export default user; \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index d539365..2320d1d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -17,6 +17,7 @@ import * as autocomplete from './autocomplete/TerraformExampleProvider'; import * as loginMgt from './views/login/loginMgt'; import * as context from './commons/context'; import { Constants } from './commons/constants'; +import user from "@/commons/tencent/user/index"; const TF_MODE: vscode.DocumentFilter = { language: 'terraform', scheme: 'file' }; const COMPATIBLE_MODE: vscode.DocumentFilter = { scheme: 'file' }; @@ -30,19 +31,19 @@ export async function activate(context: vscode.ExtensionContext) { await TerraformRunner.getInstance().checkInstalled(); await TerraformerRunner.getInstance().checkInstalled(); - // set request client - await setRequestClient(); + // set request client for all of Terminal + await setRequestClientOnTerminal(); // terraform cmd - context.subscriptions.push(vscode.commands.registerCommand('tcTerraform.apply', () => { - terraformShellManager.getShell().runTerraformCmd(TerraformCommand.Apply); + context.subscriptions.push(vscode.commands.registerCommand('tcTerraform.apply', async () => { + (await terraformShellManager.getShell()).runTerraformCmd(TerraformCommand.Apply); })); - context.subscriptions.push(vscode.commands.registerCommand('tcTerraform.refresh', () => { - terraformShellManager.getShell().runTerraformCmd(TerraformCommand.Refresh); + context.subscriptions.push(vscode.commands.registerCommand('tcTerraform.refresh', async () => { + (await terraformShellManager.getShell()).runTerraformCmd(TerraformCommand.Refresh); })); - context.subscriptions.push(vscode.commands.registerCommand('tcTerraform.destroy', () => { - terraformShellManager.getShell().runTerraformCmd(TerraformCommand.Destroy); + context.subscriptions.push(vscode.commands.registerCommand('tcTerraform.destroy', async () => { + (await terraformShellManager.getShell()).runTerraformCmd(TerraformCommand.Destroy); })); // git operations @@ -56,13 +57,13 @@ export async function activate(context: vscode.ExtensionContext) { // terraformer cmd let disposableTferImport = vscode.commands.registerCommand('tcTerraformer.import', async () => { - terraformShellManager.getShell().runTerraformCmd(TerraformerCommand.Import); + (await terraformShellManager.getShell()).runTerraformCmd(TerraformerCommand.Import); }); context.subscriptions.push(disposableTferImport); let disposableTferPlan = vscode.commands.registerCommand('tcTerraformer.plan', async () => { - terraformShellManager.getShell().runTerraformCmd(TerraformerCommand.Plan); + (await terraformShellManager.getShell()).runTerraformCmd(TerraformerCommand.Plan); }); context.subscriptions.push(disposableTferPlan); @@ -118,13 +119,13 @@ export async function activate(context: vscode.ExtensionContext) { } -async function setRequestClient() { +async function setRequestClientOnTerminal() { const config = vscode.workspace.getConfiguration('terminal.integrated.env'); const os = getOSPlatform(); const curConfig = config[os] || {}; - // env[Constants.REQUEST_CLIENT] = context.genRequestClient(); - const updatedConfig = { ...curConfig, [Constants.REQUEST_CLIENT]: context.genRequestClient() }; + const reqCli = await context.genRequestClient(); + const updatedConfig = { ...curConfig, [Constants.REQUEST_CLIENT]: reqCli }; // set ReqCli for all Terminal await config.update(os, updatedConfig, vscode.ConfigurationTarget.Global); } @@ -143,6 +144,6 @@ function getOSPlatform(): string { } // This method is called when your extension is deactivated -export function deactivate() { - +export async function deactivate() { + await user.clearInfo(); } diff --git a/src/utils/settingUtils.ts b/src/utils/settingUtils.ts index a9c6704..4008793 100644 --- a/src/utils/settingUtils.ts +++ b/src/utils/settingUtils.ts @@ -66,7 +66,7 @@ export function getAKSKandRegion(): [string, string, string] { const regionConfig = getRegionFromUI(); const regionEnv = getRegionFromEnv(); - return [secretIdConfig ?? secretIdEnv, secretKeyConfig ?? secretKeyEnv, regionConfig ?? regionEnv]; + return [secretIdConfig || secretIdEnv, secretKeyConfig || secretKeyEnv, regionConfig || regionEnv]; } export function clearAKSKandRegion() { diff --git a/src/views/login/loginExplorer.ts b/src/views/login/loginExplorer.ts index 1d99c5b..db9c106 100644 --- a/src/views/login/loginExplorer.ts +++ b/src/views/login/loginExplorer.ts @@ -19,7 +19,7 @@ export class LoginProvider extends tencent.tree.TreeDataProvider { async isLoggedIn(): Promise { if (getSecretIdFromEnv() && getSecretKeyFromEnv()) { - const userInfo = await user.getInfo() as user.UserInfo; + const userInfo = await user.getInfo(); if (!userInfo || !userInfo.secretId || userInfo.secretId === '') { return false; } @@ -31,7 +31,7 @@ export class LoginProvider extends tencent.tree.TreeDataProvider { async getChildren(element?: tencent.tree.TreeItem | undefined): Promise { let items: tencent.tree.TreeItem[] = []; if (!element) { - if (!this.isLoggedIn()) { + if (!await this.isLoggedIn()) { window.showInformationMessage(localize("TcTerraform.login.msg.need.login")); clearAKSKandRegion(); return items;