Skip to content

Commit 3044d8f

Browse files
Nikola HristovNikola Hristov
authored andcommitted
2 parents 0b019df + 537b70d commit 3044d8f

File tree

17 files changed

+2106
-572
lines changed

17 files changed

+2106
-572
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## DO NOT MODIFY THIS FILE MANUALLY. This is part of auto-baselining from 1ES Pipeline Templates. Go to [https://aka.ms/1espt-autobaselining] for more details.
2+
3+
pipelines:
4+
499:
5+
retail:
6+
source:
7+
credscan:
8+
lastModifiedDate: 2024-09-25
9+
eslint:
10+
lastModifiedDate: 2024-09-25
11+
psscriptanalyzer:
12+
lastModifiedDate: 2024-09-25
13+
armory:
14+
lastModifiedDate: 2024-09-25
15+
policheck:
16+
lastModifiedDate: 2024-11-29
17+
binary:
18+
credscan:
19+
lastModifiedDate: 2024-09-25
20+
binskim:
21+
lastModifiedDate: 2025-01-15
22+
spotbugs:
23+
lastModifiedDate: 2024-09-25

.config/guardian/.gdnbaselines

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"properties": {
3+
"helpUri": "https://eng.ms/docs/microsoft-security/security/azure-security/cloudai-security-fundamentals-engineering/security-integration/guardian-wiki/microsoft-guardian/general/baselines"
4+
},
5+
"version": "1.0.0",
6+
"baselines": {
7+
"default": {
8+
"name": "default",
9+
"createdDate": "2025-01-15 10:14:16Z",
10+
"lastUpdatedDate": "2025-01-15 10:14:16Z"
11+
}
12+
},
13+
"results": {
14+
"a9bb48acab0991d979cacbdeb12c070d85c3991db87ef562ca1911c6bd44794e": {
15+
"signature": "a9bb48acab0991d979cacbdeb12c070d85c3991db87ef562ca1911c6bd44794e",
16+
"alternativeSignatures": [
17+
"eda82faebade0e5fe8ad4afbf3ea677c294d3be3713d6a6a2b5ff0f5122ad623"
18+
],
19+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_linux_amd64.so",
20+
"memberOf": [
21+
"default"
22+
],
23+
"tool": "binskim",
24+
"ruleId": "BA3003",
25+
"createdDate": "2025-01-15 10:14:16Z",
26+
"expirationDate": "2025-07-04 10:36:14Z",
27+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
28+
},
29+
"d10b28a04ea6f37bf544021fe269e1d116971ed96309424ce6f3948a78b3dd14": {
30+
"signature": "d10b28a04ea6f37bf544021fe269e1d116971ed96309424ce6f3948a78b3dd14",
31+
"alternativeSignatures": [
32+
"7728a15920f8919ec815f1a3b132ca349bfc49bfe872e8ae4e7267b052afa868"
33+
],
34+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/pydevd_attach_to_process/attach_linux_amd64.so",
35+
"memberOf": [
36+
"default"
37+
],
38+
"tool": "binskim",
39+
"ruleId": "BA3030",
40+
"createdDate": "2025-01-15 10:14:16Z",
41+
"expirationDate": "2025-07-04 10:36:14Z",
42+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
43+
},
44+
"24060ab64146e1d968780333db6b0374f92538144527497b66112a6487b0460e": {
45+
"signature": "24060ab64146e1d968780333db6b0374f92538144527497b66112a6487b0460e",
46+
"alternativeSignatures": [
47+
"e1efc73ee8381f2ca92ddbe6cf492d9fe5be200f271670d5b4eb66d46510f51c"
48+
],
49+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cp39-win_amd64.pyd",
50+
"memberOf": [
51+
"default"
52+
],
53+
"tool": "binskim",
54+
"ruleId": "BA2008",
55+
"createdDate": "2025-01-15 10:14:16Z",
56+
"expirationDate": "2025-07-04 10:36:14Z",
57+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
58+
},
59+
"ef8a10ec6e0b3a56efdc8bfcb5935ca2f84922382bdc4461ca73288424c3945e": {
60+
"signature": "ef8a10ec6e0b3a56efdc8bfcb5935ca2f84922382bdc4461ca73288424c3945e",
61+
"alternativeSignatures": [
62+
"02b1aa6e50383300500633df7de80d91178177ccc665f068e8fbdbc81468d05c"
63+
],
64+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.cp39-win_amd64.pyd",
65+
"memberOf": [
66+
"default"
67+
],
68+
"tool": "binskim",
69+
"ruleId": "BA2008",
70+
"createdDate": "2025-01-15 10:14:16Z",
71+
"expirationDate": "2025-07-04 10:36:14Z",
72+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
73+
},
74+
"2d3403b3a4a523cedfc8c4ce6e2c23ec60ead5788591a95b7fa15b5fea955bc5": {
75+
"signature": "2d3403b3a4a523cedfc8c4ce6e2c23ec60ead5788591a95b7fa15b5fea955bc5",
76+
"alternativeSignatures": [
77+
"9ab9c4b3c0f0ead32c8db513fd722e69b0f227d8a90a2004ba660a0afcda250b"
78+
],
79+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cp310-win_amd64.pyd",
80+
"memberOf": [
81+
"default"
82+
],
83+
"tool": "binskim",
84+
"ruleId": "BA2008",
85+
"createdDate": "2025-01-15 10:14:25Z",
86+
"expirationDate": "2025-07-04 10:36:14Z",
87+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
88+
},
89+
"2f1d85ce0b29a4f99c6297078b1b792c3d43c33824c6826671b3db40c07ff648": {
90+
"signature": "2f1d85ce0b29a4f99c6297078b1b792c3d43c33824c6826671b3db40c07ff648",
91+
"alternativeSignatures": [
92+
"d0e5bf91a96af78edf77d20b504f0b6473812b93a5b470a5879b864a78fb061f"
93+
],
94+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cp311-win_amd64.pyd",
95+
"memberOf": [
96+
"default"
97+
],
98+
"tool": "binskim",
99+
"ruleId": "BA2008",
100+
"createdDate": "2025-01-15 10:14:25Z",
101+
"expirationDate": "2025-07-04 10:36:14Z",
102+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
103+
},
104+
"22ee53d01c6cc3cc7a927a508e201b804d856cee3bd5a872fa4d4e629b840a7f": {
105+
"signature": "22ee53d01c6cc3cc7a927a508e201b804d856cee3bd5a872fa4d4e629b840a7f",
106+
"alternativeSignatures": [
107+
"54064cf443446bfc97cc47d04e23581c7489bdcdc0011c544f0eef48b11ed348"
108+
],
109+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_cython.cp312-win_amd64.pyd",
110+
"memberOf": [
111+
"default"
112+
],
113+
"tool": "binskim",
114+
"ruleId": "BA2008",
115+
"createdDate": "2025-01-15 10:14:25Z",
116+
"expirationDate": "2025-07-04 10:36:14Z",
117+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
118+
},
119+
"255e1ecfc10b8f727eff4a80ebb9920a2402d9e2f9f77591b75de212e625b3a8": {
120+
"signature": "255e1ecfc10b8f727eff4a80ebb9920a2402d9e2f9f77591b75de212e625b3a8",
121+
"alternativeSignatures": [
122+
"9ad6d2cf4bbef4cb375c30c7aa8bbcda2119406221e9431f290734f7d2d23d32"
123+
],
124+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.cp310-win_amd64.pyd",
125+
"memberOf": [
126+
"default"
127+
],
128+
"tool": "binskim",
129+
"ruleId": "BA2008",
130+
"createdDate": "2025-01-15 10:14:25Z",
131+
"expirationDate": "2025-07-04 10:36:14Z",
132+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
133+
},
134+
"cb636c5012043d0607ac8124e85915985c4cf5cb2cb0a92a5bae075ce268ffe9": {
135+
"signature": "cb636c5012043d0607ac8124e85915985c4cf5cb2cb0a92a5bae075ce268ffe9",
136+
"alternativeSignatures": [
137+
"78f85f1da48efa2d27199a3f998b513e043839b654c1dafd7958d666f8d4a4da"
138+
],
139+
"target": "extension/bundled/libs/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.cp312-win_amd64.pyd",
140+
"memberOf": [
141+
"default"
142+
],
143+
"tool": "binskim",
144+
"ruleId": "BA2008",
145+
"createdDate": "2025-01-15 10:14:25Z",
146+
"expirationDate": "2025-07-04 10:36:14Z",
147+
"justification": "This error is baselined with an expiration date of 180 days from 2025-01-15 10:36:14Z"
148+
}
149+
}
150+
}

