@@ -4,7 +4,7 @@ import { green, magenta, red } from "@std/fmt/colors";
44
55import { getAppFromConfig , readConfig } from "./config.ts" ;
66import { renderTemporalTimestamp , withApp } from "./util.ts" ;
7- import { createTrpcClient } from "./auth.ts" ;
7+ import { createTrpcClient , getAuth } from "./auth.ts" ;
88import type { GlobalOptions } from "./main.ts" ;
99
1010type 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