Skip to content

Commit 5285cc8

Browse files
Merge master into feature/profile-logging
2 parents 51853ec + 000a20d commit 5285cc8

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

packages/core/src/awsService/sagemaker/commands.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
import { SagemakerUnifiedStudioSpaceNode } from '../../sagemakerunifiedstudio/explorer/nodes/sageMakerUnifiedStudioSpaceNode'
3737
import { node } from 'webpack'
3838
import { parse } from '@aws-sdk/util-arn-parser'
39-
import { storeHyperpodConnection } from './detached-server/hyperpodMappingUtils.js'
4039

4140
const localize = nls.loadMessageBundle()
4241

@@ -127,41 +126,20 @@ export async function deeplinkConnect(
127126
eksClusterArn: ${eksClusterArn}`
128127
)
129128

130-
getLogger().info(
131-
`sm:deeplinkConnect: Condition check - !domain: ${!domain}, eksClusterArn: ${!!eksClusterArn}, workspaceName: ${!!workspaceName}, namespace: ${!!namespace}`
132-
)
133-
134129
if (isRemoteWorkspace()) {
135130
void vscode.window.showErrorMessage(ConnectFromRemoteWorkspaceMessage)
136131
return
137132
}
138133

139134
try {
140135
let connectionType = 'sm_dl'
141-
let clusterName: string | undefined
142-
let region: string | undefined
143136
if (!domain && eksClusterArn && workspaceName && namespace) {
144-
const parsed = parse(eksClusterArn)
145-
clusterName = parsed.resource.split('/')[1]
146-
region = parsed.region
137+
const { accountId, region, clusterName } = parseArn(eksClusterArn)
147138
connectionType = 'sm_hp'
148-
const proposedSession = `${workspaceName}_${namespace}_${clusterName}_${region}_${parsed.accountId}`
139+
const proposedSession = `${workspaceName}_${namespace}_${clusterName}_${region}_${accountId}`
149140
session = isValidSshHostname(proposedSession)
150141
? proposedSession
151-
: createValidSshSession(workspaceName, namespace, clusterName, region, parsed.accountId)
152-
153-
await storeHyperpodConnection(
154-
workspaceName,
155-
namespace,
156-
eksClusterArn,
157-
clusterName,
158-
clusterName,
159-
undefined,
160-
undefined,
161-
region,
162-
wsUrl,
163-
token
164-
)
142+
: createValidSshSession(workspaceName, namespace, clusterName, region, accountId)
165143
}
166144
const remoteEnv = await prepareDevEnvConnection(
167145
connectionIdentifier,
@@ -175,10 +153,8 @@ export async function deeplinkConnect(
175153
domain,
176154
appType,
177155
workspaceName,
178-
clusterName,
179-
namespace,
180-
region,
181-
eksClusterArn
156+
undefined,
157+
namespace
182158
)
183159

184160
try {
@@ -220,6 +196,26 @@ export async function deeplinkConnect(
220196
}
221197
}
222198

199+
function parseArn(arn: string): { accountId: string; region: string; clusterName: string } {
200+
try {
201+
const parsed = parse(arn)
202+
if (!parsed.service) {
203+
throw new Error('Invalid service')
204+
}
205+
const clusterName = parsed.resource.split('/')[1]
206+
if (!clusterName) {
207+
throw new Error('Invalid cluster name')
208+
}
209+
return {
210+
accountId: parsed.accountId,
211+
clusterName,
212+
region: parsed.region,
213+
}
214+
} catch (error) {
215+
throw new Error('Invalid cluster ARN')
216+
}
217+
}
218+
223219
/**
224220
* Validates and sanitizes session names for SSH hostname compliance
225221
*/

packages/core/src/awsService/sagemaker/detached-server/utils.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,31 @@ export async function readServerInfo(): Promise<ServerInfo> {
5656
}
5757

5858
/**
59-
* Parses a SageMaker or EKS ARN to extract region, account ID, and space/cluster name.
59+
* Parses a SageMaker ARN to extract region, account ID, and space name.
6060
* Supports formats like:
6161
* arn:aws:sagemaker:<region>:<account_id>:space/<domain>/<space_name>
6262
* arn:aws:sagemaker:<region>:<account_id>:cluster/<cluster_id>
63-
* arn:aws:eks:<region>:<account>:cluster/cluster-name
6463
* or sm_lc_arn:aws:sagemaker:<region>:<account_id>:space__d-xxxx__<name>
6564
*
6665
* If the input is prefixed with an identifier (e.g. "sagemaker-user@"), the function will strip it.
6766
*
68-
* @param arn - The full ARN string
67+
* @param arn - The full SageMaker ARN string
6968
* @returns An object containing the region, accountId, and spaceName
7069
* @throws If the ARN format is invalid
7170
*/
7271
export function parseArn(arn: string): { region: string; accountId: string; spaceName: string } {
7372
const cleanedArn = arn.includes('@') ? arn.split('@')[1] : arn
74-
const regex = /^arn:aws:(sagemaker|eks):(?<region>[^:]+):(?<account_id>\d+):(space|cluster)[/:].+$/i
73+
const regex = /^arn:aws:sagemaker:(?<region>[^:]+):(?<account_id>\d+):(space|cluster)[/:].+$/i
7574
const match = cleanedArn.match(regex)
7675

7776
if (!match?.groups) {
78-
throw new Error(`Invalid SageMaker/EKS ARN format: "${arn}"`)
77+
throw new Error(`Invalid SageMaker ARN format: "${arn}"`)
7978
}
8079

81-
// Extract space/cluster name from the end of the ARN (after the last forward slash)
80+
// Extract space name from the end of the ARN (after the last forward slash)
8281
const spaceName = cleanedArn.split('/').pop()
8382
if (!spaceName) {
84-
throw new Error(`Could not extract space/cluster name from ARN: "${arn}"`)
83+
throw new Error(`Could not extract space name from ARN: "${arn}"`)
8584
}
8685

8786
return {

packages/toolkit/.changes/next-release/BugFix-7f4b2db6-3199-4c56-aaf6-c4be97009ced.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)