Skip to content

Commit a8d8a35

Browse files
authored
feat(core): pass auth data to workspace (#22897)
1 parent 9b77430 commit a8d8a35

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

packages/opencode/src/auth/auth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export const layer = Layer.effect(
5656
const decode = Schema.decodeUnknownOption(Info)
5757

5858
const all = Effect.fn("Auth.all")(function* () {
59+
if (process.env.OPENCODE_AUTH_CONTENT) {
60+
try {
61+
return JSON.parse(process.env.OPENCODE_AUTH_CONTENT)
62+
} catch (err) {}
63+
}
64+
5965
const data = (yield* fsys.readJson(file).pipe(Effect.orElseSucceed(() => ({})))) as Record<string, unknown>
6066
return Record.filterMap(data, (value) => Result.fromOption(decode(value), () => undefined))
6167
})

packages/opencode/src/control-plane/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type WorkspaceAdaptor = {
2828
name: string
2929
description: string
3030
configure(info: WorkspaceInfo): WorkspaceInfo | Promise<WorkspaceInfo>
31-
create(info: WorkspaceInfo, from?: WorkspaceInfo): Promise<void>
31+
create(info: WorkspaceInfo, env: Record<string, string>, from?: WorkspaceInfo): Promise<void>
3232
remove(info: WorkspaceInfo): Promise<void>
3333
target(info: WorkspaceInfo): Target | Promise<Target>
3434
}

packages/opencode/src/control-plane/workspace.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Database, asc, eq, inArray } from "@/storage"
55
import { Project } from "@/project"
66
import { BusEvent } from "@/bus/bus-event"
77
import { GlobalBus } from "@/bus/global"
8+
import { Auth } from "@/auth"
89
import { SyncEvent } from "@/sync"
910
import { EventTable } from "@/sync/event.sql"
1011
import { Flag } from "@/flag/flag"
@@ -112,7 +113,12 @@ export namespace Workspace {
112113
.run()
113114
})
114115

115-
await adaptor.create(config)
116+
const env = {
117+
OPENCODE_AUTH_CONTENT: JSON.stringify(await AppRuntime.runPromise(Auth.Service.use((auth) => auth.all()))),
118+
OPENCODE_WORKSPACE_ID: config.id,
119+
OPENCODE_EXPERIMENTAL_WORKSPACES: "true"
120+
}
121+
await adaptor.create(config, env)
116122

117123
startSync(info)
118124

packages/opencode/src/server/proxy.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ export namespace ServerProxy {
110110
req: Request,
111111
workspaceID: WorkspaceID,
112112
) {
113-
console.log("proxy http request", {
114-
method: req.method,
115-
request: req.url,
116-
url: String(url),
117-
})
118-
119113
if (!Workspace.isSyncing(workspaceID)) {
120114
return new Response(`broken sync connection for workspace: ${workspaceID}`, {
121115
status: 503,

0 commit comments

Comments
 (0)