@@ -8,30 +8,7 @@ import { LoggerFactory } from '../telemetry/LoggerFactory';
88import { extractErrorMessage } from '../utils/Errors' ;
99import { getRegion } from '../utils/Region' ;
1010import { parseWithPrettyError } from '../utils/ZodErrorWrapper' ;
11- import {
12- parseListProfilesResult ,
13- parseUpdateCredentialsParams ,
14- parseSsoTokenChangedParams ,
15- parseInvalidateSsoTokenParams ,
16- parseGetSsoTokenParams ,
17- parseUpdateProfileParams ,
18- parseGetSsoTokenResult ,
19- } from './AwsCredentialsParser' ;
20- import {
21- SsoConnectionType ,
22- BearerCredentials ,
23- ConnectionMetadata ,
24- UpdateCredentialsParams ,
25- ListProfilesResult ,
26- UpdateProfileParams ,
27- UpdateProfileResult ,
28- GetSsoTokenParams ,
29- GetSsoTokenResult ,
30- InvalidateSsoTokenParams ,
31- InvalidateSsoTokenResult ,
32- SsoTokenChangedParams ,
33- IamCredentials ,
34- } from './AwsLspAuthTypes' ;
11+ import { UpdateCredentialsParams , IamCredentials } from './AwsLspAuthTypes' ;
3512
3613const DecryptedCredentialsSchema = z . object ( {
3714 data : z . object ( {
@@ -47,8 +24,6 @@ export class AwsCredentials {
4724 private readonly logger = LoggerFactory . getLogger ( AwsCredentials ) ;
4825
4926 private iamCredentials ?: IamCredentials ;
50- private bearerCredentials ?: BearerCredentials ;
51- private connectionMetadata ?: ConnectionMetadata ;
5227 private readonly encryptionKey : Buffer ;
5328
5429 constructor (
@@ -66,96 +41,9 @@ export class AwsCredentials {
6641 return structuredClone ( this . iamCredentials ) ;
6742 }
6843
69- getBearer ( ) : DeepReadonly < BearerCredentials > {
70- if ( ! this . bearerCredentials ) {
71- throw new Error ( 'Bearer credentials not configured' ) ;
72- }
73- return structuredClone ( this . bearerCredentials ) ;
74- }
75-
76- getConnectionMetadata ( ) : ConnectionMetadata | undefined {
77- return this . connectionMetadata ;
78- }
79-
80- getConnectionType ( ) : SsoConnectionType {
81- const startUrl = this . connectionMetadata ?. sso ?. startUrl ;
82- if ( ! startUrl ) return 'none' ;
83-
84- return startUrl . includes ( 'view.awsapps.com/start' ) ? 'builderId' : 'identityCenter' ;
85- }
86-
87- async listProfiles ( ) : Promise < ListProfilesResult | undefined > {
88- try {
89- const result = await this . awsHandlers . sendListProfiles ( { } ) ;
90- if ( ! result ) return undefined ;
91-
92- const parsedResult = parseListProfilesResult ( result ) ;
93-
94- this . logger . info ( `Found ${ parsedResult . profiles . length } profiles` ) ;
95- return parsedResult ;
96- } catch ( error ) {
97- this . logger . error ( { error } , 'Failed to list profiles' ) ;
98- return undefined ;
99- }
100- }
101-
102- async updateProfile ( params : UpdateProfileParams ) : Promise < UpdateProfileResult | undefined > {
103- try {
104- const parsedParams = parseUpdateProfileParams ( params ) ;
105- const result = await this . awsHandlers . sendUpdateProfile ( parsedParams ) ;
106-
107- this . logger . info ( `Profile updated: ${ parsedParams . profile . name } ` ) ;
108- return result ?? undefined ;
109- } catch ( error ) {
110- this . logger . error ( { error } , 'Failed to update profile' ) ;
111- return undefined ;
112- }
113- }
114-
115- async getSsoToken ( params : GetSsoTokenParams ) : Promise < GetSsoTokenResult | undefined > {
116- try {
117- const parsedParams = parseGetSsoTokenParams ( params ) ;
118- const result = await this . awsHandlers . sendGetSsoToken ( parsedParams ) ;
119-
120- if ( ! result ?. ssoToken ) return result ?? undefined ;
121-
122- const parsedResult = parseGetSsoTokenResult ( result ) ;
123- this . logger . info ( 'Retrieved SSO token' ) ;
124-
125- const { data, metadata } = parsedResult . updateCredentialsParams ;
126- if ( data && 'token' in data ) {
127- this . bearerCredentials = data ;
128- if ( metadata ) {
129- this . connectionMetadata = metadata ;
130- }
131- }
132-
133- return parsedResult ;
134- } catch ( error ) {
135- this . logger . error ( { error } , 'Failed to get SSO token' ) ;
136- return undefined ;
137- }
138- }
139-
140- async invalidateSsoToken ( params : InvalidateSsoTokenParams ) : Promise < InvalidateSsoTokenResult | undefined > {
141- try {
142- const parsedParams = parseInvalidateSsoTokenParams ( params ) ;
143- const result = await this . awsHandlers . sendInvalidateSsoToken ( parsedParams ) ;
144-
145- this . bearerCredentials = undefined ;
146- this . connectionMetadata = undefined ;
147-
148- this . logger . info ( 'SSO token invalidated' ) ;
149- return result ?? undefined ;
150- } catch ( error ) {
151- this . logger . error ( { error } , 'Failed to invalidate SSO token' ) ;
152- return undefined ;
153- }
154- }
155-
15644 async handleIamCredentialsUpdate ( params : UpdateCredentialsParams ) : Promise < boolean > {
15745 try {
158- const decrypted = await compactDecrypt ( params . data as unknown as string , this . encryptionKey ) ;
46+ const decrypted = await compactDecrypt ( params . data , this . encryptionKey ) ;
15947 const rawCredentials = JSON . parse ( new TextDecoder ( ) . decode ( decrypted . plaintext ) ) as unknown ;
16048
16149 const validatedCredentials = parseWithPrettyError (
@@ -181,46 +69,8 @@ export class AwsCredentials {
18169 }
18270 }
18371
184- handleBearerCredentialsUpdate ( params : UpdateCredentialsParams ) {
185- try {
186- const { data, metadata } = parseWithPrettyError ( parseUpdateCredentialsParams , params ) ;
187-
188- if ( 'token' in data ) {
189- this . bearerCredentials = data ;
190- if ( metadata ) {
191- this . connectionMetadata = metadata ;
192- }
193- this . logger . info ( 'Updated bearer credentials' ) ;
194- }
195- } catch ( error ) {
196- this . logger . error ( `Failed to update Bearer token: ${ extractErrorMessage ( error ) } ` ) ;
197- this . bearerCredentials = undefined ;
198- this . connectionMetadata = undefined ;
199- }
200- }
201-
20272 handleIamCredentialsDelete ( ) {
20373 this . logger . info ( 'IAM credentials deleted' ) ;
20474 this . iamCredentials = undefined ;
20575 }
206-
207- handleBearerCredentialsDelete ( ) {
208- this . logger . info ( 'Bearer credentials deleted' ) ;
209- this . bearerCredentials = undefined ;
210- this . connectionMetadata = undefined ;
211- }
212-
213- handleSsoTokenChanged ( params : SsoTokenChangedParams ) {
214- try {
215- const { kind } = parseSsoTokenChangedParams ( params ) ;
216- if ( kind === 'Expired' ) {
217- this . bearerCredentials = undefined ;
218- this . connectionMetadata = undefined ;
219- } else if ( kind === 'Refreshed' ) {
220- this . logger . info ( 'SSO token refreshed' ) ;
221- }
222- } catch ( error ) {
223- this . logger . error ( { error } , 'Error handling SSO token change' ) ;
224- }
225- }
22676}
0 commit comments