Skip to content

Commit 331d7a5

Browse files
authored
refactor(cli): remove unused internal code and options (#33432)
### Reason for this change Unused code path that was previously deprecated needs to be removed in preparation of refactoring. ### Description of changes Removing previously deprecated and unused methods on `Deployments` class and transitively unused code. Removed options for asset building/publishing that are unused. ### Describe any new or updated permissions being added n/a ### Description of how you validated changes existing tests ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 91765e2 commit 331d7a5

File tree

2 files changed

+8
-118
lines changed

2 files changed

+8
-118
lines changed

packages/aws-cdk/lib/api/deployments/asset-publishing.ts

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,7 @@ import { ToolkitError } from '../../toolkit/error';
1818
import type { SdkProvider } from '../aws-auth';
1919
import { Mode } from '../plugin';
2020

21-
export interface PublishAssetsOptions {
22-
/**
23-
* Print progress at 'debug' level
24-
*/
25-
readonly quiet?: boolean;
26-
27-
/**
28-
* Whether to build assets before publishing.
29-
*
30-
* @default true To remain backward compatible.
31-
*/
32-
readonly buildAssets?: boolean;
33-
21+
interface PublishAssetsOptions {
3422
/**
3523
* Whether to build/publish assets in parallel
3624
*
@@ -46,6 +34,8 @@ export interface PublishAssetsOptions {
4634

4735
/**
4836
* Use cdk-assets to publish all assets in the given manifest.
37+
*
38+
* @deprecated used in legacy deployments only, should be migrated at some point
4939
*/
5040
export async function publishAssets(
5141
manifest: AssetManifest,
@@ -66,67 +56,19 @@ export async function publishAssets(
6656

6757
const publisher = new AssetPublishing(manifest, {
6858
aws: new PublishingAws(sdk, targetEnv),
69-
progressListener: new PublishingProgressListener(options.quiet ?? false),
59+
progressListener: new PublishingProgressListener(),
7060
throwOnError: false,
7161
publishInParallel: options.parallel ?? true,
72-
buildAssets: options.buildAssets ?? true,
62+
buildAssets: true,
7363
publishAssets: true,
74-
quiet: options.quiet,
64+
quiet: false,
7565
});
7666
await publisher.publish({ allowCrossAccount: options.allowCrossAccount });
7767
if (publisher.hasFailures) {
7868
throw new ToolkitError('Failed to publish one or more assets. See the error messages above for more information.');
7969
}
8070
}
8171

82-
export interface BuildAssetsOptions {
83-
/**
84-
* Print progress at 'debug' level
85-
*/
86-
readonly quiet?: boolean;
87-
88-
/**
89-
* Build assets in parallel
90-
*
91-
* @default true
92-
*/
93-
readonly parallel?: boolean;
94-
}
95-
96-
/**
97-
* Use cdk-assets to build all assets in the given manifest.
98-
*/
99-
export async function buildAssets(
100-
manifest: AssetManifest,
101-
sdk: SdkProvider,
102-
targetEnv: Environment,
103-
options: BuildAssetsOptions = {},
104-
) {
105-
// This shouldn't really happen (it's a programming error), but we don't have
106-
// the types here to guide us. Do an runtime validation to be super super sure.
107-
if (
108-
targetEnv.account === undefined ||
109-
targetEnv.account === UNKNOWN_ACCOUNT ||
110-
targetEnv.region === undefined ||
111-
targetEnv.account === UNKNOWN_REGION
112-
) {
113-
throw new ToolkitError(`Asset building requires resolved account and region, got ${JSON.stringify(targetEnv)}`);
114-
}
115-
116-
const publisher = new AssetPublishing(manifest, {
117-
aws: new PublishingAws(sdk, targetEnv),
118-
progressListener: new PublishingProgressListener(options.quiet ?? false),
119-
throwOnError: false,
120-
publishInParallel: options.parallel ?? true,
121-
buildAssets: true,
122-
publishAssets: false,
123-
});
124-
await publisher.publish();
125-
if (publisher.hasFailures) {
126-
throw new ToolkitError('Failed to build one or more assets. See the error messages above for more information.');
127-
}
128-
}
129-
13072
export class PublishingAws implements IAws {
13173
private sdkCache: Map<String, SDK> = new Map();
13274

@@ -241,10 +183,10 @@ export const EVENT_TO_LOGGER: Record<EventType, (x: string) => void> = {
241183
};
242184

243185
class PublishingProgressListener implements IPublishProgressListener {
244-
constructor(private readonly quiet: boolean) {}
186+
constructor() {}
245187

246188
public onPublishEvent(type: EventType, event: IPublishProgress): void {
247-
const handler = this.quiet && type !== 'fail' ? debug : EVENT_TO_LOGGER[type];
189+
const handler = EVENT_TO_LOGGER[type];
248190
handler(`[${event.percentComplete}%] ${type}: ${event.message}`);
249191
}
250192
}

packages/aws-cdk/lib/api/deployments/deployments.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import * as cdk_assets from 'cdk-assets';
44
import * as chalk from 'chalk';
55
import { AssetManifestBuilder } from './asset-manifest-builder';
66
import {
7-
buildAssets,
8-
type BuildAssetsOptions,
97
EVENT_TO_LOGGER,
10-
publishAssets,
11-
type PublishAssetsOptions,
128
PublishingAws,
139
} from './asset-publishing';
1410
import { determineAllowCrossAccountAssetPublishing } from './checks';
@@ -297,23 +293,13 @@ interface AssetOptions {
297293
}
298294

299295
export interface BuildStackAssetsOptions extends AssetOptions {
300-
/**
301-
* Options to pass on to `buildAssets()` function
302-
*/
303-
readonly buildOptions?: BuildAssetsOptions;
304-
305296
/**
306297
* Stack name this asset is for
307298
*/
308299
readonly stackName?: string;
309300
}
310301

311302
interface PublishStackAssetsOptions extends AssetOptions {
312-
/**
313-
* Options to pass on to `publishAsests()` function
314-
*/
315-
readonly publishOptions?: Omit<PublishAssetsOptions, 'buildAssets'>;
316-
317303
/**
318304
* Stack name this asset is for
319305
*/
@@ -640,43 +626,6 @@ export class Deployments {
640626
return stack.exists;
641627
}
642628

643-
private async prepareAndValidateAssets(asset: cxapi.AssetManifestArtifact, options: AssetOptions) {
644-
const env = await this.envs.accessStackForMutableStackOperations(options.stack);
645-
646-
await this.validateBootstrapStackVersion(
647-
options.stack.stackName,
648-
asset.requiresBootstrapStackVersion,
649-
asset.bootstrapStackVersionSsmParameter,
650-
env.resources);
651-
652-
const manifest = cdk_assets.AssetManifest.fromFile(asset.file);
653-
654-
return { manifest, stackEnv: env.resolvedEnvironment };
655-
}
656-
657-
/**
658-
* Build all assets in a manifest
659-
*
660-
* @deprecated Use `buildSingleAsset` instead
661-
*/
662-
public async buildAssets(asset: cxapi.AssetManifestArtifact, options: BuildStackAssetsOptions) {
663-
const { manifest, stackEnv } = await this.prepareAndValidateAssets(asset, options);
664-
await buildAssets(manifest, this.assetSdkProvider, stackEnv, options.buildOptions);
665-
}
666-
667-
/**
668-
* Publish all assets in a manifest
669-
*
670-
* @deprecated Use `publishSingleAsset` instead
671-
*/
672-
public async publishAssets(asset: cxapi.AssetManifestArtifact, options: PublishStackAssetsOptions) {
673-
const { manifest, stackEnv } = await this.prepareAndValidateAssets(asset, options);
674-
await publishAssets(manifest, this.assetSdkProvider, stackEnv, {
675-
...options.publishOptions,
676-
allowCrossAccount: await this.allowCrossAccountAssetPublishingForEnv(options.stack),
677-
});
678-
}
679-
680629
/**
681630
* Build a single asset from an asset manifest
682631
*
@@ -712,7 +661,6 @@ export class Deployments {
712661
/**
713662
* Publish a single asset from an asset manifest
714663
*/
715-
// eslint-disable-next-line max-len
716664
public async publishSingleAsset(
717665
assetManifest: cdk_assets.AssetManifest,
718666
asset: cdk_assets.IManifestEntry,

0 commit comments

Comments
 (0)