History

Return credentials as Redacted from CredentialProvider

Rhys Sullivan committed 3 months ago

Commit 46f3da21 parent 0fbb93d32 files · +540 −127Browse files

Showing the changes to examples/all-plugins/src (1 of 32 files). Show all

Unified · Split

examples/all-plugins/src/main.ts+11−5
@@ -18,12 +18,13 @@ · 17 unmodified lines
18// default.18// default.
19// ---------------------------------------------------------------------------19// ---------------------------------------------------------------------------
20 20
21import { Cause, Effect, Result } from "effect";21import { Cause, Effect, Redacted, Result } from "effect";
22 22
23import {23import {
24 AuthTemplateSlug,24 AuthTemplateSlug,
25 ConnectionName,25 ConnectionName,
26 createExecutor,26 createExecutor,
27 credentialValueToWrite,
27 IntegrationSlug,28 IntegrationSlug,
28 ProviderItemId,29 ProviderItemId,
29 ProviderKey,30 ProviderKey,
@@ -61,15 +62,20 @@ import { workosVaultPlugin } from "@executor-js/plugin-workos-vault"; · 31 unmodified lines
61// A connection's value lives in a writable credential provider. This tiny62// A connection's value lives in a writable credential provider. This tiny
62// in-memory store is enough for a script; the keychain / file-secrets /63// in-memory store is enough for a script; the keychain / file-secrets /
63// 1Password plugins below contribute durable ones. Providers are Effect-native,64// 1Password plugins below contribute durable ones. Providers are Effect-native,
64// so `get`/`set` return `Effect`s.65// so `get`/`set` return `Effect`s, and `get` hands back a `Redacted` so a
66// credential cannot land in a log by accident.
65const memory = new Map<string, string>();67const memory = new Map<string, string>();
66const memoryProvider: CredentialProvider = {68const memoryProvider: CredentialProvider = {
67 key: ProviderKey.make("memory"),69 key: ProviderKey.make("memory"),
68 writable: true,70 writable: true,
69 get: (id: ProviderItemId) => Effect.sync(() => memory.get(String(id)) ?? null),71 get: (id: ProviderItemId) =>
70 set: (id: ProviderItemId, value: string) =>
71 Effect.sync(() => {72 Effect.sync(() => {
72 memory.set(String(id), value);73 const value = memory.get(String(id));
74 return value === undefined ? null : Redacted.make(value);
75 }),
76 set: (id: ProviderItemId, value: string | Redacted.Redacted<string>) =>
77 Effect.sync(() => {
78 memory.set(String(id), credentialValueToWrite(value));
73 }),79 }),
74};80};
75 81