Skip to content

Commit 72d206f

Browse files
committed
refactor to avoid module-level args
1 parent b648317 commit 72d206f

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/codecatalyst/model.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import { VscodeRemoteConnection, ensureDependencies } from '../shared/remoteSess
3333
import { VscodeRemoteSshConfig, sshLogFileLocation } from '../shared/vscodeRemoteSshConfig'
3434

3535
export type DevEnvironmentId = Pick<DevEnvironment, 'id' | 'org' | 'project'>
36-
export const hostNamePrefix = 'aws-devenv-'
37-
export const connectScriptPrefix = 'codecatalyst_connect'
36+
// export const hostNamePrefix = 'aws-devenv-'
37+
// export const connectScriptPrefix = 'codecatalyst_connect'
3838

3939
export const docs = {
4040
vscode: {
@@ -142,10 +142,6 @@ export function bearerTokenCacheLocation(devenvId: string): string {
142142
return path.join(globals.context.globalStorageUri.fsPath, `codecatalyst.${devenvId}.token`)
143143
}
144144

145-
export function getHostNameFromEnv(env: DevEnvironmentId): string {
146-
return `${hostNamePrefix}${env.id}`
147-
}
148-
149145
export interface ConnectedDevEnv {
150146
readonly summary: DevEnvironment
151147
readonly devenvClient: DevEnvClient
@@ -209,7 +205,8 @@ export async function prepareDevEnvConnection(
209205
{ topic, timeout }: { topic?: string; timeout?: Timeout } = {}
210206
): Promise<DevEnvConnection> {
211207
const { ssm, vsc, ssh } = (await ensureDependencies()).unwrap()
212-
const sshConfig = new VscodeRemoteSshConfig(ssh, hostNamePrefix, connectScriptPrefix)
208+
const hostNamePrefix = 'aws-devenv-'
209+
const sshConfig = new VscodeRemoteSshConfig(ssh, hostNamePrefix, 'codecatalyst_connect')
213210
const config = await sshConfig.ensureValid()
214211

215212
if (config.isErr()) {
@@ -225,7 +222,7 @@ export async function prepareDevEnvConnection(
225222
projectName: project.name,
226223
})
227224

228-
const hostname = getHostNameFromEnv({ id, org, project })
225+
const hostname = `${hostNamePrefix}${id}`
229226
const logPrefix = topic ? `codecatalyst ${topic} (${id})` : `codecatalyst (${id})`
230227
const logger = (data: string) => getLogger().verbose(`${logPrefix}: ${data}`)
231228
const envProvider = createCodeCatalystEnvProvider(client, ssm, runningDevEnv)
@@ -263,7 +260,7 @@ export async function openDevEnv(
263260
const repo = env.devenv.repositories.length == 1 ? env.devenv.repositories[0].repositoryName : undefined
264261
targetPath = repo ? `/projects/${repo}` : '/projects'
265262
}
266-
await startVscodeRemote(env.SessionProcess, getHostNameFromEnv(env.devenv), targetPath, env.vscPath)
263+
await startVscodeRemote(env.SessionProcess, env.hostname, targetPath, env.vscPath)
267264
}
268265

269266
// The "codecatalyst_connect" metric should really be splt into two parts:

src/ec2/model.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ interface Ec2RemoteEnv extends VscodeRemoteConnection {
3030
selection: Ec2Selection
3131
}
3232

33-
const ec2ConnectScriptPrefix = 'ec2_connect'
34-
const hostNamePrefix = 'ec2-'
35-
3633
export class Ec2ConnectionManager {
3734
protected ssmClient: SsmClient
3835
protected ec2Client: Ec2Client
@@ -177,9 +174,8 @@ export class Ec2ConnectionManager {
177174
const remoteUser = await this.getRemoteUser(selection.instanceId)
178175
const remoteEnv = await this.prepareEc2RemoteEnvWithProgress(selection, remoteUser)
179176

180-
const fullHostName = `${hostNamePrefix}${selection.instanceId}`
181177
try {
182-
await startVscodeRemote(remoteEnv.SessionProcess, fullHostName, '/', remoteEnv.vscPath, remoteUser)
178+
await startVscodeRemote(remoteEnv.SessionProcess, remoteEnv.hostname, '/', remoteEnv.vscPath, remoteUser)
183179
} catch (err) {
184180
this.throwGeneralConnectionError(selection, err as Error)
185181
}
@@ -195,7 +191,8 @@ export class Ec2ConnectionManager {
195191
const logger = this.configureRemoteConnectionLogger(selection.instanceId)
196192
const { ssm, vsc, ssh } = (await ensureDependencies()).unwrap()
197193
const keyPath = await this.configureSshKeys(selection, remoteUser)
198-
const sshConfig = new VscodeRemoteSshConfig(ssh, hostNamePrefix, ec2ConnectScriptPrefix, keyPath)
194+
const hostNamePrefix = 'aws-ec2-'
195+
const sshConfig = new VscodeRemoteSshConfig(ssh, hostNamePrefix, 'ec2-connect', keyPath)
199196

200197
const config = await sshConfig.ensureValid()
201198
if (config.isErr()) {
@@ -216,7 +213,7 @@ export class Ec2ConnectionManager {
216213
})
217214

218215
return {
219-
hostname: selection.instanceId,
216+
hostname: `${hostNamePrefix}${selection.instanceId}`,
220217
envProvider,
221218
sshPath: ssh,
222219
vscPath: vsc,

0 commit comments

Comments
 (0)