Skip to content

Commit f36101a

Browse files
ahusseinalihayemaxi
authored andcommitted
Change sagemaker connection validation logic
1 parent ea67377 commit f36101a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ export const codeWhispererCoreScopes = [...scopesCodeWhispererCore]
5050
export const codeWhispererChatScopes = [...codeWhispererCoreScopes, ...scopesCodeWhispererChat]
5151
export const amazonQScopes = [...codeWhispererChatScopes, ...scopesGumby, ...scopesFeatureDev]
5252

53-
function isValidSageMakerConnection(conn?: Connection) {
54-
return isIamConnection(conn) || isSsoConnection(conn)
55-
}
5653
/**
5754
* "Core" are the CW scopes that existed before the addition of new scopes
5855
* for Amazon Q.
@@ -63,15 +60,15 @@ export const isValidCodeWhispererCoreConnection = (conn?: Connection): conn is C
6360
}
6461

6562
return (
66-
isValidSageMakerConnection(conn) ||
63+
(isSageMaker() && isIamConnection(conn)) ||
6764
(isCloud9('codecatalyst') && isIamConnection(conn)) ||
6865
(isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes))
6966
)
7067
}
7168
/** Superset that includes all of CodeWhisperer + Amazon Q */
7269
export const isValidAmazonQConnection = (conn?: Connection): conn is Connection => {
7370
return (
74-
isValidSageMakerConnection(conn) ||
71+
(isSageMaker() && isIamConnection(conn)) ||
7572
((isSsoConnection(conn) || isBuilderIdConnection(conn)) &&
7673
isValidCodeWhispererCoreConnection(conn) &&
7774
hasScopes(conn, amazonQScopes))
@@ -444,6 +441,10 @@ export class AuthUtil {
444441
return buildFeatureAuthState(AuthStates.disconnected)
445442
}
446443

444+
if (!isSsoConnection(conn) && !isSageMaker()) {
445+
throw new ToolkitError(`Connection "${conn.id}" is not a valid type: ${conn.type}`)
446+
}
447+
447448
// default to expired to indicate reauth is needed if unmodified
448449
const state: FeatureAuthState = buildFeatureAuthState(AuthStates.expired)
449450

0 commit comments

Comments
 (0)