Skip to content

Commit 4867294

Browse files
authored
feat(appconfig-alpha): support for relative file paths when importing config (#28191)
When importing a config from a file, you can now pass a relative path (`config.json`) instead of the absolute path (`/Users/..../config.json`). Closes #26937. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c8627ce commit 4867294

14 files changed

+191
-35
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ new appconfig.HostedConfiguration(this, 'MyHostedConfiguration', {
9393

9494
You can define hosted configuration content using any of the following ConfigurationContent methods:
9595

96-
* `fromFile` - Defines the hosted configuration content from a file.
96+
* `fromFile` - Defines the hosted configuration content from a file (you can specify a relative path).
9797
* `fromInlineText` - Defines the hosted configuration from inline text.
9898
* `fromInlineJson` - Defines the hosted configuration from inline JSON.
9999
* `fromInlineYaml` - Defines the hosted configuration from inline YAML.
@@ -121,6 +121,8 @@ configuration data is syntactically and semantically correct. You can create val
121121
Lambda function.
122122
See [About validators](https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-configuration-and-profile.html#appconfig-creating-configuration-and-profile-validators) for more information.
123123

124+
When you import a JSON Schema validator from a file, you can pass in a relative path.
125+
124126
A hosted configuration with validators:
125127

126128
```ts

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from 'fs';
22
import * as mimeTypes from 'mime-types';
3+
import * as path from 'path';
34
import { PhysicalName, Stack, ArnFormat, Names, RemovalPolicy } from 'aws-cdk-lib';
45
import { CfnConfigurationProfile, CfnDeployment, CfnHostedConfigurationVersion } from 'aws-cdk-lib/aws-appconfig';
56
import * as cp from 'aws-cdk-lib/aws-codepipeline';
@@ -766,11 +767,11 @@ export abstract class JsonSchemaValidator implements IValidator {
766767
/**
767768
* Defines a JSON Schema validator from a file.
768769
*
769-
* @param path The path to the file that defines the validator
770+
* @param inputPath The path to the file that defines the validator
770771
*/
771-
public static fromFile(path: string): JsonSchemaValidator {
772+
public static fromFile(inputPath: string): JsonSchemaValidator {
772773
return {
773-
content: fs.readFileSync(path).toString(),
774+
content: fs.readFileSync(path.resolve(inputPath)).toString(),
774775
type: ValidatorType.JSON_SCHEMA,
775776
};
776777
}
@@ -824,13 +825,13 @@ export abstract class ConfigurationContent {
824825
/**
825826
* Defines the hosted configuration content from a file.
826827
*
827-
* @param path The path to the file that defines configuration content
828+
* @param inputPath The path to the file that defines configuration content
828829
* @param contentType The content type of the configuration
829830
*/
830-
public static fromFile(path: string, contentType?: string): ConfigurationContent {
831+
public static fromFile(inputPath: string, contentType?: string): ConfigurationContent {
831832
return {
832-
content: fs.readFileSync(path).toString(),
833-
contentType: contentType || mimeTypes.lookup(path) || 'application/json',
833+
content: fs.readFileSync(path.resolve(inputPath)).toString(),
834+
contentType: contentType || mimeTypes.lookup(inputPath) || 'application/json',
834835
};
835836
}
836837

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ describe('configuration', () => {
379379
}),
380380
}),
381381
application: app,
382-
content: ConfigurationContent.fromFile('./test/config.json'),
382+
content: ConfigurationContent.fromFile('test/config.json'),
383383
});
384384

385385
Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
@@ -763,6 +763,7 @@ describe('configuration', () => {
763763
application: app,
764764
validators: [
765765
JsonSchemaValidator.fromInline(validatorContent),
766+
JsonSchemaValidator.fromFile('test/schema.json'),
766767
],
767768
content: ConfigurationContent.fromInlineText('This is my content'),
768769
deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', {
@@ -783,6 +784,10 @@ describe('configuration', () => {
783784
Type: 'JSON_SCHEMA',
784785
Content: '\n {\n \"type\": \"object\",\n \"properties\": {\n \"computeResource\": {\n \"type\": \"object\",\n \"properties\": {\n \"ComputeAL1ImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n },\n \"GPUImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n },\n \"ARMImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n },\n \"ComputeAL2ImageId\": {\n \"type\": \"object\",\n \"properties\": {\n \"me-south-1\": { \"type\": \"string\" },\n \"ap-east-1\": { \"type\": \"string\" },\n \"ap-northeast-1\": { \"type\": \"string\" },\n \"ap-northeast-2\": { \"type\": \"string\" },\n \"ap-south-1\": { \"type\": \"string\" },\n \"ap-southeast-1\": { \"type\": \"string\" },\n \"ap-southeast-2\": { \"type\": \"string\" },\n \"ca-central-1\": { \"type\": \"string\" },\n \"cn-north-1\": { \"type\": \"string\" },\n \"cn-northwest-1\": { \"type\": \"string\" },\n \"eu-central-1\": { \"type\": \"string\" },\n \"eu-north-1\": { \"type\": \"string\" },\n \"eu-west-1\": { \"type\": \"string\" },\n \"eu-west-2\": { \"type\": \"string\" },\n \"eu-west-3\": { \"type\": \"string\" },\n \"sa-east-1\": { \"type\": \"string\" },\n \"us-east-1\": { \"type\": \"string\" },\n \"us-east-2\": { \"type\": \"string\" },\n \"us-gov-west-1\": { \"type\": \"string\" },\n \"us-gov-east-1\": { \"type\": \"string\" },\n \"us-west-1\": { \"type\": \"string\" },\n \"us-west-2\": { \"type\": \"string\" },\n \"eu-south-1\": { \"type\": \"string\" },\n \"ap-northeast-3\": { \"type\": \"string\" },\n \"af-south-1\": { \"type\": \"string\" }\n }\n }\n }\n }\n }\n }',
785786
},
787+
{
788+
Type: 'JSON_SCHEMA',
789+
Content: '{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}',
790+
},
786791
],
787792
LocationUri: 'hosted',
788793
});

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/appconfigconfigurationDefaultTestDeployAssert6752CD38.assets.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.assets.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/aws-appconfig-configuration.template.json

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,42 @@
8888
"ReplicateTo": "NONE"
8989
}
9090
},
91+
"MyHostedConfigFromFileDeploymentStrategyCAF37A7C": {
92+
"Type": "AWS::AppConfig::DeploymentStrategy",
93+
"Properties": {
94+
"DeploymentDurationInMinutes": 20,
95+
"FinalBakeTimeInMinutes": 10,
96+
"GrowthFactor": 10,
97+
"GrowthType": "EXPONENTIAL",
98+
"Name": "awsappconfigconfiguration-MyFromFile-DeploymentStrategy-C2367737",
99+
"ReplicateTo": "NONE"
100+
}
101+
},
102+
"MyHostedConfigFromFileConfigurationProfile32B2D26F": {
103+
"Type": "AWS::AppConfig::ConfigurationProfile",
104+
"Properties": {
105+
"ApplicationId": {
106+
"Ref": "MyAppConfigB4B63E75"
107+
},
108+
"LocationUri": "hosted",
109+
"Name": "awsappconfigconfiguration-MyHostedConfigFromFile-8ED1123C"
110+
}
111+
},
112+
"MyHostedConfigFromFile943CF9F9": {
113+
"Type": "AWS::AppConfig::HostedConfigurationVersion",
114+
"Properties": {
115+
"ApplicationId": {
116+
"Ref": "MyAppConfigB4B63E75"
117+
},
118+
"ConfigurationProfileId": {
119+
"Ref": "MyHostedConfigFromFileConfigurationProfile32B2D26F"
120+
},
121+
"Content": "{\n \"content\": \"This is the configuration content\"\n}",
122+
"ContentType": "application/json"
123+
},
124+
"UpdateReplacePolicy": "Retain",
125+
"DeletionPolicy": "Retain"
126+
},
91127
"MyHostedConfigConfigurationProfile2E1A2BBC": {
92128
"Type": "AWS::AppConfig::ConfigurationProfile",
93129
"Properties": {
@@ -97,6 +133,10 @@
97133
"LocationUri": "hosted",
98134
"Name": "awsappconfigconfiguration-MyHostedConfig-4CF350AE",
99135
"Validators": [
136+
{
137+
"Content": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}",
138+
"Type": "JSON_SCHEMA"
139+
},
100140
{
101141
"Content": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}",
102142
"Type": "JSON_SCHEMA"
@@ -565,7 +605,7 @@
565605
"S3Bucket": {
566606
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
567607
},
568-
"S3Key": "e2277687077a2abf9ae1af1cc9565e6715e2ebb62f79ec53aa75a1af9298f642.zip"
608+
"S3Key": "3fb6287214999ddeafa7cd0e3e58bc5144c8678bb720f3b5e45e8fd32f333eb3.zip"
569609
},
570610
"Description": "/opt/awscli/aws"
571611
}
@@ -736,7 +776,7 @@
736776
"S3Bucket": {
737777
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
738778
},
739-
"S3Key": "9eb41a5505d37607ac419321497a4f8c21cf0ee1f9b4a6b29aa04301aea5c7fd.zip"
779+
"S3Key": "e976a796f036a5efbf44b99e44cfb5a961df08d8dbf7cd37e60bf216fb982a00.zip"
740780
},
741781
"Environment": {
742782
"Variables": {

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/integ.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-appconfig-alpha/test/integ.configuration.js.snapshot/manifest.json

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)