Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/commands/password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { commands, Disposable, ExtensionContext, extensions, l10n, ProgressLocat
import Instance from "../Instance";
import { Password } from "../api/password";
import { getStoredPassword, setStoredPassword } from "../config/passwords";
import { getPassword } from "../extension";
import { CustomUI } from "../webviews/CustomUI";

const access: {
Expand Down Expand Up @@ -35,7 +36,7 @@ export function registerPasswordCommands(context: ExtensionContext, instance: In
commands.registerCommand(`code-for-ibmi.getPassword.disable`, () => {
access.enabled = false;
}),
commands.registerCommand(`code-for-ibmi.getPassword`, async (extensionId: string, reason?: string) => {
commands.registerCommand(`code-for-ibmi.getPassword`, async (extensionId: string, reason?: string, prompt?:string) => {
if (access.enabled && extensionId) {
const extension = extensions.getExtension(extensionId);
const isValid = (extension && extension.isActive);
Expand All @@ -51,7 +52,7 @@ export function registerPasswordCommands(context: ExtensionContext, instance: In
throw new Error(`Password request denied for extension ${displayName}.`);
}

const storedPassword = await getStoredPassword(context, instance.getConnection()!.currentConnectionName);
const storedPassword = await getPassword(instance.getConnection()!, prompt || `IBM i password requeted by ${displayName}`);

if (storedPassword) {
let isAuthed = storage.getExtensionAuthorisation(extension.id) !== undefined;
Expand Down
34 changes: 5 additions & 29 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import { ILELibrarySettings } from "../api/CompileTools";
import { getDebugServiceDetails, ORIGINAL_DEBUG_CONFIG_FILE, resetDebugServiceDetails } from "../api/configuration/DebugConfiguration";
import IBMi from "../api/IBMi";
import { getStoredPassword } from "../config/passwords";
import { clearPassword, getPassword } from "../extension";
import { Env, getEnvConfig } from "../filesystems/local/env";
import { instance } from "../instantiate";
import { ObjectItem } from "../typings";
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function initialize(context: ExtensionContext) {
if (connection) {
const config = connection.getConfig();
if (connection.remoteFeatures[`startDebugService.sh`]) {
const password = await getPassword();
const password = await getPassword(connection, `Password for user profile ${connection.currentUser} is required to debug. Password is not stored on device, but is stored temporarily for this connection.`);

const libraries: ILELibrarySettings = {
currentLibrary: config?.currentLibrary,
Expand Down Expand Up @@ -174,28 +174,6 @@ export async function initialize(context: ExtensionContext) {
return qualifiedPath;
}

const getPassword = async () => {
const connection = instance.getConnection();

let password = await getStoredPassword(context, connection!.currentConnectionName);

if (!password) {
password = temporaryPassword;
}

if (!password) {
password = await vscode.window.showInputBox({
password: true,
prompt: `Password for user profile ${connection!.currentUser} is required to debug. Password is not stored on device, but is stored temporarily for this connection.`
});

// Store for later
temporaryPassword = password;
}

return password;
}

const validateWorkspaceFolder = (maybeFolder?: vscode.WorkspaceFolder) => {
if (maybeFolder && "uri" in maybeFolder && "name" in maybeFolder && "index" in maybeFolder) {
return maybeFolder;
Expand Down Expand Up @@ -382,7 +360,7 @@ export async function startDebug(instance: Instance, options: DebugOptions) {
const port = config?.debugPort;
const updateProductionFiles = config?.debugUpdateProductionFiles;
const enableDebugTracing = config?.debugEnableDebugTracing;
const debugIgnoreCertificateErrors= config?.debugIgnoreCertificateErrors;
const debugIgnoreCertificateErrors = config?.debugIgnoreCertificateErrors;

let secure = true;

Expand Down Expand Up @@ -447,10 +425,8 @@ export async function startDebug(instance: Instance, options: DebugOptions) {

if (debugResult) {
connectionConfirmed = true;
} else {
if (!connectionConfirmed) {
temporaryPassword = undefined;
}
} else if (!connectionConfirmed) {
clearPassword();
}
}
}
Expand Down
26 changes: 21 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import { initializeSandbox, sandboxURIHandler } from "./uri/handlers/sandbox";
import { CustomUI } from "./webviews/CustomUI";
import { SettingsUI } from "./webviews/settings";

let temporaryPassword: string | undefined;
export let getPassword: (connection: IBMi, prompt: string) => Promise<string | undefined>;
export const setTemporaryPassword = (password:string) => temporaryPassword = password;
export const clearPassword = () => temporaryPassword = undefined;

export async function activate(context: ExtensionContext): Promise<CodeForIBMi> {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
Expand Down Expand Up @@ -125,12 +130,23 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
commands.executeCommand("code-for-ibmi.environment.refresh");
});

getPassword = async (connection, prompt) => {
let password = temporaryPassword ?? await getStoredPassword(context, connection.currentConnectionName);

if (password) {
return password;
}

return temporaryPassword = await window.showInputBox({
password: true,
prompt
});
}

instance.subscribe(context, "disconnected", "Clear temporary password", clearPassword);

const mapepire = new Mapepire(path.join(context.extensionPath, `dist`), async (connection) => {
return await getStoredPassword(context, connection.currentConnectionName) ||
await window.showInputBox({
password: true,
prompt: l10n.t(`Password for user profile {0} on {1} is required to connect to Mapepire Server.`, connection.currentUser, connection.currentConnectionName)
});
return await getPassword(connection, l10n.t(`Password for user profile {0} on {1} is required to connect to Mapepire Server.`, connection.currentUser, connection.currentConnectionName));
});
extensionComponentRegistry.registerComponent(context, mapepire);

Expand Down
4 changes: 3 additions & 1 deletion src/webviews/login/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import vscode, { l10n, ThemeIcon } from "vscode";
import IBMi from "../../api/IBMi";
import { Tools } from "../../api/Tools";
import { deleteStoredPassword, deleteStoredPassphrase, getStoredPassphrase, getStoredPassword, setStoredPassphrase, setStoredPassword } from "../../config/passwords";
import { deleteStoredPassphrase, deleteStoredPassword, getStoredPassphrase, getStoredPassword, setStoredPassphrase, setStoredPassword } from "../../config/passwords";
import { setTemporaryPassword } from "../../extension";
import { instance, safeDisconnect } from "../../instantiate";
import { ConnectionData } from '../../typings';
import { CustomUI, Section } from "../CustomUI";
Expand Down Expand Up @@ -228,6 +229,7 @@ async function promptPassword(connection: ConnectionData) {
savePassword = true;
}
connection.password = passwordBox.value;
setTemporaryPassword(passwordBox.value);
passwordBox.dispose();
};
passwordBox.onDidTriggerButton(onClose);
Expand Down
Loading