Skip to content

Commit

Permalink
Merge pull request #1990 from codefori/feature/debugConfig
Browse files Browse the repository at this point in the history
Debug service configuration and management improvement
  • Loading branch information
sebjulliand committed Apr 25, 2024
2 parents 6d7cdaa + bb8899d commit 3f65f3f
Show file tree
Hide file tree
Showing 16 changed files with 693 additions and 477 deletions.
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,13 @@
"category": "IBM i",
"icon": "$(debug-stop)",
"enablement": "!code-for-ibmi:debugWorking"
},
{
"command": "code-for-ibmi.debug.open.service.config",
"title": "Open configuration",
"category": "IBM i",
"icon": "$(settings-gear)",
"enablement": "!code-for-ibmi:debugWorking"
}
],
"keybindings": [
Expand Down Expand Up @@ -2160,6 +2167,10 @@
{
"command": "code-for-ibmi.debug.refresh",
"when": "never"
},
{
"command": "code-for-ibmi.debug.open.service.config",
"when": "never"
}
],
"view/title": [
Expand Down Expand Up @@ -2732,14 +2743,19 @@
"when": "!code-for-ibmi:debugManaged && view == ibmiDebugBrowser && viewItem =~ /^debugJob_.*_on$/",
"group": "inline"
},
{
"command": "code-for-ibmi.debug.open.service.config",
"when": "!code-for-ibmi:debugManaged && view == ibmiDebugBrowser && viewItem =~ /^debugJob_service.*$/",
"group": "inline"
},
{
"command": "code-for-ibmi.debug.setup.remote",
"when": "!code-for-ibmi:debugManaged && view == ibmiDebugBrowser && viewItem === certificateIssue_noremote",
"group": "inline"
},
{
"command": "code-for-ibmi.debug.setup.local",
"when": "!code-for-ibmi:debugManaged && view == ibmiDebugBrowser && viewItem =~ /^certificateIssue_(nolocal|dontmatch)$/",
"when": "!code-for-ibmi:debugManaged && view == ibmiDebugBrowser && viewItem =~ /^certificateIssue_localissue$/",
"group": "inline"
}
]
Expand Down
3 changes: 0 additions & 3 deletions src/api/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import os from "os";
import * as vscode from 'vscode';
import { DeploymentMethod } from '../typings';
import { FilterType } from './Filter';
import { DEFAULT_CERT_DIRECTORY } from "./debug/certificates";

