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 region = "us-central1"; |
| 14 | |
| 15 | const waitUntilGone = (project: string, sslPolicyName: string) => |
| 16 | compute.getRegionSslPolicies({ project, region, sslPolicy: sslPolicyName }).pipe( |
| 17 | Effect.as("found" as const), |
| 18 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 19 | Effect.repeat({ |
| 20 | schedule: Schedule.spaced("1 second"), |
| 21 | until: (status) => status === "gone", |
| 22 | times: 10, |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | const CUSTOM_FEATURES = [ |
| 27 | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", |
| 28 | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", |
| 29 | ]; |
| 30 | |
| 31 | test.provider( |
| 32 | "create, update, and delete a regional ssl policy", |
| 33 | (stack) => |
| 34 | Effect.gen(function* () { |
| 35 | yield* stack.destroy(); |
| 36 | |
| 37 | const created = yield* stack.deploy( |
| 38 | Effect.gen(function* () { |
| 39 | return yield* GCP.Compute.RegionSslPolicy("FrontendTls", { |
| 40 | region, |
| 41 | description: "frontend tls", |
| 42 | profile: "MODERN", |
| 43 | minTlsVersion: "TLS_1_2", |
| 44 | }); |
| 45 | }), |
| 46 | ); |
| 47 | |
| 48 | expect(created.sslPolicyName).toEqual(expect.any(String)); |
| 49 | expect(created.region).toEqual(region); |
| 50 | expect(created.profile).toEqual("MODERN"); |
| 51 | expect(created.minTlsVersion).toEqual("TLS_1_2"); |
| 52 | expect(created.description).toEqual("frontend tls"); |
| 53 | expect(created.enabledFeatures.length).toBeGreaterThan(0); |
| 54 | expect(created.selfLink).toEqual(expect.any(String)); |
| 55 | |
| 56 | const fetched = yield* compute.getRegionSslPolicies({ |
| 57 | project: created.project, |
| 58 | region, |
| 59 | sslPolicy: created.sslPolicyName, |
| 60 | }); |
| 61 | expect(fetched.name).toEqual(created.sslPolicyName); |
| 62 | expect(fetched.profile).toEqual("MODERN"); |
| 63 | expect(fetched.minTlsVersion).toEqual("TLS_1_2"); |
| 64 | expect(fetched.description).toContain("[alchemy "); |
| 65 | expect(fetched.description).toContain("frontend tls"); |
| 66 | |
| 67 | const listed = yield* compute.listRegionSslPolicies({ |
| 68 | project: created.project, |
| 69 | region, |
| 70 | maxResults: 500, |
| 71 | }); |
| 72 | expect((listed.items ?? []).some((policy) => policy.name === created.sslPolicyName)).toEqual( |
| 73 | true, |
| 74 | ); |
| 75 | |
| 76 | const updated = yield* stack.deploy( |
| 77 | Effect.gen(function* () { |
| 78 | return yield* GCP.Compute.RegionSslPolicy("FrontendTls", { |
| 79 | sslPolicyName: created.sslPolicyName, |
| 80 | region, |
| 81 | description: "strict tls", |
| 82 | profile: "RESTRICTED", |
| 83 | minTlsVersion: "TLS_1_2", |
| 84 | }); |
| 85 | }), |
| 86 | ); |
| 87 | |
| 88 | expect(updated.sslPolicyName).toEqual(created.sslPolicyName); |
| 89 | expect(updated.profile).toEqual("RESTRICTED"); |
| 90 | expect(updated.minTlsVersion).toEqual("TLS_1_2"); |
| 91 | expect(updated.description).toEqual("strict tls"); |
| 92 | |
| 93 | const refetched = yield* compute.getRegionSslPolicies({ |
| 94 | project: updated.project, |
| 95 | region, |
| 96 | sslPolicy: updated.sslPolicyName, |
| 97 | }); |
| 98 | expect(refetched.profile).toEqual("RESTRICTED"); |
| 99 | expect(refetched.minTlsVersion).toEqual("TLS_1_2"); |
| 100 | expect(refetched.description).toContain("strict tls"); |
| 101 | |
| 102 | const customized = yield* stack.deploy( |
| 103 | Effect.gen(function* () { |
| 104 | return yield* GCP.Compute.RegionSslPolicy("FrontendTls", { |
| 105 | sslPolicyName: created.sslPolicyName, |
| 106 | region, |
| 107 | description: "custom ciphers", |
| 108 | profile: "CUSTOM", |
| 109 | minTlsVersion: "TLS_1_2", |
| 110 | customFeatures: CUSTOM_FEATURES, |
| 111 | }); |
| 112 | }), |
| 113 | ); |
| 114 | |
| 115 | expect(customized.sslPolicyName).toEqual(created.sslPolicyName); |
| 116 | expect(customized.profile).toEqual("CUSTOM"); |
| 117 | expect(customized.customFeatures.sort()).toEqual([...CUSTOM_FEATURES].sort()); |
| 118 | expect(customized.description).toEqual("custom ciphers"); |
| 119 | |
| 120 | const afterCustom = yield* compute.getRegionSslPolicies({ |
| 121 | project: customized.project, |
| 122 | region, |
| 123 | sslPolicy: customized.sslPolicyName, |
| 124 | }); |
| 125 | expect(afterCustom.profile).toEqual("CUSTOM"); |
| 126 | expect([...(afterCustom.customFeatures ?? [])].sort()).toEqual([...CUSTOM_FEATURES].sort()); |
| 127 | |
| 128 | yield* stack.destroy(); |
| 129 | |
| 130 | const gone = yield* waitUntilGone(created.project, created.sslPolicyName); |
| 131 | expect(gone).toEqual("gone"); |
| 132 | }).pipe(logLevel), |
| 133 | { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 }, |
| 134 | ); |