Skip to content

Commit 58e87fb

Browse files
authored
refactor(appconfig): refactoring deployTo and contentType properties (#26768)
Refactoring deployTo property to only create a deployment if specified. Refactoring contentType to be passed in by ConfigurationContent. **Includes breaking change. Deployments will not be created anymore if deployTo is not specified and contentType cannot be passed in as a HostedConfiguration prop, only can be passed directly to ConfigurationContent ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 89393a2 commit 58e87fb

14 files changed

+239
-158
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
"@aws-cdk/assertions-alpha/fs-extra/**",
9797
"@aws-cdk/assertions/fs-extra",
9898
"@aws-cdk/assertions/fs-extra/**",
99+
"@aws-cdk/aws-appconfig-alpha/mime-types",
100+
"@aws-cdk/aws-appconfig-alpha/mime-types/**",
99101
"@aws-cdk/aws-codebuild/yaml",
100102
"@aws-cdk/aws-codebuild/yaml/**",
101103
"@aws-cdk/aws-codepipeline-actions/case",
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
AWS Cloud Development Kit (AWS CDK)
22
Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
-------------------------------------------------------------------------------
5+
6+
The AWS CDK includes the following third-party software/licensing:
7+
8+
** mime-db - https://www.npmjs.com/package/mime-db
9+
** mime-types - https://www.npmjs.com/package/mime-types
10+
(The MIT License)
11+
12+
Copyright (c) 2014 Jonathan Ong <[email protected]>
13+
Copyright (c) 2015-2022 Douglas Christopher Wilson <[email protected]>
14+
15+
Permission is hereby granted, free of charge, to any person obtaining
16+
a copy of this software and associated documentation files (the
17+
'Software'), to deal in the Software without restriction, including
18+
without limitation the rights to use, copy, modify, merge, publish,
19+
distribute, sublicense, and/or sell copies of the Software, and to
20+
permit persons to whom the Software is furnished to do so, subject to
21+
the following conditions:
22+
23+
The above copyright notice and this permission notice shall be
24+
included in all copies or substantial portions of the Software.
25+
26+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
27+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
30+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33+
34+
----------------

packages/@aws-cdk/aws-appconfig-alpha/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ declare const application: appconfig.Application;
7979

8080
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
8181
application,
82-
content: appconfig.ConfigurationContent.fromInline('This is my configuration content.'),
82+
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
8383
});
8484
```
8585

@@ -95,7 +95,7 @@ declare const application: appconfig.Application;
9595

9696
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
9797
application,
98-
content: appconfig.ConfigurationContent.fromInline('This is my configuration content.'),
98+
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
9999
type: appconfig.ConfigurationType.FEATURE_FLAGS,
100100
});
101101
```
@@ -111,7 +111,7 @@ declare const fn: lambda.Function;
111111

