The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as compute from "@distilled.cloud/gcp/compute_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 12 | |
| 13 | const waitUntilGone = (project: string, sslPolicyName: string) => |
| 14 | compute.getSslPolicies({ project, sslPolicy: sslPolicyName }).pipe( |
| 15 | Effect.as("found" as const), |
| 16 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("1 second"), |
| 19 | until: (status) => status === "gone", |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | |
| 24 | const CUSTOM_FEATURES = [ |
| 25 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", |
| 26 | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", |
| 27 | ]; |
| 28 | |
| 29 | test.provider( |
| 30 | "create, update, and delete an ssl policy", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const created = yield* stack.deploy( |
| 36 | Effect.gen(function* () { |
| 37 | return yield* GCP.Compute.SslPolicy("FrontendTls", { |
| 38 | description: "frontend tls", |
| 39 | profile: "MODERN", |
| 40 | minTlsVersion: "TLS_1_2", |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | expect(created.sslPolicyName).toEqual(expect.any(String)); |
| 46 | expect(created.profile).toEqual("MODERN"); |
| 47 | expect(created.minTlsVersion).toEqual("TLS_1_2"); |
| 48 | expect(created.description).toEqual("frontend tls"); |
| 49 | expect(created.enabledFeatures.length).toBeGreaterThan(0); |
| 50 | expect(created.selfLink).toEqual(expect.any(String)); |
| 51 | |
| 52 | const fetched = yield* compute.getSslPolicies({ |
| 53 | project: created.project, |
| 54 | sslPolicy: created.sslPolicyName, |
| 55 | }); |
| 56 | expect(fetched.name).toEqual(created.sslPolicyName); |
| 57 | expect(fetched.profile).toEqual("MODERN"); |
| 58 | expect(fetched.minTlsVersion).toEqual("TLS_1_2"); |
| 59 | expect(fetched.description).toContain("[alchemy "); |
| 60 | expect(fetched.description).toContain("frontend tls"); |
| 61 | |
| 62 | const listed = yield* compute.listSslPolicies({ |
| 63 | project: created.project, |
| 64 | maxResults: 500, |
| 65 | }); |
| 66 | expect((listed.items ?? []).some((policy) => policy.name === created.sslPolicyName)).toEqual( |
| 67 | true, |
| 68 | ); |
| 69 | |
| 70 | const updated = yield* stack.deploy( |
| 71 | Effect.gen(function* () { |
| 72 | return yield* GCP.Compute.SslPolicy("FrontendTls", { |
| 73 | sslPolicyName: created.sslPolicyName, |
| 74 | description: "strict tls", |
| 75 | profile: "RESTRICTED", |
| 76 | minTlsVersion: "TLS_1_2", |
| 77 | }); |
| 78 | }), |
| 79 | ); |
| 80 | |
| 81 | expect(updated.sslPolicyName).toEqual(created.sslPolicyName); |
| 82 | expect(updated.profile).toEqual("RESTRICTED"); |
| 83 | expect(updated.minTlsVersion).toEqual("TLS_1_2"); |
| 84 | expect(updated.description).toEqual("strict tls"); |
| 85 | |
| 86 | const refetched = yield* compute.getSslPolicies({ |
| 87 | project: updated.project, |
| 88 | sslPolicy: updated.sslPolicyName, |
| 89 | }); |
| 90 | expect(refetched.profile).toEqual("RESTRICTED"); |
| 91 | expect(refetched.minTlsVersion).toEqual("TLS_1_2"); |
| 92 | expect(refetched.description).toContain("strict tls"); |
| 93 | |
| 94 | const customized = yield* stack.deploy( |
| 95 | Effect.gen(function* () { |
| 96 | return yield* GCP.Compute.SslPolicy("FrontendTls", { |
| 97 | sslPolicyName: created.sslPolicyName, |
| 98 | description: "custom ciphers", |
| 99 | profile: "CUSTOM", |
| 100 | minTlsVersion: "TLS_1_2", |
| 101 | customFeatures: CUSTOM_FEATURES, |
| 102 | }); |
| 103 | }), |
| 104 | ); |
| 105 | |
| 106 | expect(customized.sslPolicyName).toEqual(created.sslPolicyName); |
| 107 | expect(customized.profile).toEqual("CUSTOM"); |
| 108 | expect(customized.customFeatures.sort()).toEqual([...CUSTOM_FEATURES].sort()); |
| 109 | expect(customized.description).toEqual("custom ciphers"); |
| 110 | |
| 111 | const afterCustom = yield* compute.getSslPolicies({ |
| 112 | project: customized.project, |
| 113 | sslPolicy: customized.sslPolicyName, |
| 114 | }); |
| 115 | expect(afterCustom.profile).toEqual("CUSTOM"); |
| 116 | expect([...(afterCustom.customFeatures ?? [])].sort()).toEqual([...CUSTOM_FEATURES].sort()); |
| 117 | |
| 118 | yield* stack.destroy(); |
| 119 | |
| 120 | const gone = yield* waitUntilGone(created.project, created.sslPolicyName); |
| 121 | expect(gone).toEqual("gone"); |
| 122 | }).pipe(logLevel), |
| 123 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 124 | ); |