export type SourceDateMode = "edit" | "diff";
export type DefaultOpenMode = "browse" | "edit";
Expand Down Expand Up @@ -52,7 +51,6 @@ export namespace ConnectionConfiguration {
connectringStringFor5250: string;
autoSaveBeforeAction: boolean;
showDescInLibList: boolean;
debugCertDirectory: string;
debugPort: string;
debugSepPort: string;
debugIsSecure: boolean;
Expand Down Expand Up @@ -134,7 +132,6 @@ export namespace ConnectionConfiguration {
connectringStringFor5250: parameters.connectringStringFor5250 || `localhost`,
autoSaveBeforeAction: (parameters.autoSaveBeforeAction === true),
showDescInLibList: (parameters.showDescInLibList === true),
debugCertDirectory: (parameters.debugCertDirectory || DEFAULT_CERT_DIRECTORY),
debugPort: (parameters.debugPort || "8005"),
debugSepPort: (parameters.debugSepPort || "8008"),
debugIsSecure: (parameters.debugIsSecure === true),
Expand Down
43 changes: 38 additions & 5 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { existsSync } from "fs";
import os from "os";
import path from 'path';
import { instance } from "../instantiate";
import { CcsidOrigin, CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand } from "../typings";
import { CcsidOrigin, CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand, SpecialAuthorities } from "../typings";
import { CompileTools } from "./CompileTools";
import { CachedServerSettings, GlobalStorage } from './Storage';
import { Tools } from './Tools';
import * as configVars from './configVars';
import { DebugConfiguration } from "./debug/config";
import { debugPTFInstalled } from "./debug/server";

export interface MemberParts extends IBMiMember {
basename: string
Expand Down Expand Up @@ -868,6 +870,22 @@ export default class IBMi {
}
}

let debugConfigLoaded = false
if ((!quickConnect || !cachedServerSettings?.debugConfigLoaded)) {
if (debugPTFInstalled()) {
try {
const debugServiceConfig = await new DebugConfiguration().load();
delete this.config.debugCertDirectory;
this.config.debugPort = debugServiceConfig.getOrDefault("DBGSRV_SECURED_PORT", "8005");
this.config.debugSepPort = debugServiceConfig.getOrDefault("DBGSRV_SEP_DAEMON_PORT", "8008");
debugConfigLoaded = true;
}
catch (error) {
vscode.window.showWarningMessage(`Could not load debug service configuration: ${error}`);
}
}
}

if (!reconnecting) {
vscode.workspace.getConfiguration().update(`workbench.editor.enablePreview`, false, true);
await vscode.commands.executeCommand(`setContext`, `code-for-ibmi:connected`, true);
Expand All @@ -887,7 +905,8 @@ export default class IBMi {
badDataAreasChecked: true,
libraryListValidated: true,
pathChecked: true,
userDefaultCCSID: this.userDefaultCCSID
userDefaultCCSID: this.userDefaultCCSID,
debugConfigLoaded
});

//Keep track of variant characters that can be uppercased
Expand Down Expand Up @@ -1254,7 +1273,7 @@ export default class IBMi {
}
return upperCased.join("");
}
else{
else {
return name.toLocaleUpperCase();
}
}
Expand All @@ -1268,7 +1287,7 @@ export default class IBMi {
* @param statements
* @returns a Result set
*/
async runSQL(statements: string, opts: {userCcsid?: number} = {}): Promise<Tools.DB2Row[]> {
async runSQL(statements: string, opts: { userCcsid?: number } = {}): Promise<Tools.DB2Row[]> {
const { 'QZDFMDB2.PGM': QZDFMDB2 } = this.remoteFeatures;

if (QZDFMDB2) {
Expand Down Expand Up @@ -1308,5 +1327,19 @@ export default class IBMi {
runtimeCcsid: this.runtimeCcsid,
userDefaultCCSID: this.userDefaultCCSID,
};
}
}

async checkUserSpecialAuthorities(authorities: SpecialAuthorities[], user?: string) {
const profile = (user || this.currentUser).toLocaleUpperCase();
const [row] = await this.runSQL(
`select trim(coalesce(usr.special_authorities,'') concat ' ' concat coalesce(grp.special_authorities, '')) AUTHORITIES ` +
`from qsys2.user_info_basic usr ` +
`left join qsys2.user_info_basic grp on grp.authorization_name = usr.group_profile_name ` +
`where usr.authorization_name = '${profile}'`
);

const userAuthorities = row?.AUTHORITIES ? String(row.AUTHORITIES).split(" ").filter(Boolean).filter(Tools.distinct) : [];
const missing = authorities.filter(auth => !userAuthorities.includes(auth));
return { valid: !Boolean(missing.length), missing };
}
}
4 changes: 2 additions & 2 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default class IBMiContent {
* @deprecated Use {@linkcode IBMi.runSQL IBMi.runSQL} instead
*/
runSQL(statements: string) {
return this.ibmi.runSQL(statements);
return this.ibmi.runSQL(statements);
}

/**
Expand Down Expand Up @@ -931,7 +931,7 @@ export default class IBMiContent {
})).code === 0;
}

async testStreamFile(path: string, right: "r" | "w" | "x") {
async testStreamFile(path: string, right: "f" | "d" | "r" | "w" | "x") {
return (await this.ibmi.sendCommand({ command: `test -${right} ${Tools.escapePath(path)}` })).code === 0;
}

Expand Down
17 changes: 9 additions & 8 deletions src/api/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ export type LastConnection = {
};

export type CachedServerSettings = {
aspInfo: { [id: number]: string };
runtimeCcsid: number | null;
remoteFeatures: { [name: string]: string | undefined };
remoteFeaturesKeys: string | null;
variantChars: { american: string, local: string };
badDataAreasChecked: boolean | null,
libraryListValidated: boolean | null,
aspInfo: { [id: number]: string }
runtimeCcsid: number | null
remoteFeatures: { [name: string]: string | undefined }
remoteFeaturesKeys: string | null
variantChars: { american: string, local: string }
badDataAreasChecked: boolean | null
libraryListValidated: boolean | null
pathChecked?: boolean
userDefaultCCSID: number | null;
userDefaultCCSID: number | null
debugConfigLoaded : boolean
} | undefined;

export class GlobalStorage extends Storage {
Expand Down
Loading

0 comments on commit 3f65f3f

Please sign in to comment.