112112
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
113113
application,
114-
content: appconfig.ConfigurationContent.fromInline('This is my configuration content.'),
114+
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
115115
validators: [
116116
appconfig.JsonSchemaValidator.fromFile('schema.json'),
117117
appconfig.LambdaValidator.fromFunction(fn),
@@ -128,7 +128,7 @@ declare const application: appconfig.Application;
128128

129129
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
130130
application,
131-
content: appconfig.ConfigurationContent.fromInline('This is my configuration content.'),
131+
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
132132
deploymentStrategy: new appconfig.DeploymentStrategy(this, 'MyDeploymentStrategy', {
133133
rolloutStrategy: appconfig.RolloutStrategy.linear({
134134
growthFactor: 15,
@@ -139,7 +139,7 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
139139
});
140140
```
141141

142-
The `deployTo` parameter is used to specify which environments to deploy the configuration to. If this parameter is not specified, there will only be a deployment if there is one environment associated to the AWS AppConfig application.
142+
The `deployTo` parameter is used to specify which environments to deploy the configuration to. If this parameter is not specified, there will not be a deployment.
143143

144144
A hosted configuration with `deployTo`:
145145

@@ -149,7 +149,7 @@ declare const env: appconfig.Environment;
149149

150150
new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
151151
application,
152-
content: appconfig.ConfigurationContent.fromInline('This is my configuration content.'),
152+
content: appconfig.ConfigurationContent.fromInlineText('This is my configuration content.'),
153153
deployTo: [env],
154154
});
155155
```
@@ -301,7 +301,7 @@ new appconfig.SourcedConfiguration(this, 'MySourcedConfiguration', {
301301
});
302302
```
303303

304-
The `deployTo` parameter is used to specify which environments to deploy the configuration to. If this parameter is not specified, there will only be a deployment if there is one environment associated to the AWS AppConfig application.
304+
The `deployTo` parameter is used to specify which environments to deploy the configuration to. If this parameter is not specified, there will not be a deployment.
305305

306306
A sourced configuration with `deployTo`:
307307

packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts

+41-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs';
2+
import * as mimeTypes from 'mime-types';
23
import { PhysicalName, Stack, ArnFormat, Names, RemovalPolicy } from 'aws-cdk-lib';
34
import { CfnConfigurationProfile, CfnDeployment, CfnHostedConfigurationVersion } from 'aws-cdk-lib/aws-appconfig';
45
import * as cp from 'aws-cdk-lib/aws-codepipeline';
@@ -55,9 +56,8 @@ export interface ConfigurationOptions {
5556
/**
5657
* The list of environments to deploy the configuration to.
5758
*
58-
* If this parameter is not specified and there is only one environment
59-
* associated to the application, then we will deploy to that one. Otherwise,
60-
* there will be no deployment.
59+
* If this parameter is not specified, then there will be no
60+
* deployment.
6161
*
6262
* @default - None.
6363
*/
@@ -305,13 +305,7 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
305305
}
306306

307307
protected deployConfigToEnvironments() {
308-
if (this.application.environments.length == 0) {
309-
this.application.addEnvironment('Environment', {
310-
description: this.description,
311-
});
312-
}
313-
314-
if ((!this.deployTo && this.application.environments.length > 1) || !this.versionNumber) {
308+
if (!this.deployTo || !this.versionNumber) {
315309
return;
316310
}
317311

@@ -320,9 +314,6 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
320314
return;
321315
}
322316
const logicalId = `Deployment${this.getDeploymentHash(environment)}`;
323-
if (this.node.tryFindChild(logicalId)) {
324-
return;
325-
}
326317
new CfnDeployment(this, logicalId, {
327318
applicationId: this.application.applicationId,
328319
configurationProfileId: this.configurationProfileId,
@@ -342,11 +333,6 @@ export interface HostedConfigurationOptions extends ConfigurationOptions {
342333
*/
343334
readonly content: ConfigurationContent;
344335

345-
/**
346-
* The content type of the hosted configuration.
347-
*/
348-
readonly contentType?: string;
349-
350336
/**
351337
* The latest version number of the hosted configuration.
352338
*/
@@ -364,11 +350,6 @@ export interface HostedConfigurationProps extends ConfigurationProps {
364350
*/
365351
readonly content: ConfigurationContent;
366352

367-
/**
368-
* The content type of the hosted configuration.
369-
*/
370-
readonly contentType?: string;
371-
372353
/**
373354
* The latest version number of the hosted configuration.
374355
*/
@@ -444,7 +425,7 @@ export class HostedConfiguration extends ConfigurationBase {
444425
this.extensible = new ExtensibleBase(scope, this.configurationProfileArn, this.name);
445426

446427
this.content = props.content.content;
447-
this.contentType = props.contentType || 'application/json';
428+
this.contentType = props.content.contentType;
448429
this.latestVersionNumber = props.latestVersionNumber;
449430
this.versionLabel = props.versionLabel;
450431
this._cfnHostedConfigurationVersion = new CfnHostedConfigurationVersion(this, 'Resource', {
@@ -792,28 +773,62 @@ export abstract class ConfigurationContent {
792773
* Defines the hosted configuration content from a file.
793774
*
794775
* @param path The path to the file that defines configuration content
776+
* @param contentType The content type of the configuration
795777
*/
796-
public static fromFile(path: string): ConfigurationContent {
778+
public static fromFile(path: string, contentType?: string): ConfigurationContent {
797779
return {
798780
content: fs.readFileSync(path).toString(),
781+
contentType: contentType || mimeTypes.lookup(path) || 'application/json',
799782
};
800783
}
801784

802785
/**
803786
* Defines the hosted configuration content from inline code.
804787
*
805788
* @param content The inline code that defines the configuration content
789+
* @param contentType The content type of the configuration
806790
*/
807-
public static fromInline(content: string): ConfigurationContent {
791+
public static fromInline(content: string, contentType?: string): ConfigurationContent {
808792
return {
809793
content,
794+
contentType: contentType || 'application/octet-stream',
795+
};
796+
}
797+
798+
/**
799+
* Defines the hosted configuration content as JSON from inline code.
800+
*
801+
* @param content The inline code that defines the configuration content
802+
* @param contentType The content type of the configuration
803+
*/
804+
public static fromInlineJson(content: string, contentType?: string): ConfigurationContent {
805+
return {
806+
content,
807+
contentType: contentType || 'application/json',
808+
};
809+
}
810+
811+
/**
812+
* Defines the hosted configuration content as text from inline code.
813+
*
814+
* @param content The inline code that defines the configuration content
815+
*/
816+
public static fromInlineText(content: string): ConfigurationContent {
817+
return {
818+
content,
819+
contentType: 'text/plain',
810820
};
811821
}
812822

813823
/**
814824
* The configuration content.
815825
*/
816826
public abstract readonly content: string;
827+
828+
/**
829+
* The configuration content type.
830+
*/
831+
public abstract readonly contentType: string;
817832
}
818833

819834
/**

packages/@aws-cdk/aws-appconfig-alpha/package.json

+10-5
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@
7676
},
7777
"license": "Apache-2.0",
7878
"devDependencies": {
79-
"aws-cdk-lib": "0.0.0",
8079
"@aws-cdk/cdk-build-tools": "0.0.0",
8180
"@aws-cdk/integ-runner": "0.0.0",
82-
"@aws-cdk/pkglint": "0.0.0",
8381
"@aws-cdk/integ-tests-alpha": "0.0.0",
82+
"@aws-cdk/pkglint": "0.0.0",
8483
"@types/jest": "^29.5.3",
84+
"@types/mime-types": "^2.1.1",
85+
"aws-cdk-lib": "0.0.0",
8586
"constructs": "^10.0.0",
86-
"jest": "^29.6.2"
87+
"jest": "^29.6.1"
8788
},
8889
"dependencies": {
8990
"aws-cdk-lib": "0.0.0",
90-
"constructs": "^10.0.0"
91+
"constructs": "^10.0.0",
92+
"mime-types": "^2.1.35"
9193
},
9294
"homepage": "https://github.com/aws/aws-cdk",
9395
"peerDependencies": {
@@ -115,5 +117,8 @@
115117
"env": {
116118
"AWSLINT_BASE_CONSTRUCT": true
117119
}
118-
}
120+
},
121+
"bundleDependencies": [
122+
"mime-types"
123+
]
119124
}

0 commit comments

Comments
 (0)