@@ -21,7 +21,6 @@ import { getCodeCatalystSpaceName, getCodeCatalystProjectName, getCodeCatalystDe
21
21
import { writeFile } from 'fs-extra'
22
22
import { sshAgentSocketVariable , startSshAgent , startVscodeRemote } from '../shared/extensions/ssh'
23
23
import { ChildProcess } from '../shared/utilities/childProcess'
24
- import { ensureDependencies , hostNamePrefix } from './tools'
25
24
import { isDevenvVscode } from './utils'
26
25
import { Timeout } from '../shared/utilities/timeoutUtils'
27
26
import { Commands } from '../shared/vscode/commands2'
@@ -30,8 +29,11 @@ import { fileExists } from '../shared/filesystemUtilities'
30
29
import { CodeCatalystAuthenticationProvider } from './auth'
31
30
import { ToolkitError } from '../shared/errors'
32
31
import { Result } from '../shared/utilities/result'
32
+ import { VscodeRemoteConnection , ensureDependencies } from '../shared/remoteSession'
33
+ import { SshConfig , sshLogFileLocation } from '../shared/sshConfig'
33
34
34
35
export type DevEnvironmentId = Pick < DevEnvironment , 'id' | 'org' | 'project' >
36
+ export const connectScriptPrefix = 'codecatalyst_connect'
35
37
36
38
export const docs = {
37
39
vscode : {
@@ -86,7 +88,7 @@ export function getCodeCatalystSsmEnv(region: string, ssmPath: string, devenv: D
86
88
AWS_SSM_CLI : ssmPath ,
87
89
CODECATALYST_ENDPOINT : getCodeCatalystConfig ( ) . endpoint ,
88
90
BEARER_TOKEN_LOCATION : bearerTokenCacheLocation ( devenv . id ) ,
89
- LOG_FILE_LOCATION : sshLogFileLocation ( devenv . id ) ,
91
+ LOG_FILE_LOCATION : sshLogFileLocation ( 'codecatalyst' , devenv . id ) ,
90
92
SPACE_NAME : devenv . org . name ,
91
93
PROJECT_NAME : devenv . project . name ,
92
94
DEVENV_ID : devenv . id ,
@@ -139,14 +141,6 @@ export function bearerTokenCacheLocation(devenvId: string): string {
139
141
return path . join ( globals . context . globalStorageUri . fsPath , `codecatalyst.${ devenvId } .token` )
140
142
}
141
143
142
- export function sshLogFileLocation ( devenvId : string ) : string {
143
- return path . join ( globals . context . globalStorageUri . fsPath , `codecatalyst.${ devenvId } .log` )
144
- }
145
-
146
- export function getHostNameFromEnv ( env : DevEnvironmentId ) : string {
147
- return `${ hostNamePrefix } ${ env . id } `
148
- }
149
-
150
144
export interface ConnectedDevEnv {
151
145
readonly summary : DevEnvironment
152
146
readonly devenvClient : DevEnvClient
@@ -200,12 +194,7 @@ export async function getThisDevEnv(authProvider: CodeCatalystAuthenticationProv
200
194
/**
201
195
* Everything needed to connect to a dev environment via VS Code or `ssh`
202
196
*/
203
- interface DevEnvConnection {
204
- readonly sshPath : string
205
- readonly vscPath : string
206
- readonly hostname : string
207
- readonly envProvider : EnvProvider
208
- readonly SessionProcess : typeof ChildProcess
197
+ interface DevEnvConnection extends VscodeRemoteConnection {
209
198
readonly devenv : DevEnvironment
210
199
}
211
200
@@ -215,13 +204,24 @@ export async function prepareDevEnvConnection(
215
204
{ topic, timeout } : { topic ?: string ; timeout ?: Timeout } = { }
216
205
) : Promise < DevEnvConnection > {
217
206
const { ssm, vsc, ssh } = ( await ensureDependencies ( ) ) . unwrap ( )
207
+ const hostNamePrefix = 'aws-devenv-'
208
+ const sshConfig = new SshConfig ( ssh , hostNamePrefix , connectScriptPrefix )
209
+ const config = await sshConfig . ensureValid ( )
210
+
211
+ if ( config . isErr ( ) ) {
212
+ const err = config . err ( )
213
+ getLogger ( ) . error ( `codecatalyst: failed to add ssh config section: ${ err . message } ` )
214
+
215
+ throw err
216
+ }
217
+
218
218
const runningDevEnv = await client . startDevEnvironmentWithProgress ( {
219
219
id,
220
220
spaceName : org . name ,
221
221
projectName : project . name ,
222
222
} )
223
223
224
- const hostname = getHostNameFromEnv ( { id , org , project } )
224
+ const hostname = ` ${ hostNamePrefix } ${ id } `
225
225
const logPrefix = topic ? `codecatalyst ${ topic } (${ id } )` : `codecatalyst (${ id } )`
226
226
const logger = ( data : string ) => getLogger ( ) . verbose ( `${ logPrefix } : ${ data } ` )
227
227
const envProvider = createCodeCatalystEnvProvider ( client , ssm , runningDevEnv )
@@ -259,7 +259,7 @@ export async function openDevEnv(
259
259
const repo = env . devenv . repositories . length == 1 ? env . devenv . repositories [ 0 ] . repositoryName : undefined
260
260
targetPath = repo ? `/projects/${ repo } ` : '/projects'
261
261
}
262
- await startVscodeRemote ( env . SessionProcess , getHostNameFromEnv ( env . devenv ) , targetPath , env . vscPath )
262
+ await startVscodeRemote ( env . SessionProcess , env . hostname , targetPath , env . vscPath )
263
263
}
264
264
265
265
// The "codecatalyst_connect" metric should really be splt into two parts:
0 commit comments