Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(appconfig-alpha): support for relative file paths when importing config #28191

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ configuration data is syntactically and semantically correct. You can create val
Lambda function.
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.

When you import a JSON Schema validator from a file, you can pass in a relative path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update here as well?

* `fromFile` - Defines the hosted configuration content from a file (you can specify a relative path).


A hosted configuration with validators:

```ts
Expand Down
15 changes: 8 additions & 7 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as mimeTypes from 'mime-types';
import * as path from 'path';
import { PhysicalName, Stack, ArnFormat, Names, RemovalPolicy } from 'aws-cdk-lib';
import { CfnConfigurationProfile, CfnDeployment, CfnHostedConfigurationVersion } from 'aws-cdk-lib/aws-appconfig';
import * as cp from 'aws-cdk-lib/aws-codepipeline';
Expand Down Expand Up @@ -766,11 +767,11 @@ export abstract class JsonSchemaValidator implements IValidator {
/**
* Defines a JSON Schema validator from a file.
*
* @param path The path to the file that defines the validator
* @param inputPath The path to the file that defines the validator
*/
public static fromFile(path: string): JsonSchemaValidator {
public static fromFile(inputPath: string): JsonSchemaValidator {
return {
content: fs.readFileSync(path).toString(),
content: fs.readFileSync(path.resolve(inputPath)).toString(),
type: ValidatorType.JSON_SCHEMA,
};
}
Expand Down Expand Up @@ -824,13 +825,13 @@ export abstract class ConfigurationContent {
/**
* Defines the hosted configuration content from a file.
*
* @param path The path to the file that defines configuration content
* @param inputPath The path to the file that defines configuration content
* @param contentType The content type of the configuration
*/
public static fromFile(path: string, contentType?: string): ConfigurationContent {
public static fromFile(inputPath: string, contentType?: string): ConfigurationContent {
return {
content: fs.readFileSync(path).toString(),
contentType: contentType || mimeTypes.lookup(path) || 'application/json',
content: fs.readFileSync(path.resolve(inputPath)).toString(),
contentType: contentType || mimeTypes.lookup(inputPath) || 'application/json',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('configuration', () => {
}),
}),
application: app,
content: ConfigurationContent.fromFile('./test/config.json'),
content: ConfigurationContent.fromFile('test/config.json'),
});

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ConfigurationProfile', {
Expand Down Expand Up @@ -763,6 +763,7 @@ describe('configuration', () => {
application: app,
validators: [
JsonSchemaValidator.fromInline(validatorContent),
JsonSchemaValidator.fromFile('test/schema.json'),
],
content: ConfigurationContent.fromInlineText('This is my content'),
deploymentStrategy: new DeploymentStrategy(stack, 'MyDeploymentStrategy', {
Expand All @@ -783,6 +784,10 @@ describe('configuration', () => {
Type: 'JSON_SCHEMA',
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 }',
},
{
Type: 'JSON_SCHEMA',
Content: '{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}',
},
],
LocationUri: 'hosted',
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@
"ReplicateTo": "NONE"
}
},
"MyHostedConfigFromFileDeploymentStrategyCAF37A7C": {
"Type": "AWS::AppConfig::DeploymentStrategy",
"Properties": {
"DeploymentDurationInMinutes": 20,
"FinalBakeTimeInMinutes": 10,
"GrowthFactor": 10,
"GrowthType": "EXPONENTIAL",
"Name": "awsappconfigconfiguration-MyFromFile-DeploymentStrategy-C2367737",
"ReplicateTo": "NONE"
}
},
"MyHostedConfigFromFileConfigurationProfile32B2D26F": {
"Type": "AWS::AppConfig::ConfigurationProfile",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"LocationUri": "hosted",
"Name": "awsappconfigconfiguration-MyHostedConfigFromFile-8ED1123C"
}
},
"MyHostedConfigFromFile943CF9F9": {
"Type": "AWS::AppConfig::HostedConfigurationVersion",
"Properties": {
"ApplicationId": {
"Ref": "MyAppConfigB4B63E75"
},
"ConfigurationProfileId": {
"Ref": "MyHostedConfigFromFileConfigurationProfile32B2D26F"
},
"Content": "{\n \"content\": \"This is the configuration content\"\n}",
"ContentType": "application/json"
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"MyHostedConfigConfigurationProfile2E1A2BBC": {
"Type": "AWS::AppConfig::ConfigurationProfile",
"Properties": {
Expand All @@ -97,6 +133,10 @@
"LocationUri": "hosted",
"Name": "awsappconfigconfiguration-MyHostedConfig-4CF350AE",
"Validators": [
{
"Content": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}",
"Type": "JSON_SCHEMA"
},
{
"Content": "{\n \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n \"type\": \"string\"\n}",
"Type": "JSON_SCHEMA"
Expand Down Expand Up @@ -565,7 +605,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "e2277687077a2abf9ae1af1cc9565e6715e2ebb62f79ec53aa75a1af9298f642.zip"
"S3Key": "3fb6287214999ddeafa7cd0e3e58bc5144c8678bb720f3b5e45e8fd32f333eb3.zip"
},
"Description": "/opt/awscli/aws"
}
Expand Down Expand Up @@ -736,7 +776,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "9eb41a5505d37607ac419321497a4f8c21cf0ee1f9b4a6b29aa04301aea5c7fd.zip"
"S3Key": "e976a796f036a5efbf44b99e44cfb5a961df08d8dbf7cd37e60bf216fb982a00.zip"
},
"Environment": {
"Variables": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading