mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Another iteration
This commit is contained in:
parent
f400c5576a
commit
28d24bb6ea
12 changed files with 134 additions and 107 deletions
|
|
@ -52,8 +52,8 @@ export function initializePackageManager(packageManagerName) {
|
|||
state.packageManagerName = createBunPackageManager();
|
||||
} else if (packageManagerName === "bunx") {
|
||||
state.packageManagerName = createBunxPackageManager();
|
||||
} else if (packageManagerName === "pip" || packageManagerName === "pip3") {
|
||||
state.packageManagerName = createPipPackageManager(packageManagerName);
|
||||
} else if (packageManagerName === "pip") {
|
||||
state.packageManagerName = createPipPackageManager();
|
||||
} else {
|
||||
throw new Error("Unsupported package manager: " + packageManagerName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
import { runPip } from "./runPipCommand.js";
|
||||
|
||||
import { getCurrentPipInvocation } from "./pipSettings.js";
|
||||
/**
|
||||
* @param {string} [command]
|
||||
* @returns {import("../currentPackageManager.js").PackageManager}
|
||||
*/
|
||||
export function createPipPackageManager(command = "pip") {
|
||||
export function createPipPackageManager() {
|
||||
return {
|
||||
runCommand: /** @param {string[]} args */ (args) => runPip(command, args),
|
||||
/**
|
||||
* @param {string[]} args
|
||||
*/
|
||||
runCommand: (args) => {
|
||||
const invocation = getCurrentPipInvocation();
|
||||
const fullArgs = [...invocation.args, ...args];
|
||||
console.debug('[safe-chain debug] runCommand:', invocation.command, fullArgs);
|
||||
return runPip(invocation.command, fullArgs);
|
||||
},
|
||||
// For pip, rely solely on MITM proxy to detect/deny downloads from known registries.
|
||||
isSupportedCommand: () => false,
|
||||
getDependencyUpdatesForCommand: () => [],
|
||||
|
|
|
|||
31
packages/safe-chain/src/packagemanager/pip/pipSettings.js
Normal file
31
packages/safe-chain/src/packagemanager/pip/pipSettings.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Constant for pip package manager name
|
||||
export const PIP_PACKAGE_MANAGER = "pip";
|
||||
|
||||
// Enum of possible Python/pip invocations for Safe Chain interception
|
||||
export const PIP_INVOCATIONS = {
|
||||
PIP: { command: "pip", args: [] },
|
||||
PIP3: { command: "pip3", args: [] },
|
||||
PY_PIP: { command: "python", args: ["-m", "pip"] },
|
||||
PY3_PIP: { command: "python3", args: ["-m", "pip"] }
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {{ command: string, args: string[] }}
|
||||
*/
|
||||
let currentInvocation = PIP_INVOCATIONS.PY3_PIP; // Default to python3 -m pip
|
||||
|
||||
/**
|
||||
* @param {{ command: string, args: string[] }} invocation
|
||||
*/
|
||||
export function setCurrentPipInvocation(invocation) {
|
||||
console.debug('[safe-chain debug] setCurrentPipInvocation:', invocation);
|
||||
currentInvocation = invocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {{ command: string, args: string[] }}
|
||||
*/
|
||||
export function getCurrentPipInvocation() {
|
||||
console.debug('[safe-chain debug] getCurrentPipInvocation:', currentInvocation);
|
||||
return currentInvocation;
|
||||
}
|
||||
|
|
@ -26,10 +26,10 @@ export async function runPip(command, args) {
|
|||
});
|
||||
return { status: result.status };
|
||||
} catch (/** @type any */ error) {
|
||||
ui.writeError("Error executing command:", error.message);
|
||||
if (error.status) {
|
||||
return { status: error.status };
|
||||
} else {
|
||||
ui.writeError("Error executing command:", error.message);
|
||||
return { status: 1 };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue