Skip to content

Commit

Permalink
Merge pull request #4 from subquery/fix-sandbox-config
Browse files Browse the repository at this point in the history
Fix sandbox loading config via env
  • Loading branch information
stwiname authored Oct 10, 2024
2 parents 829e6c7 + 4dad1ab commit b49f843
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-sys --allow-read --allow-write --allow-ffi --allow-run --unstable-worker-options
#!/usr/bin/env -S deno run --allow-env --allow-net --allow-sys --allow-read --allow-write --allow-ffi --allow-run --unstable-worker-options --no-prompt
// TODO limit --allow-ffi to just lancedb
// TODO limit --deny-net on localhost except ollama/db
// TODO limit --allow-run needed for Deno.exit
Expand Down
3 changes: 2 additions & 1 deletion src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ const ProjectEntrypointGen = <T extends TObject>(t: T) =>

export async function getProjectFromEntrypoint(
entrypoint: unknown,
providedConfig?: Record<string, string>,
): Promise<IProject> {
if (!entrypoint) {
throw new Error("Project entry is invalid");
}
// Validate the entrypoint
if (validateProjectEntry(entrypoint)) {
const config = loadConfigFromEnv(entrypoint.configType);
const config = loadConfigFromEnv(entrypoint.configType, providedConfig);

// Check that the constructed project is valid
const project = await entrypoint.projectFactory(config);
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/webWorker/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type IProjectJson = Omit<IProject, "tools"> & { tools: Tool[] };
// Framework -> Sandbox
export const Load = new rpc.RequestType<string, void, string>("load");
export const Init = new rpc.RequestType<
Record<string, unknown>,
Record<string, string>,
IProjectJson,
string
>("init");
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/webWorker/webWorkerSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class WebWorkerSandbox implements ISandbox {
type: "module",
deno: {
permissions: {
env: true, // TODO limit this
env: false, // Should be passed through in loadConfigFromEnv below
// hrtime: false,
net: "inherit", // TODO remove localhost
ffi: true, // Needed for node js ffi
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { brightBlue } from "@std/fmt/colors";

export function loadConfigFromEnv<T extends TSchema>(
schema?: T,
envObj?: Record<string, string>,
): Static<T> | undefined {
if (!schema) return undefined;
const envObj = Deno.env.toObject();
envObj ??= Deno.env.toObject();
return Value.Parse(schema, envObj);
}

Expand Down

0 comments on commit b49f843

Please sign in to comment.