@@ -38,9 +38,9 @@ TypeScript::
3838[source,typescript,subs="verbatim,attributes"]
3939----
4040// Example plugin structure
41- import type { IPluginHost } from '@aws-cdk/cli-plugin-contract';
41+ import type { IPluginHost, Plugin } from '@aws-cdk/cli-plugin-contract';
4242
43- export = {
43+ const plugin: Plugin = {
4444 // Version of the plugin infrastructure (currently always '1')
4545 version: '1',
4646
@@ -50,13 +50,15 @@ export = {
5050 // For example, register a custom credential provider
5151 }
5252};
53+
54+ export = plugin;
5355----
5456
5557JavaScript::
5658+
5759[source,javascript,subs="verbatim,attributes"]
5860----
59- module.exports = {
61+ const plugin = {
6062 // Version of the plugin infrastructure (currently always '1')
6163 version: '1',
6264
@@ -66,6 +68,8 @@ module.exports = {
6668 // For example, register a custom credential provider
6769 }
6870};
71+
72+ module.exports = plugin;
6973----
7074====
7175
@@ -175,9 +179,7 @@ TypeScript::
175179+
176180[source,typescript,subs="verbatim,attributes"]
177181----
178- import type { IPluginHost } from '@aws-cdk/cli-plugin-contract';
179- import { CredentialProviderSource, Mode } from '@aws-cdk/cli-plugin-contract';
180- import { Credentials } from '@aws-sdk/client-sts';
182+ import type { CredentialProviderSource, ForReading, ForWriting, IPluginHost, Plugin, PluginProviderResult, SDKv3CompatibleCredentials } from '@aws-cdk/cli-plugin-contract';
181183
182184class CustomCredentialProviderSource implements CredentialProviderSource {
183185 // Friendly name for the provider, used in error messages
@@ -204,44 +206,41 @@ class CustomCredentialProviderSource implements CredentialProviderSource {
204206 // - SDKv2CompatibleCredentials (AWS SDK v2 entered maintenance on Sept 8, 2024 and will reach end-of-life on Sept 8, 2025)
205207 // - SDKv3CompatibleCredentialProvider
206208 // - SDKv3CompatibleCredentials
207- public async getProvider(accountId: string, mode: Mode ): Promise<PluginProviderResult> {
209+ public async getProvider(accountId: string, mode: ForReading | ForWriting ): Promise<PluginProviderResult> {
208210 // The access mode can be used to provide different credential sets
209- const readOnly = mode === Mode. ForReading;
211+ const readOnly = mode === 0 satisfies ForReading;
210212
211213 // Create appropriate credentials based on your authentication mechanism
212- // In this example we're using AWS SDK v3 credentials
213- const credentials = new Credentials({
214+ const credentials: SDKv3CompatibleCredentials = {
214215 accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
215216 secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
216217 // Add sessionToken if using temporary credentials
217218 // sessionToken: 'AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT+FvwqnKwRcOIfrRh3c/LTo6UDdyJwOOvEVPvLXCrrrUtdnniCEXAMPLE/IvU1dYUg2RVAJBanLiHb4IgRmpRV3zrkuWJOgQs8IZZaIv2BXIa2R4Olgk',
218219 // expireTime: new Date(Date.now() + 3600 * 1000), // 1 hour from now
219- }) ;
220+ };
220221
221222 return credentials;
222223 }
223224}
224225
225- export = {
226+ const plugin: Plugin = {
226227 version: '1',
227228 init(host: IPluginHost): void {
228229 // Register the credential provider to the PluginHost.
229230 host.registerCredentialProviderSource(new CustomCredentialProviderSource());
230231 }
231232};
233+
234+ export = plugin;
232235----
233236
234237JavaScript::
235238+
236239[source,javascript,subs="verbatim,attributes"]
237240----
238- const { CredentialProviderSource, Mode } = require('@aws-cdk/cli-plugin-contract');
239- const { Credentials } = require('@aws-sdk/client-sts');
240-
241241// Implement the CredentialProviderSource interface
242- class CustomCredentialProviderSource extends CredentialProviderSource {
242+ class CustomCredentialProviderSource {
243243 constructor() {
244- super();
245244 // Friendly name for the provider, used in error messages
246245 this.name = 'custom-credential-provider';
247246 }
@@ -269,29 +268,30 @@ class CustomCredentialProviderSource extends CredentialProviderSource {
269268 // - SDKv3CompatibleCredentials
270269 async getProvider(accountId, mode) {
271270 // The access mode can be used to provide different credential sets
272- const readOnly = mode === Mode. ForReading;
271+ const readOnly = mode === 0; // 0 indicates ForReading; 1 indicates ForWriting
273272
274273 // Create appropriate credentials based on your authentication mechanism
275- // In this example we're using AWS SDK v3 credentials
276- const credentials = new Credentials({
274+ const credentials = {
277275 accessKeyId: 'ASIAIOSFODNN7EXAMPLE',
278276 secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
279277 // Add sessionToken if using temporary credentials
280278 // sessionToken: 'AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT+FvwqnKwRcOIfrRh3c/LTo6UDdyJwOOvEVPvLXCrrrUtdnniCEXAMPLE/IvU1dYUg2RVAJBanLiHb4IgRmpRV3zrkuWJOgQs8IZZaIv2BXIa2R4Olgk',
281279 // expireTime: new Date(Date.now() + 3600 * 1000), // 1 hour from now
282- }) ;
280+ };
283281
284282 return credentials;
285283 }
286284}
287285
288- module.exports = {
286+ const plugin = {
289287 version: '1',
290288 init(host) {
291289 // Register the credential provider to the PluginHost.
292290 host.registerCredentialProviderSource(new CustomCredentialProviderSource());
293291 }
294292};
293+
294+ module.exports = plugin;
295295----
296296====
297297
0 commit comments