.vscode/launch.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
13+
"outFiles": ["${workspaceFolder}/dist/**/*.js", "!${workspaceFolder}/**/node_modules**/*"],
14+
"preLaunchTask": "npm: watch",
15+
"presentation": {
16+
"hidden": false,
17+
"group": "",
18+
"order": 2
19+
}
20+
},
21+
{
22+
"name": "Unit Tests",
23+
"type": "extensionHost",
24+
"request": "launch",
25+
"runtimeExecutable": "${execPath}",
26+
"args": [
27+
"./out/test/**/*.unit.test.js",
28+
"--extensionDevelopmentPath=${workspaceFolder}",
29+
"--extensionTestsPath=${workspaceFolder}/out/test/unittest/index",
30+
//"--grep", "<suite name>",
31+
"--timeout=300000"
32+
],
33+
"outFiles": ["${workspaceFolder}/out/**/*.js"],
34+
"preLaunchTask": "tasks: watch-tests"
35+
}
36+
]
37+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import * as fs from 'fs';
5+
import * as path from 'path';
6+
import * as crypto from 'crypto';
7+
import * as os from 'os';
8+
import { DebugSessionOptions, Disposable, GlobalEnvironmentVariableCollection, l10n, RelativePattern } from 'vscode';
9+
import { createFileSystemWatcher, debugStartDebugging } from './utils';
10+
import { traceError, traceLog, traceVerbose } from './common/log/logging';
11+
12+
/**
13+
* Registers the configuration-less debugging setup for the extension.
14+
*
15+
* This function sets up environment variables and a file system watcher to
16+
* facilitate debugging without requiring a pre-configured launch.json file.
17+
*
18+
* @param envVarCollection - The collection of environment variables to be modified.
19+
* @param extPath - The path to the extension directory.
20+
*
21+
* Environment Variables:
22+
* - `DEBUGPY_ADAPTER_ENDPOINTS`: Path to the file containing the debugger adapter endpoint.
23+
* - `BUNDLED_DEBUGPY_PATH`: Path to the bundled debugpy library.
24+
* - `PATH`: Appends the path to the noConfigScripts directory.
25+
*/
26+
export async function registerNoConfigDebug(
27+
envVarCollection: GlobalEnvironmentVariableCollection,
28+
extPath: string,
29+
): Promise<Disposable> {
30+
const collection = envVarCollection;
31+
32+
// create a temp directory for the noConfigDebugAdapterEndpoints
33+
// file path format: tempDir/noConfigDebugAdapterEndpoints-<randomString>/debuggerAdapterEndpoint.txt
34+
const randomSuffix = crypto.randomBytes(10).toString('hex');
35+
const tempDirName = `noConfigDebugAdapterEndpoints-${randomSuffix}`;
36+
let tempDirPath = path.join(os.tmpdir(), tempDirName);
37+
try {
38+
traceLog('Attempting to use temp directory for noConfigDebugAdapterEndpoints, dir name:', tempDirName);
39+
await fs.promises.mkdir(tempDirPath, { recursive: true });
40+
} catch (error) {
41+
// Handle the error when accessing the temp directory
42+
traceError('Error accessing temp directory:', error, ' Attempt to use extension root dir instead');
43+
// Make new temp directory in extension root dird
44+
tempDirPath = path.join(extPath, '.temp');
45+
await fs.promises.mkdir(tempDirPath, { recursive: true });
46+
}
47+
const tempFilePath = path.join(tempDirPath, 'debuggerAdapterEndpoint.txt');
48+
49+
// Add env var for PYDEVD_DISABLE_FILE_VALIDATION to disable extra output in terminal when starting the debug session.
50+
collection.replace('PYDEVD_DISABLE_FILE_VALIDATION', '1');
51+
52+
// Add env vars for DEBUGPY_ADAPTER_ENDPOINTS, BUNDLED_DEBUGPY_PATH, and PATH
53+
collection.replace('DEBUGPY_ADAPTER_ENDPOINTS', tempFilePath);
54+
55+
const noConfigScriptsDir = path.join(extPath, 'bundled', 'scripts', 'noConfigScripts');
56+
const pathSeparator = process.platform === 'win32' ? ';' : ':';
57+
collection.append('PATH', `${pathSeparator}${noConfigScriptsDir}`);
58+
59+
const bundledDebugPath = path.join(extPath, 'bundled', 'libs', 'debugpy');
60+
collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath);
61+
62+
envVarCollection.description = l10n.t(
63+
'Enables use of [no-config debugging](https://github.com/microsoft/vscode-python-debugger/wiki/No%E2%80%90Config-Debugging), `debugpy <script.py>`, in the terminal.',
64+
);
65+
66+
// create file system watcher for the debuggerAdapterEndpointFolder for when the communication port is written
67+
const fileSystemWatcher = createFileSystemWatcher(new RelativePattern(tempDirPath, '**/*'));
68+
const fileCreationEvent = fileSystemWatcher.onDidCreate(async (uri) => {
69+
const filePath = uri.fsPath;
70+
fs.readFile(filePath, (err, data) => {
71+
const dataParse = data.toString();
72+
if (err) {
73+
traceError(`Error reading debuggerAdapterEndpoint.txt file: ${err}`);
74+
return;
75+
}
76+
try {
77+
// parse the client port
78+
const jsonData = JSON.parse(dataParse);
79+
const clientPort = jsonData.client?.port;
80+
traceVerbose(`Parsed client port: ${clientPort}`);
81+
82+
const options: DebugSessionOptions = {
83+
noDebug: false,
84+
};
85+
86+
// start debug session with the client port
87+
debugStartDebugging(
88+
undefined,
89+
{
90+
type: 'python',
91+
request: 'attach',
92+
name: 'Attach to Python',
93+
connect: {
94+
port: clientPort,
95+
host: 'localhost',
96+
},
97+
},
98+
options,
99+
).then(
100+
(started) => {
101+
if (started) {
102+
traceVerbose('Successfully started debug session');
103+
} else {
104+
traceError('Error starting debug session, session not started.');
105+
}
106+
},
107+
(error) => {
108+
traceError(`Error starting debug session: ${error}`);
109+
},
110+
);
111+
} catch (parseErr) {
112+
traceError(`Error parsing JSON: ${parseErr}`);
113+
}
114+
});
115+
JSON.parse;
116+
});
117+
return Promise.resolve(
118+
new Disposable(() => {
119+
fileSystemWatcher.dispose();
120+
fileCreationEvent.dispose();
121+
}),
122+
);
123+
}

Source/extension/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
workspace,
3+
debug,
4+
WorkspaceFolder,
5+
DebugConfiguration,
6+
DebugSession,
7+
DebugSessionOptions,
8+
FileSystemWatcher,
9+
} from 'vscode';
10+
11+
export function createFileSystemWatcher(args: any): FileSystemWatcher {
12+
return workspace.createFileSystemWatcher(args);
13+
}
14+
15+
export async function debugStartDebugging(
16+
folder: WorkspaceFolder | undefined,
17+
nameOrConfiguration: string | DebugConfiguration,
18+
parentSessionOrOptions?: DebugSession | DebugSessionOptions,
19+
): Promise<boolean> {
20+
return debug.startDebugging(folder, nameOrConfiguration, parentSessionOrOptions);
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
# Bash script
3+
python3 $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $@
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
:: Bat script
3+
python %BUNDLED_DEBUGPY_PATH% --listen 0 --wait-for-client %*
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Fish script
2+
python3 $BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $argv
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# PowerShell script
2+
if ($PSVersionTable.OS -match "Windows") {
3+
python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
4+
} else {
5+
python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
6+
}

0 commit comments

Comments
 (0)