Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage custom C4iDebugService.env file to store Debug Service configuration #2417

Merged
merged 3 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion src/api/debug/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export async function setup(connection: IBMi, imported?: ImportedCertificate) {
}

export async function debugKeyFileExists(connection: IBMi, debugConfig: DebugConfiguration) {
return await connection.content.testStreamFile(`${debugConfig.getRemoteServiceWorkDir()}/.code4i.debug`, "f");
return await connection.getContent().testStreamFile(`${debugConfig.getRemoteServiceWorkDir()}/.code4i.debug`, "f");
}

export async function remoteCertificatesExists(debugConfig?: DebugConfiguration) {
Expand Down
21 changes: 17 additions & 4 deletions src/api/debug/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ type ConfigLine = {
key: string
value?: string
}
export const DEBUG_CONFIG_FILE = "/QIBM/ProdData/IBMiDebugService/bin/DebugService.env";

export const DEBUG_CONFIG_FILE = "/QIBM/UserData/IBMiDebugService/C4iDebugService.env";
export const ORIGINAL_DEBUG_CONFIG_FILE = "/QIBM/ProdData/IBMiDebugService/bin/DebugService.env";

export class DebugConfiguration {
constructor(private connection: IBMi) {}
constructor(private connection: IBMi) { }
readonly configLines: ConfigLine[] = [];
private readOnly = false;

private getContent() {
const content = this.connection.getContent();
Expand Down Expand Up @@ -49,7 +52,15 @@ export class DebugConfiguration {
}

async load() {
const content = (await this.getContent().downloadStreamfileRaw(DEBUG_CONFIG_FILE)).toString("utf-8");
//Since Debug Service 2.0.1: https://github.com/codefori/vscode-ibmi/issues/2416
if (!await this.getContent().testStreamFile(DEBUG_CONFIG_FILE, "r")) {
const copyResult = await this.connection.sendCommand({ command: `cp ${ORIGINAL_DEBUG_CONFIG_FILE} ${DEBUG_CONFIG_FILE} && chmod 755 ${DEBUG_CONFIG_FILE}` });
if (copyResult.code) {
this.readOnly = true;
}
}

const content = (await this.getContent().downloadStreamfileRaw(this.readOnly ? ORIGINAL_DEBUG_CONFIG_FILE : DEBUG_CONFIG_FILE)).toString("utf-8");
this.configLines.push(...content.split("\n")
.map(line => line.trim())
.map(line => {
Expand All @@ -69,7 +80,9 @@ export class DebugConfiguration {
}

async save() {
await this.getContent().writeStreamfileRaw(DEBUG_CONFIG_FILE, Buffer.from(this.configLines.map(line => `${line.key}${line.value !== undefined ? `=${line.value}` : ''}`).join("\n"), `utf8`));
if (!this.readOnly) {
await this.getContent().writeStreamfileRaw(DEBUG_CONFIG_FILE, Buffer.from(this.configLines.map(line => `${line.key}${line.value !== undefined ? `=${line.value}` : ''}`).join("\n"), `utf8`));
}
}

getRemoteServiceCertificatePath() {
Expand Down
10 changes: 7 additions & 3 deletions src/api/debug/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { instance } from "../../instantiate";
import { CustomUI } from "../CustomUI";
import IBMi from "../IBMi";
import { Tools } from "../Tools";
import { DebugConfiguration, getDebugServiceDetails } from "./config";
import { DEBUG_CONFIG_FILE, DebugConfiguration, getDebugServiceDetails, ORIGINAL_DEBUG_CONFIG_FILE } from "./config";

export type DebugJob = {
name: string
Expand All @@ -28,6 +28,10 @@ export async function startService(connection: IBMi) {

try {
await checkAuthority();
const debugServiceVersion = (await getDebugServiceDetails()).semanticVersion();
const prestartCommand = (debugServiceVersion.major >= 2 && debugServiceVersion.patch >= 1) ?
`export DEBUG_SERVICE_EXTERNAL_CONFIG_FILE=${DEBUG_CONFIG_FILE}` :
`cp ${DEBUG_CONFIG_FILE} ${ORIGINAL_DEBUG_CONFIG_FILE}`
const debugConfig = await new DebugConfiguration(connection).load();

const submitOptions = await window.showInputBox({
Expand All @@ -41,7 +45,7 @@ export async function startService(connection: IBMi) {
if (submitUser && submitUser !== "*CURRENT") {
await checkAuthority(submitUser);
}
const command = `SBMJOB CMD(STRQSH CMD('${connection.remoteFeatures[`bash`]} -c /QIBM/ProdData/IBMiDebugService/bin/startDebugService.sh')) JOB(DBGSVCE) ${submitOptions}`
const command = `SBMJOB CMD(STRQSH CMD('${connection.remoteFeatures[`bash`]} -c ''${prestartCommand}; /QIBM/ProdData/IBMiDebugService/bin/startDebugService.sh''')) JOB(DBGSVCE) ${submitOptions}`
const submitResult = await connection.runCommand({ command, cwd: debugConfig.getRemoteServiceWorkDir(), noLibList: true });
if (submitResult.code === 0) {
const submitMessage = Tools.parseMessages(submitResult.stderr || submitResult.stdout).findId("CPC1221")?.text;
Expand Down Expand Up @@ -229,7 +233,7 @@ async function openQPRINT(connection: IBMi, job: string) {
.setOptions({ fullWidth: true })
.loadPage(`${job} QPRINT`);
}
else{
else {
window.showWarningMessage(`No QPRINT spooled file found for job ${job}!`);
}
}
21 changes: 9 additions & 12 deletions src/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { Terminal } from './api/Terminal';
import { getDebugServiceDetails } from './api/debug/config';
import { debugPTFInstalled, isDebugEngineRunning } from './api/debug/server';
import { setupGitEventHandler } from './api/local/git';
import { registerActionsCommands } from './commands/actions';
import { registerCompareCommands } from './commands/compare';
import { registerConnectionCommands } from './commands/connection';
import { registerOpenCommands } from './commands/open';
import { registerPasswordCommands } from './commands/password';
import { QSysFS } from "./filesystems/qsys/QSysFs";
import { SEUColorProvider } from "./languages/general/SEUColorProvider";
import { ActionsUI } from './webviews/actions';
import { VariablesUI } from "./webviews/variables";
import { registerOpenCommands } from './commands/open';
import { registerCompareCommands } from './commands/compare';
import { registerActionsCommands } from './commands/actions';
import { registerPasswordCommands } from './commands/password';
import { registerConnectionCommands } from './commands/connection';

export let instance: Instance;

Expand Down Expand Up @@ -108,9 +108,8 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
}

async function updateConnectedBar() {
const connection = instance.getConnection();
if (connection) {
const config = instance.getConfig()!;
const config = instance.getConnection()?.getConfig();
if (config) {
connectedBarItem.text = `$(${config.readOnlyMode ? "lock" : "settings-gear"}) ${config.name}`;
}

Expand All @@ -128,9 +127,7 @@ async function updateConnectedBar() {
}

async function onConnected() {
const connection = instance.getConnection()!;
const config = connection.getConfig();

const config = instance.getConnection()?.getConfig();
[
connectedBarItem,
disconnectBarItem,
Expand All @@ -139,7 +136,7 @@ async function onConnected() {
updateConnectedBar();

// Enable the profile view if profiles exist.
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:hasProfiles`, (config.connectionProfiles || []).length > 0);
vscode.commands.executeCommand(`setContext`, `code-for-ibmi:hasProfiles`, (config?.connectionProfiles || []).length > 0);
}

async function onDisconnected() {
Expand Down
Loading