@alchemy.run/daytona 0.0.0-stage → 2.0.0-beta.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +80 -2
- package/lib/ApiKey.d.ts +99 -0
- package/lib/ApiKey.d.ts.map +1 -0
- package/lib/ApiKey.js +152 -0
- package/lib/ApiKey.js.map +1 -0
- package/lib/AuthProvider.d.ts +55 -0
- package/lib/AuthProvider.d.ts.map +1 -0
- package/lib/AuthProvider.js +280 -0
- package/lib/AuthProvider.js.map +1 -0
- package/lib/Bootstrap.d.ts +8 -0
- package/lib/Bootstrap.d.ts.map +1 -0
- package/lib/Bootstrap.js +28 -0
- package/lib/Bootstrap.js.map +1 -0
- package/lib/ConnectSandbox.d.ts +72 -0
- package/lib/ConnectSandbox.d.ts.map +1 -0
- package/lib/ConnectSandbox.js +3 -0
- package/lib/ConnectSandbox.js.map +1 -0
- package/lib/ConnectSandboxHttp.d.ts +5 -0
- package/lib/ConnectSandboxHttp.d.ts.map +1 -0
- package/lib/ConnectSandboxHttp.js +22 -0
- package/lib/ConnectSandboxHttp.js.map +1 -0
- package/lib/Contributions.d.ts +7 -0
- package/lib/Contributions.d.ts.map +1 -0
- package/lib/Contributions.js +6 -0
- package/lib/Contributions.js.map +1 -0
- package/lib/CreateSandbox.d.ts +86 -0
- package/lib/CreateSandbox.d.ts.map +1 -0
- package/lib/CreateSandbox.js +3 -0
- package/lib/CreateSandbox.js.map +1 -0
- package/lib/CreateSandboxHttp.d.ts +5 -0
- package/lib/CreateSandboxHttp.d.ts.map +1 -0
- package/lib/CreateSandboxHttp.js +65 -0
- package/lib/CreateSandboxHttp.js.map +1 -0
- package/lib/CreateSecret.d.ts +56 -0
- package/lib/CreateSecret.d.ts.map +1 -0
- package/lib/CreateSecret.js +3 -0
- package/lib/CreateSecret.js.map +1 -0
- package/lib/CreateSecretHttp.d.ts +5 -0
- package/lib/CreateSecretHttp.d.ts.map +1 -0
- package/lib/CreateSecretHttp.js +39 -0
- package/lib/CreateSecretHttp.js.map +1 -0
- package/lib/CreateSnapshot.d.ts +80 -0
- package/lib/CreateSnapshot.d.ts.map +1 -0
- package/lib/CreateSnapshot.js +3 -0
- package/lib/CreateSnapshot.js.map +1 -0
- package/lib/CreateSnapshotHttp.d.ts +5 -0
- package/lib/CreateSnapshotHttp.d.ts.map +1 -0
- package/lib/CreateSnapshotHttp.js +47 -0
- package/lib/CreateSnapshotHttp.js.map +1 -0
- package/lib/CreateVolume.d.ts +81 -0
- package/lib/CreateVolume.d.ts.map +1 -0
- package/lib/CreateVolume.js +10 -0
- package/lib/CreateVolume.js.map +1 -0
- package/lib/CreateVolumeHttp.d.ts +5 -0
- package/lib/CreateVolumeHttp.d.ts.map +1 -0
- package/lib/CreateVolumeHttp.js +31 -0
- package/lib/CreateVolumeHttp.js.map +1 -0
- package/lib/Credentials.d.ts +9 -0
- package/lib/Credentials.d.ts.map +1 -0
- package/lib/Credentials.js +18 -0
- package/lib/Credentials.js.map +1 -0
- package/lib/DaytonaBindings.d.ts +51 -0
- package/lib/DaytonaBindings.d.ts.map +1 -0
- package/lib/DaytonaBindings.js +61 -0
- package/lib/DaytonaBindings.js.map +1 -0
- package/lib/IdentityProvider.d.ts +80 -0
- package/lib/IdentityProvider.d.ts.map +1 -0
- package/lib/IdentityProvider.js +111 -0
- package/lib/IdentityProvider.js.map +1 -0
- package/lib/MountVolume.d.ts +86 -0
- package/lib/MountVolume.d.ts.map +1 -0
- package/lib/MountVolume.js +27 -0
- package/lib/MountVolume.js.map +1 -0
- package/lib/OAuthClient.d.ts +14 -0
- package/lib/OAuthClient.d.ts.map +1 -0
- package/lib/OAuthClient.js +23 -0
- package/lib/OAuthClient.js.map +1 -0
- package/lib/Organization.d.ts +40 -0
- package/lib/Organization.d.ts.map +1 -0
- package/lib/Organization.js +80 -0
- package/lib/Organization.js.map +1 -0
- package/lib/OrganizationInvitation.d.ts +70 -0
- package/lib/OrganizationInvitation.d.ts.map +1 -0
- package/lib/OrganizationInvitation.js +109 -0
- package/lib/OrganizationInvitation.js.map +1 -0
- package/lib/OrganizationMember.d.ts +86 -0
- package/lib/OrganizationMember.d.ts.map +1 -0
- package/lib/OrganizationMember.js +109 -0
- package/lib/OrganizationMember.js.map +1 -0
- package/lib/OrganizationOtelConfig.d.ts +59 -0
- package/lib/OrganizationOtelConfig.d.ts.map +1 -0
- package/lib/OrganizationOtelConfig.js +87 -0
- package/lib/OrganizationOtelConfig.js.map +1 -0
- package/lib/OrganizationRole.d.ts +66 -0
- package/lib/OrganizationRole.d.ts.map +1 -0
- package/lib/OrganizationRole.js +106 -0
- package/lib/OrganizationRole.js.map +1 -0
- package/lib/OrganizationSettings.d.ts +76 -0
- package/lib/OrganizationSettings.d.ts.map +1 -0
- package/lib/OrganizationSettings.js +107 -0
- package/lib/OrganizationSettings.js.map +1 -0
- package/lib/Providers.d.ts +14 -0
- package/lib/Providers.d.ts.map +1 -0
- package/lib/Providers.js +53 -0
- package/lib/Providers.js.map +1 -0
- package/lib/ReadAuditLogs.d.ts +30 -0
- package/lib/ReadAuditLogs.d.ts.map +1 -0
- package/lib/ReadAuditLogs.js +17 -0
- package/lib/ReadAuditLogs.js.map +1 -0
- package/lib/ReadOrganization.d.ts +39 -0
- package/lib/ReadOrganization.d.ts.map +1 -0
- package/lib/ReadOrganization.js +39 -0
- package/lib/ReadOrganization.js.map +1 -0
- package/lib/ReadUsage.d.ts +31 -0
- package/lib/ReadUsage.d.ts.map +1 -0
- package/lib/ReadUsage.js +17 -0
- package/lib/ReadUsage.js.map +1 -0
- package/lib/Region.d.ts +78 -0
- package/lib/Region.d.ts.map +1 -0
- package/lib/Region.js +169 -0
- package/lib/Region.js.map +1 -0
- package/lib/Registry.d.ts +84 -0
- package/lib/Registry.d.ts.map +1 -0
- package/lib/Registry.js +97 -0
- package/lib/Registry.js.map +1 -0
- package/lib/Runner.d.ts +66 -0
- package/lib/Runner.d.ts.map +1 -0
- package/lib/Runner.js +116 -0
- package/lib/Runner.js.map +1 -0
- package/lib/Sandbox.d.ts +376 -0
- package/lib/Sandbox.d.ts.map +1 -0
- package/lib/Sandbox.js +565 -0
- package/lib/Sandbox.js.map +1 -0
- package/lib/SandboxClient.d.ts +258 -0
- package/lib/SandboxClient.d.ts.map +1 -0
- package/lib/SandboxClient.js +233 -0
- package/lib/SandboxClient.js.map +1 -0
- package/lib/Secret.d.ts +93 -0
- package/lib/Secret.d.ts.map +1 -0
- package/lib/Secret.js +130 -0
- package/lib/Secret.js.map +1 -0
- package/lib/Snapshot.d.ts +327 -0
- package/lib/Snapshot.d.ts.map +1 -0
- package/lib/Snapshot.js +447 -0
- package/lib/Snapshot.js.map +1 -0
- package/lib/Volume.d.ts +99 -0
- package/lib/Volume.d.ts.map +1 -0
- package/lib/Volume.js +152 -0
- package/lib/Volume.js.map +1 -0
- package/lib/WarmPool.d.ts +61 -0
- package/lib/WarmPool.d.ts.map +1 -0
- package/lib/WarmPool.js +81 -0
- package/lib/WarmPool.js.map +1 -0
- package/lib/Webhooks.d.ts +58 -0
- package/lib/Webhooks.d.ts.map +1 -0
- package/lib/Webhooks.js +75 -0
- package/lib/Webhooks.js.map +1 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +36 -0
- package/lib/index.js.map +1 -0
- package/lib/internal/BuildContext.d.ts +16 -0
- package/lib/internal/BuildContext.d.ts.map +1 -0
- package/lib/internal/BuildContext.js +50 -0
- package/lib/internal/BuildContext.js.map +1 -0
- package/lib/internal/Declared.d.ts +29 -0
- package/lib/internal/Declared.d.ts.map +1 -0
- package/lib/internal/Declared.js +31 -0
- package/lib/internal/Declared.js.map +1 -0
- package/lib/internal/Derived.d.ts +40 -0
- package/lib/internal/Derived.d.ts.map +1 -0
- package/lib/internal/Derived.js +64 -0
- package/lib/internal/Derived.js.map +1 -0
- package/lib/internal/Errors.d.ts +4 -0
- package/lib/internal/Errors.d.ts.map +1 -0
- package/lib/internal/Errors.js +1 -0
- package/lib/internal/Errors.js.map +1 -0
- package/lib/internal/Labels.d.ts +20 -0
- package/lib/internal/Labels.d.ts.map +1 -0
- package/lib/internal/Labels.js +22 -0
- package/lib/internal/Labels.js.map +1 -0
- package/lib/internal/Names.d.ts +18 -0
- package/lib/internal/Names.d.ts.map +1 -0
- package/lib/internal/Names.js +25 -0
- package/lib/internal/Names.js.map +1 -0
- package/lib/internal/Organization.d.ts +27 -0
- package/lib/internal/Organization.d.ts.map +1 -0
- package/lib/internal/Organization.js +32 -0
- package/lib/internal/Organization.js.map +1 -0
- package/lib/internal/Process.d.ts +14 -0
- package/lib/internal/Process.d.ts.map +1 -0
- package/lib/internal/Process.js +15 -0
- package/lib/internal/Process.js.map +1 -0
- package/lib/internal/Program.d.ts +83 -0
- package/lib/internal/Program.d.ts.map +1 -0
- package/lib/internal/Program.js +169 -0
- package/lib/internal/Program.js.map +1 -0
- package/lib/internal/Ref.d.ts +14 -0
- package/lib/internal/Ref.d.ts.map +1 -0
- package/lib/internal/Ref.js +7 -0
- package/lib/internal/Ref.js.map +1 -0
- package/lib/internal/Scoped.d.ts +31 -0
- package/lib/internal/Scoped.d.ts.map +1 -0
- package/lib/internal/Scoped.js +48 -0
- package/lib/internal/Scoped.js.map +1 -0
- package/lib/internal/Tar.d.ts +13 -0
- package/lib/internal/Tar.d.ts.map +1 -0
- package/lib/internal/Tar.js +62 -0
- package/lib/internal/Tar.js.map +1 -0
- package/lib/internal/Toolbox.d.ts +11 -0
- package/lib/internal/Toolbox.d.ts.map +1 -0
- package/lib/internal/Toolbox.js +20 -0
- package/lib/internal/Toolbox.js.map +1 -0
- package/lib/internal/Wait.d.ts +49 -0
- package/lib/internal/Wait.d.ts.map +1 -0
- package/lib/internal/Wait.js +57 -0
- package/lib/internal/Wait.js.map +1 -0
- package/package.json +79 -3
- package/src/ApiKey.ts +221 -0
- package/src/AuthProvider.ts +406 -0
- package/src/Bootstrap.ts +55 -0
- package/src/ConnectSandbox.ts +76 -0
- package/src/ConnectSandboxHttp.ts +26 -0
- package/src/Contributions.ts +9 -0
- package/src/CreateSandbox.ts +107 -0
- package/src/CreateSandboxHttp.ts +97 -0
- package/src/CreateSecret.ts +73 -0
- package/src/CreateSecretHttp.ts +58 -0
- package/src/CreateSnapshot.ts +133 -0
- package/src/CreateSnapshotHttp.ts +77 -0
- package/src/CreateVolume.ts +104 -0
- package/src/CreateVolumeHttp.ts +50 -0
- package/src/Credentials.ts +37 -0
- package/src/DaytonaBindings.ts +111 -0
- package/src/IdentityProvider.ts +181 -0
- package/src/MountVolume.ts +122 -0
- package/src/OAuthClient.ts +27 -0
- package/src/Organization.ts +121 -0
- package/src/OrganizationInvitation.ts +174 -0
- package/src/OrganizationMember.ts +174 -0
- package/src/OrganizationOtelConfig.ts +138 -0
- package/src/OrganizationRole.ts +167 -0
- package/src/OrganizationSettings.ts +187 -0
- package/src/Providers.ts +93 -0
- package/src/ReadAuditLogs.ts +50 -0
- package/src/ReadOrganization.ts +83 -0
- package/src/ReadUsage.ts +51 -0
- package/src/Region.ts +226 -0
- package/src/Registry.ts +164 -0
- package/src/Runner.ts +166 -0
- package/src/Sandbox.ts +927 -0
- package/src/SandboxClient.ts +625 -0
- package/src/Secret.ts +203 -0
- package/src/Snapshot.ts +685 -0
- package/src/Volume.ts +229 -0
- package/src/WarmPool.ts +128 -0
- package/src/Webhooks.ts +121 -0
- package/src/globals.d.ts +2 -0
- package/src/index.ts +46 -0
- package/src/internal/BuildContext.ts +62 -0
- package/src/internal/Declared.ts +80 -0
- package/src/internal/Derived.ts +97 -0
- package/src/internal/Errors.ts +4 -0
- package/src/internal/Labels.ts +39 -0
- package/src/internal/Names.ts +37 -0
- package/src/internal/Organization.ts +40 -0
- package/src/internal/Process.ts +25 -0
- package/src/internal/Program.ts +239 -0
- package/src/internal/Ref.ts +15 -0
- package/src/internal/Scoped.ts +102 -0
- package/src/internal/Tar.ts +72 -0
- package/src/internal/Toolbox.ts +27 -0
- package/src/internal/Wait.ts +105 -0
package/src/Secret.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as secrets from "@distilled.cloud/daytona/secret";
|
|
3
|
+
import { Unowned } from "alchemy/AdoptPolicy";
|
|
4
|
+
import { deepEqual, isResolved } from "alchemy/Diff";
|
|
5
|
+
import * as Provider from "alchemy/Provider";
|
|
6
|
+
import { Resource } from "alchemy/Resource";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Redacted from "effect/Redacted";
|
|
9
|
+
import * as Stream from "effect/Stream";
|
|
10
|
+
import { isOwnedName, resolveName } from "./internal/Names.ts";
|
|
11
|
+
import type { Providers } from "./Providers.ts";
|
|
12
|
+
|
|
13
|
+
export interface SecretProps {
|
|
14
|
+
/**
|
|
15
|
+
* Secret name, unique in the organization (letters, digits, `-`, `_`).
|
|
16
|
+
* If omitted, a unique name is generated from the stack, stage and
|
|
17
|
+
* logical ID. Changing it replaces the secret.
|
|
18
|
+
*/
|
|
19
|
+
name?: string;
|
|
20
|
+
/** The secret value. Changing it updates the secret in place. */
|
|
21
|
+
value: string | Redacted.Redacted<string>;
|
|
22
|
+
/** What the secret is for. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The only hosts Daytona will send the real value to. A sandbox sees a
|
|
26
|
+
* placeholder in its environment; Daytona's egress proxy swaps in the
|
|
27
|
+
* value on requests to these hosts. Omit to allow any host.
|
|
28
|
+
*/
|
|
29
|
+
hosts?: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SecretAttributes {
|
|
33
|
+
/** Secret ID. */
|
|
34
|
+
secretId: string;
|
|
35
|
+
/** Secret name. */
|
|
36
|
+
name: string;
|
|
37
|
+
/**
|
|
38
|
+
* The placeholder a sandbox sees instead of the value. Put it in a
|
|
39
|
+
* sandbox's env (`env: { NPM_TOKEN: secret.placeholder }`) or pass the
|
|
40
|
+
* secret in `secrets`.
|
|
41
|
+
*/
|
|
42
|
+
placeholder: string;
|
|
43
|
+
/** Hosts the value may be sent to. */
|
|
44
|
+
hosts: string[];
|
|
45
|
+
/** Description, if any. */
|
|
46
|
+
description: string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* SHA-256 of the value last written. Daytona never returns a secret's
|
|
49
|
+
* value, so this is how reconcile knows whether to write it again.
|
|
50
|
+
*/
|
|
51
|
+
valueHash: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type Secret = Resource<"Daytona.Secret", SecretProps, SecretAttributes, never, Providers>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A secret stored in Daytona. A sandbox gets a placeholder in place of
|
|
58
|
+
* the value, and Daytona's egress proxy substitutes the real value only on
|
|
59
|
+
* requests to the secret's `hosts`, so code in the sandbox (or an agent
|
|
60
|
+
* running there) can use a credential without being able to read it.
|
|
61
|
+
*
|
|
62
|
+
* Declare a secret here for credentials the whole app shares. For a secret
|
|
63
|
+
* per user, create it at runtime with {@link CreateSecret}.
|
|
64
|
+
* @see https://www.daytona.io/docs/en/secrets/
|
|
65
|
+
*
|
|
66
|
+
* ### Creating a Secret
|
|
67
|
+
* **Example:** An npm token only sent to the registry
|
|
68
|
+
* ```typescript
|
|
69
|
+
* export const NpmToken = Daytona.Secret("NpmToken", {
|
|
70
|
+
* value: Config.Redacted("NPM_TOKEN"),
|
|
71
|
+
* hosts: ["registry.npmjs.org"],
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ### Using a Secret in a Sandbox
|
|
76
|
+
* **Example:** Expose it to a sandbox as an environment variable
|
|
77
|
+
* ```typescript
|
|
78
|
+
* export const DevBox = Daytona.Sandbox("DevBox", {
|
|
79
|
+
* snapshot: Base,
|
|
80
|
+
* secrets: { NPM_TOKEN: NpmToken },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @resource
|
|
85
|
+
* @product Secret
|
|
86
|
+
*/
|
|
87
|
+
export const Secret = Resource<Secret>("Daytona.Secret");
|
|
88
|
+
|
|
89
|
+
export const hashSecretValue = (value: string | Redacted.Redacted<string>) =>
|
|
90
|
+
Effect.sync(() =>
|
|
91
|
+
createHash("sha256")
|
|
92
|
+
.update(Redacted.isRedacted(value) ? Redacted.value(value) : value)
|
|
93
|
+
.digest("hex"),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
export const toSecretAttributes = (s: secrets.Secret2, valueHash: string): SecretAttributes => ({
|
|
97
|
+
secretId: s.id,
|
|
98
|
+
name: s.name,
|
|
99
|
+
placeholder: s.placeholder,
|
|
100
|
+
hosts: s.hosts,
|
|
101
|
+
description: s.description,
|
|
102
|
+
valueHash,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const getSecretById = (secretId: string) =>
|
|
106
|
+
secrets.getSecret({ secretId }).pipe(Effect.catchTag("SecretNotFound", () => Effect.undefined));
|
|
107
|
+
|
|
108
|
+
/** Exact-name lookup over the paginated list (its `name` filter is a substring match). */
|
|
109
|
+
export const findSecretByName = (name: string) =>
|
|
110
|
+
secrets.listSecretsPaginated.items({ name }).pipe(
|
|
111
|
+
Stream.filter((s) => s.name === name),
|
|
112
|
+
Stream.runHead,
|
|
113
|
+
Effect.map((found) => (found._tag === "Some" ? found.value : undefined)),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
export const ensureSecret = Effect.fn(function* (input: {
|
|
117
|
+
readonly name: string;
|
|
118
|
+
readonly value: string | Redacted.Redacted<string>;
|
|
119
|
+
readonly description?: string | undefined;
|
|
120
|
+
readonly hosts?: string[] | undefined;
|
|
121
|
+
readonly existing?: secrets.Secret2 | undefined;
|
|
122
|
+
readonly knownHash?: string | undefined;
|
|
123
|
+
}) {
|
|
124
|
+
const valueHash = yield* hashSecretValue(input.value);
|
|
125
|
+
const existing = input.existing ?? (yield* findSecretByName(input.name));
|
|
126
|
+
if (existing === undefined) {
|
|
127
|
+
const created = yield* secrets
|
|
128
|
+
.createSecret({
|
|
129
|
+
name: input.name,
|
|
130
|
+
value: input.value,
|
|
131
|
+
description: input.description,
|
|
132
|
+
hosts: input.hosts,
|
|
133
|
+
})
|
|
134
|
+
.pipe(Effect.catchTag("SecretAlreadyExists", () => Effect.undefined));
|
|
135
|
+
if (created !== undefined) return toSecretAttributes(created, valueHash);
|
|
136
|
+
}
|
|
137
|
+
const current = existing ?? (yield* findSecretByName(input.name));
|
|
138
|
+
if (current === undefined)
|
|
139
|
+
return yield* Effect.die(`Daytona secret ${input.name} vanished during create`);
|
|
140
|
+
// Sync — the value can't be observed, so it is rewritten unless the
|
|
141
|
+
// hash we last wrote matches. Description and hosts diff against cloud.
|
|
142
|
+
const hostsChanged =
|
|
143
|
+
input.hosts !== undefined && !deepEqual([...input.hosts].sort(), [...current.hosts].sort());
|
|
144
|
+
const descriptionChanged =
|
|
145
|
+
input.description !== undefined && input.description !== current.description;
|
|
146
|
+
const valueChanged = input.knownHash !== valueHash;
|
|
147
|
+
if (!hostsChanged && !descriptionChanged && !valueChanged)
|
|
148
|
+
return toSecretAttributes(current, valueHash);
|
|
149
|
+
const updated = yield* secrets.updateSecret({
|
|
150
|
+
secretId: current.id,
|
|
151
|
+
value: valueChanged ? input.value : undefined,
|
|
152
|
+
description: descriptionChanged ? input.description : undefined,
|
|
153
|
+
hosts: hostsChanged ? input.hosts : undefined,
|
|
154
|
+
});
|
|
155
|
+
return toSecretAttributes(updated, valueHash);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export const SecretProvider = () =>
|
|
159
|
+
Provider.effect(
|
|
160
|
+
Secret,
|
|
161
|
+
Effect.succeed({
|
|
162
|
+
stables: ["secretId", "placeholder"],
|
|
163
|
+
list: Effect.fn(function* () {
|
|
164
|
+
const all = yield* secrets.listSecretsPaginated.items({}).pipe(Stream.runCollect);
|
|
165
|
+
return Array.from(all).map((s) => toSecretAttributes(s, ""));
|
|
166
|
+
}),
|
|
167
|
+
diff: Effect.fn(function* ({ id, news, output }) {
|
|
168
|
+
if (!isResolved(news) || output === undefined) return undefined;
|
|
169
|
+
const name = yield* resolveName(
|
|
170
|
+
id,
|
|
171
|
+
news.name,
|
|
172
|
+
news.name === undefined ? output.name : undefined,
|
|
173
|
+
);
|
|
174
|
+
if (name !== output.name) return { action: "replace", deleteFirst: true } as const;
|
|
175
|
+
}),
|
|
176
|
+
read: Effect.fn(function* ({ id, olds, output }) {
|
|
177
|
+
const name = yield* resolveName(id, olds?.name, output?.name);
|
|
178
|
+
const found =
|
|
179
|
+
(output ? yield* getSecretById(output.secretId) : undefined) ??
|
|
180
|
+
(yield* findSecretByName(name));
|
|
181
|
+
if (found === undefined) return undefined;
|
|
182
|
+
const attrs = toSecretAttributes(found, output?.valueHash ?? "");
|
|
183
|
+
return (yield* isOwnedName(id, found.name, output !== undefined)) ? attrs : Unowned(attrs);
|
|
184
|
+
}),
|
|
185
|
+
reconcile: Effect.fn(function* ({ id, news, output }) {
|
|
186
|
+
const name = yield* resolveName(id, news.name, output?.name);
|
|
187
|
+
const byId = output ? yield* getSecretById(output.secretId) : undefined;
|
|
188
|
+
return yield* ensureSecret({
|
|
189
|
+
name,
|
|
190
|
+
value: news.value,
|
|
191
|
+
description: news.description,
|
|
192
|
+
hosts: news.hosts,
|
|
193
|
+
existing: byId?.name === name ? byId : undefined,
|
|
194
|
+
knownHash: byId?.name === name ? output?.valueHash : undefined,
|
|
195
|
+
});
|
|
196
|
+
}),
|
|
197
|
+
delete: Effect.fn(function* ({ output }) {
|
|
198
|
+
yield* secrets
|
|
199
|
+
.deleteSecret({ secretId: output.secretId })
|
|
200
|
+
.pipe(Effect.catchTag("SecretNotFound", () => Effect.void));
|
|
201
|
+
}),
|
|
202
|
+
}),
|
|
203
|
+
);
|