Skip to content

Commit

Permalink
add support unset env feature (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha authored Apr 1, 2024
1 parent b3562df commit 4396fac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/+support-unset-feature.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
support unset env feature part of https://github.com/metalbear-co/mirrord/issues/2260
6 changes: 4 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,17 @@ export class MirrordExecution {

env: Map<string, string>;
patchedPath: string | null;
envToUnset: undefined | string[];

constructor(env: Map<string, string>, patchedPath: string | null) {
constructor(env: Map<string, string>, patchedPath: string | null, envToUnset: string[]) {
this.env = env;
this.patchedPath = patchedPath;
this.envToUnset = envToUnset;
}

static mirrordExecutionFromJson(data: string): MirrordExecution {
const parsed = JSON.parse(data);
return new MirrordExecution(new Map(Object.entries(parsed["environment"])), parsed["patched_path"]);
return new MirrordExecution(new Map(Object.entries(parsed["environment"])), parsed["patched_path"], parsed["env_to_unset"]);
}

}
Expand Down
7 changes: 7 additions & 0 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,15 @@ async function main(
}

let env = executionInfo?.env;

config.env = Object.assign({}, config.env, Object.fromEntries(env));

if (executionInfo.envToUnset) {
for (let key of executionInfo.envToUnset) {
delete config.env[key]

Check warning on line 194 in src/debugger.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

Check warning on line 194 in src/debugger.ts

View workflow job for this annotation

GitHub Actions / e2e / vscode-e2e

Missing semicolon

Check warning on line 194 in src/debugger.ts

View workflow job for this annotation

GitHub Actions / e2e / vscode-e2e

Missing semicolon

Check warning on line 194 in src/debugger.ts

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon

Check warning on line 194 in src/debugger.ts

View workflow job for this annotation

GitHub Actions / e2e / vscode-e2e

Missing semicolon

Check warning on line 194 in src/debugger.ts

View workflow job for this annotation

GitHub Actions / e2e / vscode-e2e

Missing semicolon
}
}

config.env["__MIRRORD_EXT_INJECTED"] = 'true';

return config;
Expand Down

0 comments on commit 4396fac

Please sign in to comment.