@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 73 lines 2.56 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { KeyPair } from "@alchemy.run/aws/EC2/KeyPair";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as ec2 from "@distilled.cloud/aws/ec2";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8 import * as Redacted from "effect/Redacted";
9 import { assertKeyPairGone } from "./Gone.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Create a generated key pair, assert the private key is captured, verify it
14 // exists out-of-band, then destroy it and confirm it is gone.
15 test.provider(
16 "create generates a key pair and captures the private key",
17 (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 const keyPair = yield* stack.deploy(
22 Effect.gen(function* () {
23 return yield* KeyPair("GeneratedKey", { keyType: "ed25519" });
24 }),
25 );
26
27 expect(keyPair.keyPairId).toMatch(/^key-/);
28 expect(keyPair.keyName).toBeTruthy();
29 expect(keyPair.keyType).toBe("ed25519");
30 expect(keyPair.keyFingerprint).toBeTruthy();
31 // AWS returns the private key exactly once, at create time.
32 expect(keyPair.privateKey).toBeDefined();
33 expect(Redacted.value(keyPair.privateKey!)).toContain("PRIVATE KEY");
34
35 // Verify out-of-band.
36 const described = yield* ec2.describeKeyPairs({ KeyPairIds: [keyPair.keyPairId] });
37 expect(described.KeyPairs?.[0]?.KeyName).toBe(keyPair.keyName);
38 expect(described.KeyPairs?.[0]?.KeyType).toBe("ed25519");
39
40 yield* stack.destroy();
41
42 // Confirm deletion.
43 const after = yield* ec2
44 .describeKeyPairs({ KeyNames: [keyPair.keyName] })
45 .pipe(Effect.catchTag("InvalidKeyPair.NotFound", () => Effect.succeed({ KeyPairs: [] })));
46 expect(after.KeyPairs ?? []).toHaveLength(0);
47 }),
48 { tags: ["provider:aws", "provider:aws:ec2", "live"] },
49 );
50
51 // `list()` enumerates branded key pairs in the account.
52 test.provider(
53 "list enumerates the deployed key pair",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const keyPair = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* KeyPair("ListKey", {});
61 }),
62 );
63
64 const provider = yield* Provider.findProvider(KeyPair);
65 const all = yield* provider.list();
66 expect(all.some((k) => k.keyPairId === keyPair.keyPairId)).toBe(true);
67
68 yield* stack.destroy();
69
70 yield* assertKeyPairGone(keyPair.keyPairId);
71 }),
72 { tags: ["provider:aws", "provider:aws:ec2", "live"] },
73 );