Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a77138

Browse files
committed
review
1 parentfb9a263 commit3a77138

File tree

3 files changed

+125
-135
lines changed

3 files changed

+125
-135
lines changed

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@
311311
"date-fns":"^3.6.0",
312312
"eventsource":"^3.0.6",
313313
"find-process":"https://github.com/coder/find-process#fix/sequoia-compat",
314+
"ip-range-check":"^0.2.0",
314315
"jsonc-parser":"^3.3.1",
315316
"memfs":"^4.9.3",
316317
"node-forge":"^1.3.1",
317318
"pretty-bytes":"^6.1.1",
318319
"proxy-agent":"^6.4.0",
319-
"range_check":"^3.2.0",
320320
"semver":"^7.6.2",
321321
"ua-parser-js":"^1.0.38",
322322
"ws":"^8.18.1",

‎src/commands.ts

Lines changed: 114 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Api } from "coder/site/src/api/api"
33
import{getErrorMessage}from"coder/site/src/api/errors"
44
import{User,Workspace,WorkspaceAgent}from"coder/site/src/api/typesGenerated"
55
import{lookup}from"dns"
6-
import{inRange}from"range_check"
6+
importipRangeCheckfrom"ip-range-check"
77
import{promisify}from"util"
88
import*asvscodefrom"vscode"
99
import{makeCoderSdk,needToken}from"./api"
@@ -396,26 +396,14 @@ export class Commands {
396396
if(!baseUrl){
397397
thrownewError("You are not logged in")
398398
}
399-
400-
try{
401-
awaitopenWorkspace(
402-
this.restClient,
403-
baseUrl,
404-
treeItem.workspaceOwner,
405-
treeItem.workspaceName,
406-
treeItem.workspaceAgent,
407-
treeItem.workspaceFolderPath,
408-
true,
409-
)
410-
}catch(err){
411-
constmessage=getErrorMessage(err,"no response from the server")
412-
this.storage.writeToCoderOutputChannel(`Failed to open workspace:${message}`)
413-
this.vscodeProposed.window.showErrorMessage("Failed to open workspace",{
414-
detail:message,
415-
modal:true,
416-
useCustom:true,
417-
})
418-
}
399+
awaitthis.openWorkspace(
400+
baseUrl,
401+
treeItem.workspaceOwner,
402+
treeItem.workspaceName,
403+
treeItem.workspaceAgent,
404+
treeItem.workspaceFolderPath,
405+
true,
406+
)
419407
}else{
420408
// If there is no tree item, then the user manually ran this command.
421409
// Default to the regular open instead.
@@ -513,15 +501,7 @@ export class Commands {
513501
}
514502

515503
try{
516-
awaitopenWorkspace(
517-
this.restClient,
518-
baseUrl,
519-
workspaceOwner,
520-
workspaceName,
521-
workspaceAgent,
522-
folderPath,
523-
openRecent,
524-
)
504+
awaitthis.openWorkspace(baseUrl,workspaceOwner,workspaceName,workspaceAgent,folderPath,openRecent)
525505
}catch(err){
526506
constmessage=getErrorMessage(err,"no response from the server")
527507
this.storage.writeToCoderOutputChannel(`Failed to open workspace:${message}`)
@@ -574,32 +554,112 @@ export class Commands {
574554
awaitthis.workspaceRestClient.updateWorkspaceVersion(this.workspace)
575555
}
576556
}
577-
}
578557

