1import * as GCP from "@/GCP";
2import * as Effect from "effect/Effect";
3import { serveProbes } from "../../bindingHost.ts";
4
5/**
6 * Memcached instances need Private Service Access on the project's default
7 * network (without it create fails with BadRequest "Google private service
8 * access is not enabled.") and take ~10 minutes to provision, so
9 * `GCP_TEST_PRIVATE_SERVICE_ACCESS=1` + `GCP_TEST_SLOW=1` opt in. The gate
10 * is forwarded to the host's environment so the deployed runtime binds the
11 * same set.
12 */
13export const memcacheEnabled =
14 !!process.env.GCP_TEST_PRIVATE_SERVICE_ACCESS &&
15 !!process.env.GCP_TEST_SLOW &&
16 !process.env.FAST;
17
18/** Instance the binding is granted for; declared only when enabled. */
19export const Cache = GCP.Memcache.Instance("Cache", {
20 location: "us-central1",
21});
22
23const instanceProbes = Effect.gen(function* () {
24 const getInstance = yield* GCP.Memcache.GetInstance(Cache);
25 return { getInstance: getInstance() };
26});
27
28/**
29 * Effect-native Cloud Run service exercising the Memcache binding as its own
30 * runtime service account. Deployed from {@link ../Bindings.test.ts}.
31 */
32export default class MemcacheBindingsHost extends GCP.Function<MemcacheBindingsHost>()(
33 "MemcacheBindingsHost",
34 {
35 main: import.meta.url,
36 invokerIamDisabled: true,
37 env: {
38 GCP_TEST_PRIVATE_SERVICE_ACCESS: memcacheEnabled ? "1" : "",
39 GCP_TEST_SLOW: memcacheEnabled ? "1" : "",
40 },
41 },
42 Effect.gen(function* () {
43 const instance = memcacheEnabled ? yield* instanceProbes : {};
44 return { fetch: serveProbes({ ...instance }) };
45 }).pipe(Effect.provide(GCP.Memcache.GetInstanceHttp)),
46) {}