Skip to content

Commit c63f04d

Browse files
committed
chore: add new function to register a global secret
It hides the idea of having a root keychain for external users.
1 parent af39421 commit c63f04d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/common/keychain.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ export class Keychain {
3434
return [...this.secrets];
3535
}
3636
}
37+
38+
export function registerGlobalSecretToRedact(value: Secret["value"], kind: Secret["kind"]): void {
39+
Keychain.root.register(value, kind);
40+
}

src/lib.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ export type {
1919
} from "./common/connectionErrorHandler.js";
2020
export { ErrorCodes } from "./common/errors.js";
2121
export { Telemetry } from "./telemetry/telemetry.js";
22+
export { Keychain, registerGlobalSecretToRedact } from "./common/keychain.js";
23+
export type { Secret } from "./common/keychain.js";

tests/unit/common/keychain.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Keychain } from "../../../src/common/keychain.js";
1+
import { Keychain, registerGlobalSecretToRedact } from "../../../src/common/keychain.js";
22
import { describe, beforeEach, afterEach, it, expect } from "vitest";
33

44
describe("Keychain", () => {
@@ -26,4 +26,11 @@ describe("Keychain", () => {
2626
keychain.register("654321", "user");
2727
expect(keychain.allSecrets).toEqual([{ value: "654321", kind: "user" }]);
2828
});
29+
30+
describe("registerGlobalSecretToRedact", () => {
31+
it("registers the secret in the root keychain", () => {
32+
registerGlobalSecretToRedact("123456", "password");
33+
expect(keychain.allSecrets).toEqual([{ value: "123456", kind: "password" }]);
34+
});
35+
});
2936
});

0 commit comments

Comments
 (0)