579-
/**
580-
* Given a workspace, build the host name, find a directory to open, and pass
581-
* both to the Remote SSH plugin in the form of a remote authority URI.
582-
*/
583-
asyncfunctionopenWorkspace(
584-
restClient:Api,
585-
baseUrl:string,
586-
workspaceOwner:string,
587-
workspaceName:string,
588-
workspaceAgent:string|undefined,
589-
folderPath:string|undefined,
590-
openRecent:boolean|undefined,
591-
){
592-
letremoteAuthority=toRemoteAuthority(baseUrl,workspaceOwner,workspaceName,workspaceAgent)
558+
/**
559+
* Given a workspace, build the host name, find a directory to open, and pass
560+
* both to the Remote SSH plugin in the form of a remote authority URI.
561+
*/
562+
privateasyncopenWorkspace(
563+
baseUrl:string,
564+
workspaceOwner:string,
565+
workspaceName:string,
566+
workspaceAgent:string|undefined,
567+
folderPath:string|undefined,
568+
openRecent:boolean|undefined,
569+
){
570+
letremoteAuthority=toRemoteAuthority(baseUrl,workspaceOwner,workspaceName,workspaceAgent)
571+
572+
// When called from `openFromSidebar`, the workspaceAgent will only not be set
573+
// if the workspace is stopped, in which case we can't use Coder Connect
574+
// When called from `open`, the workspaceAgent will always be set.
575+
if(workspaceAgent){
576+
lethostnameSuffix="coder"
577+
try{
578+
// If the field was undefined, it's an older server, and always 'coder'
579+
hostnameSuffix=(awaitthis.fetchHostnameSuffix())??hostnameSuffix
580+
}catch(error){
581+
constmessage=getErrorMessage(error,"no response from the server")
582+
this.storage.writeToCoderOutputChannel(`Failed to open workspace:${message}`)
583+
this.vscodeProposed.window.showErrorMessage("Failed to open workspace",{
584+
detail:message,
585+
modal:true,
586+
useCustom:true,
587+
})
588+
}
593589

594-
// When called from `openFromSidebar`, the workspaceAgent will only not be set
595-
// if the workspace is stopped, in which case we can't use Coder Connect
596-
// When called from `open`, the workspaceAgent will always be set.
597-
if(workspaceAgent){
598-
lethostnameSuffix="coder"
590+
constcoderConnectAddr=awaitmaybeCoderConnectAddr(
591+
workspaceAgent,
592+
workspaceName,
593+
workspaceOwner,
594+
hostnameSuffix,
595+
)
596+
if(coderConnectAddr){
597+
remoteAuthority=`ssh-remote+${coderConnectAddr}`
598+
}
599+
}
600+
601+
letnewWindow=true
602+
// Open in the existing window if no workspaces are open.
603+
if(!vscode.workspace.workspaceFolders?.length){
604+
newWindow=false
605+
}
606+
607+
// If a folder isn't specified or we have been asked to open the most recent,
608+
// we can try to open a recently opened folder/workspace.
609+
if(!folderPath||openRecent){
610+
constoutput:{
611+
workspaces:{folderUri:vscode.Uri;remoteAuthority:string}[]
612+
}=awaitvscode.commands.executeCommand("_workbench.getRecentlyOpened")
613+
constopened=output.workspaces.filter(
614+
// Remove recents that do not belong to this connection. The remote
615+
// authority maps to a workspace or workspace/agent combination (using the
616+
// SSH host name). This means, at the moment, you can have a different
617+
// set of recents for a workspace versus workspace/agent combination, even
618+
// if that agent is the default for the workspace.
619+
(opened)=>opened.folderUri?.authority===remoteAuthority,
620+
)
621+
622+
// openRecent will always use the most recent. Otherwise, if there are
623+
// multiple we ask the user which to use.
624+
if(opened.length===1||(opened.length>1&&openRecent)){
625+
folderPath=opened[0].folderUri.path
626+
}elseif(opened.length>1){
627+
constitems=opened.map((f)=>f.folderUri.path)
628+
folderPath=awaitvscode.window.showQuickPick(items,{
629+
title:"Select a recently opened folder",
630+
})
631+
if(!folderPath){
632+
// User aborted.
633+
return
634+
}
635+
}
636+
}
637+
638+
if(folderPath){
639+
awaitvscode.commands.executeCommand(
640+
"vscode.openFolder",
641+
vscode.Uri.from({
642+
scheme:"vscode-remote",
643+
authority:remoteAuthority,
644+
path:folderPath,
645+
}),
646+
// Open this in a new window!
647+
newWindow,
648+
)
649+
return
650+
}
651+
652+
// This opens the workspace without an active folder opened.
653+
awaitvscode.commands.executeCommand("vscode.newWindow",{
654+
remoteAuthority:remoteAuthority,
655+
reuseWindow:!newWindow,
656+
})
657+
}
658+
659+
privateasyncfetchHostnameSuffix():Promise<string|undefined>{
599660
try{
600-
constsshConfig=awaitrestClient.getDeploymentSSHConfig()
601-
// If the field is undefined, it's an older server, and always 'coder'
602-
hostnameSuffix=sshConfig.hostname_suffix??hostnameSuffix
661+
constsshConfig=awaitthis.restClient.getDeploymentSSHConfig()
662+
returnsshConfig.hostname_suffix
603663
}catch(error){
604664
if(!isAxiosError(error)){
605665
throwerror
@@ -609,75 +669,11 @@ async function openWorkspace(
609669
// Likely a very old deployment, just use the default.
610670
break
611671
}
612-
case401:{
613-
throwerror
614-
}
615672
default:
616673
throwerror
617674
}
618675
}
619-
constcoderConnectAddr=awaitmaybeCoderConnectAddr(workspaceAgent,workspaceName,workspaceOwner,hostnameSuffix)
620-
if(coderConnectAddr){
621-
remoteAuthority=`ssh-remote+${coderConnectAddr}`
622-
}
623-
}
624-
625-
letnewWindow=true
626-
// Open in the existing window if no workspaces are open.
627-
if(!vscode.workspace.workspaceFolders?.length){
628-
newWindow=false
629676
}
630-
631-
// If a folder isn't specified or we have been asked to open the most recent,
632-
// we can try to open a recently opened folder/workspace.
633-
if(!folderPath||openRecent){
634-
constoutput:{
635-
workspaces:{folderUri:vscode.Uri;remoteAuthority:string}[]
636-
}=awaitvscode.commands.executeCommand("_workbench.getRecentlyOpened")
637-
constopened=output.workspaces.filter(
638-
// Remove recents that do not belong to this connection. The remote
639-
// authority maps to a workspace or workspace/agent combination (using the
640-
// SSH host name). This means, at the moment, you can have a different
641-
// set of recents for a workspace versus workspace/agent combination, even
642-
// if that agent is the default for the workspace.
643-
(opened)=>opened.folderUri?.authority===remoteAuthority,
644-
)
645-
646-
// openRecent will always use the most recent. Otherwise, if there are
647-
// multiple we ask the user which to use.
648-
if(opened.length===1||(opened.length>1&&openRecent)){
649-
folderPath=opened[0].folderUri.path
650-
}elseif(opened.length>1){
651-
constitems=opened.map((f)=>f.folderUri.path)
652-
folderPath=awaitvscode.window.showQuickPick(items,{
653-
title:"Select a recently opened folder",
654-
})
655-
if(!folderPath){
656-
// User aborted.
657-
return
658-
}
659-
}
660-
}
661-
662-
if(folderPath){
663-
awaitvscode.commands.executeCommand(
664-
"vscode.openFolder",
665-
vscode.Uri.from({
666-
scheme:"vscode-remote",
667-
authority:remoteAuthority,
668-
path:folderPath,
669-
}),
670-
// Open this in a new window!
671-
newWindow,
672-
)
673-
return
674-
}
675-
676-
// This opens the workspace without an active folder opened.
677-
awaitvscode.commands.executeCommand("vscode.newWindow",{
678-
remoteAuthority:remoteAuthority,
679-
reuseWindow:!newWindow,
680-
})
681677
}
682678

683679
asyncfunctionmaybeCoderConnectAddr(
@@ -689,7 +685,7 @@ async function maybeCoderConnectAddr(
689685
constcoderConnectHostname=`${agent}.${workspace}.${owner}.${hostnameSuffix}`
690686
try{
691687
constres=awaitpromisify(lookup)(coderConnectHostname)
692-
returnres.family===6&&inRange(res.address,"fd60:627a:a42b::/48") ?coderConnectHostname :undefined
688+
returnres.family===6&&ipRangeCheck(res.address,"fd60:627a:a42b::/48") ?coderConnectHostname :undefined
693689
}catch{
694690
returnundefined
695691
}

‎yarn.lock

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,15 +3441,17 @@ ip-address@^9.0.5:
34413441
jsbn "1.1.0"
34423442
sprintf-js "^1.1.3"
34433443

3444-
ip6@^0.2.10:
3445-
version "0.2.11"
3446-
resolved "https://registry.yarnpkg.com/ip6/-/ip6-0.2.11.tgz#b7cf71864ef16c7418c29f7b1f2f5db892a189ec"
3447-
integrity sha512-OmTP7FyIp+ZoNvZ7Xr97bWrCgypa3BeuYuRFNTOPT8Y11cxMW1pW1VC70kHZP1onSHHMotADcjdg5QyECiIMUw==
3444+
ip-range-check@^0.2.0:
3445+
version "0.2.0"
3446+
resolved "https://registry.yarnpkg.com/ip-range-check/-/ip-range-check-0.2.0.tgz#e67f126c8fb36c8f11d4c07d7924b7e364365157"
3447+
integrity sha512-oaM3l/3gHbLlt/tCWLvt0mj1qUaI+STuRFnUvARGCujK9vvU61+2JsDpmkMzR4VsJhuFXWWgeKKVnwwoFfzCqw==
3448+
dependencies:
3449+
ipaddr.js "^1.0.1"
34483450

3449-
ipaddr.js@^2.2.0:
3450-
version "2.2.0"
3451-
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.2.0.tgz#d33fa7bac284f4de7af949638c9d68157c6b92e8"
3452-
integrity sha512-Ag3wB2o37wslZS19hZqorUnrnzSkpOVy+IiiDEiTqNubEYpYuHWIf6K4psgN2ZWKExS4xhVCrRVfb/wfW8fWJA==
3451+
ipaddr.js@^1.0.1:
3452+
version "1.9.1"
3453+
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3"
3454+
integrity sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==
34533455

34543456
irregular-plurals@^2.0.0:
34553457
version "2.0.0"
@@ -4844,14 +4846,6 @@ randombytes@^2.1.0:
48444846
dependencies:
48454847
safe-buffer "^5.1.0"
48464848

4847-
range_check@^3.2.0:
4848-
version "3.2.0"
4849-
resolved "https://registry.yarnpkg.com/range_check/-/range_check-3.2.0.tgz#6ef17940bb382a7fb905ecda8204f2f28ce7f61d"
4850-
integrity sha512-JxiMqvzQJJLt5vaKSUm7f++UkDM1TuMbkQsqRZJYaSvvCTTVtoUMkE/rm+ZNgLXNFAQPhO74WgMPHJaxz/JOEA==
4851-
dependencies:
4852-
ip6 "^0.2.10"
4853-
ipaddr.js "^2.2.0"
4854-
48554849
rc@^1.2.7:
48564850
version "1.2.8"
48574851
resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.8.tgz#cd924bf5200a075b83c188cd6b9e211b7fc0d3ed"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp