@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, 04:45 UTC

main
ts 62 lines 2.2 KB
Raw
1 import * as dataproc from "@distilled.cloud/gcp/dataproc_v1";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import type { Cluster } from "./Cluster.ts";
6 import { SubmitJob, type SubmitJobRequest } from "./SubmitJob.ts";
7
8 /**
9 * HTTP implementation of {@link SubmitJob}.
10 *
11 * Grants `roles/dataproc.editor` on the project because
12 * `dataproc.jobs.create` is checked on the project (jobs are not children
13 * of the cluster, so neither a cluster-level grant nor an IAM Condition on
14 * the cluster name applies) and no narrower predefined role contains it.
15 *
16 * @layer
17 * @provides GCP.Dataproc.SubmitJob
18 */
19 export const SubmitJobHttp = Layer.effect(
20 SubmitJob,
21 Effect.gen(function* () {
22 const bind = yield* GCPBindings.Bind;
23 const submitProjectsRegionsJobs = yield* GCPBindings.withCredentials(
24 dataproc.submitProjectsRegionsJobs,
25 );
26 return Effect.fn(function* <T extends Cluster>(cluster: T) {
27 if (!globalThis.__ALCHEMY_RUNTIME__) {
28 yield* bind`GCP.Dataproc.SubmitJob(${cluster})`({
29 // dataproc.jobs.create is checked on the project (jobs are not
30 // children of the cluster); no narrower predefined role contains it.
31 iam: [{ role: "roles/dataproc.editor" }],
32 });
33 }
34 const projectId = yield* cluster.project;
35 const region = yield* cluster.region;
36 const clusterName = yield* cluster.clusterName;
37 return Effect.fn(`GCP.Dataproc.SubmitJob(${cluster.LogicalId})`)(function* (
38 request: SubmitJobRequest,
39 ) {
40 const resolvedProject = yield* projectId;
41 const resolvedRegion = yield* region;
42 const resolvedCluster = yield* clusterName;
43 const job = request.body?.job;
44 return yield* submitProjectsRegionsJobs({
45 ...request,
46 projectId: resolvedProject,
47 region: resolvedRegion,
48 body: {
49 ...request?.body,
50 job: {
51 ...job,
52 placement: {
53 ...job?.placement,
54 clusterName: job?.placement?.clusterName ?? resolvedCluster,
55 },
56 },
57 },
58 });
59 });
60 });
61 }),
62 );