Skip to content

Commit e60abae

Browse files
committed
make encryptionkey not required
1 parent 5e1ca2c commit e60abae

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/auth/AwsCredentials.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export class AwsCredentials {
2323
private readonly logger = LoggerFactory.getLogger(AwsCredentials);
2424

2525
private iamCredentials?: IamCredentials;
26-
private readonly encryptionKey: Buffer;
26+
private readonly encryptionKey?: Buffer;
2727

2828
constructor(
2929
private readonly awsHandlers: LspAuthHandlers,
3030
private readonly settingsManager: SettingsManager,
31-
encryptionKey: string,
31+
encryptionKey?: string,
3232
) {
33-
this.encryptionKey = Buffer.from(encryptionKey, 'base64');
33+
this.encryptionKey = encryptionKey ? Buffer.from(encryptionKey, 'base64') : undefined;
3434
}
3535

3636
getIAM(): DeepReadonly<IamCredentials> {
@@ -41,6 +41,11 @@ export class AwsCredentials {
4141
}
4242

4343
async handleIamCredentialsUpdate(params: UpdateCredentialsParams): Promise<boolean> {
44+
if (!this.encryptionKey) {
45+
this.logger.error('Authentication failed: encryption key not configured');
46+
return false;
47+
}
48+
4449
try {
4550
const decrypted = await compactDecrypt(params.data, this.encryptionKey);
4651
const rawCredentials = JSON.parse(new TextDecoder().decode(decrypted.plaintext)) as unknown;

src/server/CfnInfraCore.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ export class CfnInfraCore implements Configurables, Closeable {
6060
this.fileContextManager = overrides.fileContextManager ?? new FileContextManager(this.documentManager);
6161

6262
const encryptionKey = initializeParams.initializationOptions?.encryption?.key;
63-
if (!encryptionKey) {
64-
throw new Error('Encryption key is required');
65-
}
6663

6764
this.awsCredentials =
6865
overrides.awsCredentials ??

src/services/AwsClient.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ export class AwsClient {
2323
}
2424

2525
private iamClientConfig(): IamClientConfig {
26-
const credential = this.credentialsProvider.getIAM();
27-
return {
28-
region: credential.region,
29-
credentials: this.credentialsProvider.getIAM(),
30-
customUserAgent: `${ExtensionId}/${ExtensionVersion}`,
31-
};
26+
try {
27+
const credential = this.credentialsProvider.getIAM();
28+
return {
29+
region: credential.region,
30+
credentials: credential,
31+
customUserAgent: `${ExtensionId}/${ExtensionVersion}`,
32+
};
33+
} catch {
34+
throw new Error('AWS credentials not configured. Authentication required for online features.');
35+
}
3236
}
3337
}

tst/unit/services/AwsClient.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ describe('AwsClient', () => {
4747
});
4848

4949
it('should handle credentials provider errors', () => {
50-
mockComponents.awsCredentials.getIAM.throws(new Error('Credential provider error'));
50+
mockComponents.awsCredentials.getIAM.throws(new Error('IAM credentials not configured'));
5151

52-
expect(() => component.getCloudFormationClient()).toThrow('Credential provider error');
52+
expect(() => component.getCloudFormationClient()).toThrow(
53+
'AWS credentials not configured. Authentication required for online features.',
54+
);
5355
});
5456
});
5557
});

0 commit comments

Comments
 (0)