Skip to content

Commit 8f26d74

Browse files
authored
fix: hostcall token issue (#1010)
1 parent cf3da01 commit 8f26d74

File tree

7 files changed

+54
-54
lines changed

7 files changed

+54
-54
lines changed

src/typegate/src/runtimes/deno/deno.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ export class DenoRuntime extends Runtime {
163163
}
164164
}
165165

166-
const token = await InternalAuth.emit(typegate.cryptoKeys);
167-
168166
const hostcallCtx = {
169-
authToken: token,
170167
typegate,
171168
typegraphUrl: new URL(
172169
`internal+hostcall+deno://typegate/${typegraphName}`,

src/typegate/src/runtimes/python.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ export class PythonRuntime extends Runtime {
122122

123123
// add default vm for lambda/def
124124
const uuid = crypto.randomUUID();
125-
const token = await InternalAuth.emit(typegate.cryptoKeys);
126125

127126
const hostcallCtx = {
128-
authToken: token,
129127
typegate,
130128
typegraphUrl: new URL(
131129
`internal+hostcall+witwire://typegate/${typegraphName}`,

src/typegate/src/runtimes/substantial.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ export class SubstantialRuntime extends Runtime {
118118
maxAcquirePerTick: typegate.config.base.substantial_max_acquire_per_tick!,
119119
} satisfies AgentConfig;
120120

121-
const token = await InternalAuth.emit(typegate.cryptoKeys);
122-
123121
const hostcallCtx = {
124-
authToken: token,
125122
typegate,
126123
typegraphUrl: new URL(
127124
`internal+hostcall+subs://typegate/${params.typegraphName}`,

src/typegate/src/runtimes/wasm_wire.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export class WasmRuntimeWire extends Runtime {
5353
};
5454

5555
const uuid = crypto.randomUUID();
56-
const token = await InternalAuth.emit(typegate.cryptoKeys);
57-
const componentPath =
58-
await typegate.artifactStore.getLocalPath(artifactMeta);
56+
const componentPath = await typegate.artifactStore.getLocalPath(
57+
artifactMeta,
58+
);
5959

6060
const wireMat = materializers.map((mat) => ({
6161
op_name: mat.data.op_name as string,
@@ -66,9 +66,10 @@ export class WasmRuntimeWire extends Runtime {
6666
}));
6767

6868
const hostcallCtx = {
69-
authToken: token,
7069
typegate,
71-
typegraphUrl: new URL(`internal+hostcall+witwire://typegate/${typegraphName}`),
70+
typegraphUrl: new URL(
71+
`internal+hostcall+witwire://typegate/${typegraphName}`,
72+
),
7273
};
7374

7475
const workerManager = new WorkerManager(hostcallCtx);

src/typegate/src/runtimes/wit_wire/hostcall.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import * as zod from "zod";
55
import type { Typegate } from "../../typegate/mod.ts";
66
import { getLogger } from "../../log.ts";
7+
import { InternalAuth } from "../../services/auth/protocols/internal.ts";
78

89
const logger = getLogger(import.meta);
910

1011
export type HostCallCtx = {
1112
typegate: Typegate;
12-
authToken: string;
1313
typegraphUrl: URL;
1414
};
1515

@@ -64,7 +64,7 @@ async function gql(cx: HostCallCtx, args: object) {
6464
throw new Error("error validating gql args", {
6565
cause: {
6666
zodErr: parseRes.error,
67-
args
67+
args,
6868
},
6969
});
7070
}
@@ -82,12 +82,13 @@ async function gql(cx: HostCallCtx, args: object) {
8282
}
8383
}
8484

85+
const token = await InternalAuth.emit(cx.typegate.cryptoKeys);
8586
const request = new Request(cx.typegraphUrl, {
8687
method: "POST",
8788
headers: {
8889
accept: "application/json",
8990
"content-type": "application/json",
90-
authorization: `Bearer ${cx.authToken}`,
91+
authorization: `Bearer ${token}`,
9192
},
9293
body: JSON.stringify({
9394
query: parsed.query,

tools/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ENV GHJK_ENV=oci
6262
ENV GHJK_ACTIVATE=.ghjk/envs/$GHJK_ENV/activate.sh
6363
RUN ghjk envs cook
6464

65-
SHELL ["/bin/sh", "-c", ". .ghjk/envs/oci/activate.sh && sh -c \"$*\"", "sh"]
65+
SHELL ["/bin/sh", "-c", ". ${GHJK_ACTIVATE} && sh -c \"$*\"", "sh"]
6666

6767
COPY --from=plan /app/recipe.json recipe.json
6868

tools/list-duplicates.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -337,46 +337,52 @@ export function listDuplicates(tg: TypeGraphDS, rootIdx = 0) {
337337
}
338338
}
339339

340-
const args = parseArgs(Deno.args, {
341-
string: ["root"],
342-
});
340+
// const args = parseArgs(Deno.args, {
341+
// string: ["root"],
342+
// });
343+
//
344+
// const rootIdx = argToInt(args.root, 0);
345+
//
346+
// const files = args._ as string[];
347+
// if (files.length === 0) {
348+
// throw new Error("Path to typegraph definition module is required.");
349+
// }
350+
// if (files.length > 1) {
351+
// throw new Error("Cannot accept more than one file");
352+
// }
353+
// const cmd = [
354+
// "cargo",
355+
// "run",
356+
// "--manifest-path",
357+
// `${projectDir}/Cargo.toml`,
358+
// "-p",
359+
// "meta-cli",
360+
// "--",
361+
// "serialize",
362+
// "-f",
363+
// files[0],
364+
// ];
365+
// const { stdout } = await new Deno.Command(cmd[0], {
366+
// args: cmd.slice(1),
367+
// stdout: "piped",
368+
// stderr: "inherit",
369+
// }).output();
370+
//
371+
// function argToInt(arg: string | undefined, defaultValue: number): number {
372+
// const parsed = parseInt(arg ?? `${defaultValue}`);
373+
// return isNaN(parsed) ? defaultValue : parsed;
374+
// }
343375

344-
const rootIdx = argToInt(args.root, 0);
345-
346-
const files = args._ as string[];
347-
if (files.length === 0) {
348-
throw new Error("Path to typegraph definition module is required.");
349-
}
350-
if (files.length > 1) {
351-
throw new Error("Cannot accept more than one file");
376+
let raw = "";
377+
const decoder = new TextDecoder();
378+
for await (const chunk of Deno.stdin.readable) {
379+
raw += decoder.decode(chunk);
380+
// do something with the text
352381
}
353-
const cmd = [
354-
"cargo",
355-
"run",
356-
"--manifest-path",
357-
`${projectDir}/Cargo.toml`,
358-
"-p",
359-
"meta-cli",
360-
"--",
361-
"serialize",
362-
"-f",
363-
files[0],
364-
];
365-
const { stdout } = await new Deno.Command(cmd[0], {
366-
args: cmd.slice(1),
367-
stdout: "piped",
368-
stderr: "inherit",
369-
}).output();
370382

371-
const tgs: TypeGraphDS[] = JSON.parse(
372-
new TextDecoder().decode(stdout),
373-
);
383+
// const raw = new TextDecoder().decode(stdout),
384+
const tgs: TypeGraphDS[] = JSON.parse(raw);
374385

375386
for (const tg of tgs) {
376-
listDuplicatesEnhanced(tg, rootIdx);
377-
}
378-
379-
function argToInt(arg: string | undefined, defaultValue: number): number {
380-
const parsed = parseInt(arg ?? `${defaultValue}`);
381-
return isNaN(parsed) ? defaultValue : parsed;
387+
listDuplicatesEnhanced(tg, 0);
382388
}

0 commit comments

Comments
 (0)