diff --git a/preview/apitypes/apitypes.go b/preview/apitypes/apitypes.go index 95dee72..e2144b6 100644 --- a/preview/apitypes/apitypes.go +++ b/preview/apitypes/apitypes.go @@ -33,6 +33,8 @@ const ( OptionTypeListString OptionType = "list(string)" ) +type WorkspaceOwner = types.WorkspaceOwner + type PreviewOutput struct { Output *Output `json:"output"` Diags types.Diagnostics `json:"diags"` diff --git a/preview/main.go b/preview/main.go index c3666c6..8e14754 100644 --- a/preview/main.go +++ b/preview/main.go @@ -18,7 +18,6 @@ import ( "github.com/coder/preview" "github.com/coder/preview/types" - "github.com/coder/parameters-playground/preview/apitypes" ) @@ -61,12 +60,17 @@ func tfpreview(this js.Value, p []js.Value) (output any) { return err } + owner, err := workspaceOwner(p[1]) + if err != nil { + return err + } + handler := slog.NewJSONHandler(l, nil) logger := slog.New(handler) var parameters map[string]string - if len(p) >= 2 { - params, err := jsValueToStringMap(p[1]) + if len(p) >= 3 { + params, err := jsValueToStringMap(p[2]) if err != nil { logger.Error("Unable to convert second prameter into map[string]string", "err", err) } @@ -81,7 +85,7 @@ func tfpreview(this js.Value, p []js.Value) (output any) { PlanJSONPath: "", PlanJSON: nil, ParameterValues: parameters, - Owner: types.WorkspaceOwner{}, + Owner: owner, Logger: logger, }, tf) @@ -110,6 +114,16 @@ func fileTreeFS(value js.Value) (fs.FS, error) { return afero.NewIOFS(mem), nil } +func workspaceOwner(value js.Value) (apitypes.WorkspaceOwner, error) { + data := js.Global().Get("JSON").Call("stringify", value).String() + var owner apitypes.WorkspaceOwner + if err := json.Unmarshal([]byte(data), &owner); err != nil { + return apitypes.WorkspaceOwner(types.WorkspaceOwner{}), err + } + + return owner, nil +} + func loadTree(mem afero.Fs, fileTree map[string]any, path ...string) { dir := filepath.Join(path...) err := mem.MkdirAll(dir, 0755) diff --git a/public/build/preview.wasm b/public/build/preview.wasm index 1ef37b0..fb523a5 100755 Binary files a/public/build/preview.wasm and b/public/build/preview.wasm differ diff --git a/src/client/App.tsx b/src/client/App.tsx index 47a3bf6..967c3e8 100644 --- a/src/client/App.tsx +++ b/src/client/App.tsx @@ -31,9 +31,11 @@ import { } from "@/client/components/Tooltip"; import { rpc } from "@/utils/rpc"; import { useLoaderData, type LoaderFunctionArgs } from "react-router"; +import type {WorkspaceOwner} from "@/gen/types.ts"; type GoPreviewDef = ( v: Record, + owner: WorkspaceOwner, params: Record, ) => Promise; diff --git a/src/client/Preview.tsx b/src/client/Preview.tsx index d6e2e8d..96af017 100644 --- a/src/client/Preview.tsx +++ b/src/client/Preview.tsx @@ -14,7 +14,7 @@ import { } from "@/client/diagnostics"; import { useDebouncedValue } from "@/client/hooks/debounce"; import { useStore } from "@/client/store"; -import type { Parameter, ParserLog, PreviewOutput } from "@/gen/types"; +import type {Parameter, ParserLog, PreviewOutput} from "@/gen/types"; import { cn } from "@/utils/cn"; import ReactJsonView from "@microlink/react-json-view"; import * as Dialog from "@radix-ui/react-dialog"; @@ -83,6 +83,16 @@ export const Preview: FC = () => { { "main.tf": debouncedCode, }, + { + id: "8d36e355-e775-4c49-9b8d-ac042ed50440", + name: "coder", + full_name: "Coder", + email: "coder@coder.com", + ssh_public_key: "", + groups: ["Everyone"], + login_type: "password", + rbac_roles: [{name:"member", org_id:""}, {name:"organization-member",org_id:"09942665-ba1b-4661-be9f-36bf9f738c83"}] + }, $form, ); diff --git a/src/gen/types.ts b/src/gen/types.ts index 762e2e3..4e57ba8 100644 --- a/src/gen/types.ts +++ b/src/gen/types.ts @@ -134,4 +134,22 @@ export interface Range { End: Pos; } +// From apitypes/apitypes.go +export interface WorkspaceOwner { + id: string; + name: string; + full_name: string; + email: string; + ssh_public_key: string; + groups: string[]; + login_type: string; + rbac_roles: WorkspaceOwnerRBACRole[]; +} + +// From types/owner.go +export interface WorkspaceOwnerRBACRole { + name: string; + org_id: string; +} +