Skip to content

Commit 7c347df

Browse files
authored
fix: don't create org tokens in sandbox subcommand (#29)
1 parent a801179 commit 7c347df

3 files changed

Lines changed: 19 additions & 29 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"imports": {
1818
"@cfa/gitignore-parser": "jsr:@cfa/gitignore-parser@^0.1.4",
1919
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.8",
20-
"@deno/sandbox": "jsr:@deno/sandbox@^0.2.1",
20+
"@deno/sandbox": "jsr:@deno/sandbox@^0.4.1",
2121
"@std/cli": "jsr:@std/cli@1.0.22",
2222
"@std/dotenv": "jsr:@std/dotenv@^0.225.5",
2323
"@std/encoding": "jsr:@std/encoding@^1.0.10",

deno.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sandbox.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { green, magenta, red } from "@std/fmt/colors";
44

55
import { getAppFromConfig, readConfig } from "./config.ts";
66
import { renderTemporalTimestamp, withApp } from "./util.ts";
7-
import { createTrpcClient } from "./auth.ts";
7+
import { createTrpcClient, getAuth } from "./auth.ts";
88
import type { GlobalOptions } from "./main.ts";
99

1010
type SandboxContext = GlobalOptions & {
@@ -15,18 +15,12 @@ export const sandboxNewCommand = new Command<SandboxContext>()
1515
.description("Create a new sandbox in an organization")
1616
.action(async (options) => {
1717
const org = await ensureOrg(options);
18-
const client = createTrpcClient(options.debug, options.endpoint);
19-
20-
// deno-lint-ignore no-explicit-any
21-
const token = await (client.orgs as any).accessTokens.create.mutate({
22-
org,
23-
description: "$$DENO_DEPLOY_CLI_SSH_TOKEN$$",
24-
expiresAt: new Date(Date.now() + 1000 * 60 * 60).toISOString(), // 1 hour
25-
});
18+
const token = await getAuth(options.debug, options.endpoint);
2619

2720
const sandbox = await Sandbox.create({
2821
debug: options.debug,
29-
token: token.token,
22+
token: token,
23+
org,
3024
});
3125

3226
const success = await sshIntoSandbox(sandbox);
@@ -147,23 +141,19 @@ export const sandboxSshCommand = new Command<SandboxContext>()
147141
.action(async (options, sandboxId) => {
148142
const org = await ensureOrg(options);
149143
const client = createTrpcClient(options.debug, options.endpoint);
150-
151-
const [cluster, token] = await Promise.all([
152-
// deno-lint-ignore no-explicit-any
153-
(client.sandboxes as any).findHostname.query({ org, sandboxId }),
154-
// deno-lint-ignore no-explicit-any
155-
(client.orgs as any).accessTokens.create.mutate({
156-
org,
157-
description: "$$DENO_DEPLOY_CLI_SSH_TOKEN$$",
158-
expiresAt: new Date(Date.now() + 1000 * 60 * 60).toISOString(),
159-
}),
160-
]);
144+
const token = await getAuth(options.debug, options.endpoint);
145+
// deno-lint-ignore no-explicit-any
146+
const cluster = await (client.sandboxes as any).findHostname.query({
147+
org,
148+
sandboxId,
149+
});
161150

162151
await using sandbox = await Sandbox.connect({
163152
id: sandboxId,
164153
region: cluster.region,
165154
debug: options.debug,
166-
token: token.token,
155+
token: token,
156+
org,
167157
});
168158
await sshIntoSandbox(sandbox);
169159
});

0 commit comments

Comments
 (0)