@@ -30,9 +30,28 @@ import {
3030 SpaceStatus ,
3131} from './constants'
3232import { SagemakerUnifiedStudioSpaceNode } from '../../sagemakerunifiedstudio/explorer/nodes/sageMakerUnifiedStudioSpaceNode'
33+ import { SageMakerSshConfig } from './sshConfig'
34+ import { findSshPath } from '../../shared/utilities/pathFind'
3335
3436const localize = nls . loadMessageBundle ( )
3537
38+ /**
39+ * Validates SSH configuration before starting connection.
40+ */
41+ async function validateSshConfig ( ) : Promise < void > {
42+ const sshPath = await findSshPath ( )
43+ if ( ! sshPath ) {
44+ throw new ToolkitError (
45+ 'SSH is required to connect to SageMaker spaces, but was not found.Install SSH to connect to spaces.'
46+ )
47+ }
48+ const sshConfig = new SageMakerSshConfig ( sshPath , 'sm_' , 'sagemaker_connect' )
49+ const result = await sshConfig . ensureValid ( )
50+ if ( result . isErr ( ) ) {
51+ throw result . err ( )
52+ }
53+ }
54+
3655export async function filterSpaceAppsByDomainUserProfiles ( parentNode : SagemakerParentNode ) : Promise < void > {
3756 if ( parentNode . domainUserProfiles . size === 0 ) {
3857 // if parentNode has not been expanded, domainUserProfiles will be empty
@@ -107,6 +126,9 @@ export async function deeplinkConnect(
107126 return
108127 }
109128
129+ // Validate SSH config before attempting connection
130+ await validateSshConfig ( )
131+
110132 try {
111133 const remoteEnv = await prepareDevEnvConnection (
112134 connectionIdentifier ,
@@ -301,6 +323,9 @@ async function handleRunningSpaceWithDisabledAccess(
301323 return
302324 }
303325
326+ // Validate SSH config before showing progress
327+ await validateSshConfig ( )
328+
304329 // Enable remote access and connect
305330 const client = sageMakerClient || new SagemakerClient ( node . regionCode )
306331
@@ -359,6 +384,9 @@ async function handleStoppedSpace(
359384 spaceName : string ,
360385 sageMakerClient ?: SagemakerClient
361386) {
387+ // Validate SSH config before showing progress
388+ await validateSshConfig ( )
389+
362390 const client = sageMakerClient || new SagemakerClient ( node . regionCode )
363391
364392 try {
@@ -403,6 +431,9 @@ async function handleRunningSpaceWithEnabledAccess(
403431 spaceName : string ,
404432 sageMakerClient ?: SagemakerClient
405433) {
434+ // Validate SSH config before showing progress
435+ await validateSshConfig ( )
436+
406437 return await vscode . window . withProgress (
407438 {
408439 location : vscode . ProgressLocation . Notification ,
0 commit comments