Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion src/__tests__/validation/__snapshots__/auth.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports[`Valdiation Invalid should validate a Lambda with missing config 1`] = `
exports[`Valdiation Invalid should validate a OIDC with empty config 1`] = `"/authentication/config: must have required property 'issuer'"`;

exports[`Valdiation Invalid should validate a OIDC with invalid config 1`] = `
"/authentication/config/issuer: must be string
"/authentication/config/issuer: must be a string or a CloudFormation intrinsic function
/authentication/config/clientId: must be string
/authentication/config/iatTTL: must be number
/authentication/config/authTTL: must be number"
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/validation/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`Valdiation EnhancedMetrics Invalid should validate a Missing required f
exports[`Valdiation Log Invalid should validate a Invalid 1`] = `
"/logging/level: must be one of 'ALL', 'INFO', 'DEBUG', 'ERROR' or 'NONE'
/logging/retentionInDays: must be integer
/logging/excludeVerboseContent: must be boolean"
/logging/excludeVerboseContent: must be a boolean or a CloudFormation intrinsic function"
`;

exports[`Valdiation Waf Invalid should validate a Invalid 1`] = `
Expand All @@ -64,7 +64,7 @@ exports[`Valdiation should validate 1`] = `
": must have required property 'name'
: must have required property 'authentication'
/unknownPorp: invalid (unknown) property
/xrayEnabled: must be boolean
/xrayEnabled: must be a boolean or a CloudFormation intrinsic function
/visibility: must be "GLOBAL" or "PRIVATE"
/introspection: must be boolean
/queryDepthLimit: must be integer
Expand Down
13 changes: 13 additions & 0 deletions src/__tests__/validation/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('Valdiation', () => {
},
} as AppSyncConfig,
},
{
name: 'OIDC with an intrinsic function issuer',
config: {
...basicConfig,
authentication: {
type: 'OPENID_CONNECT',
config: {
issuer: { 'Fn::ImportValue': 'IssuerUrl' },
clientId: '90941906-004b-4cc5-9685-6864a8e08835',
},
},
} as AppSyncConfig,
},
{
name: 'IAM',
config: {
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/validation/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ describe('Valdiation', () => {
}).toThrowErrorMatchingSnapshot();
});

it('should allow intrinsic functions for xrayEnabled', () => {
expect(
validateConfig({
...basicConfig,
xrayEnabled: { 'Fn::ImportValue': 'XrayEnabled' },
} as AppSyncConfig),
).toBe(true);
});

describe('Log', () => {
describe('Valid', () => {
const assertions = [
Expand All @@ -73,6 +82,16 @@ describe('Valdiation', () => {
},
} as AppSyncConfig,
},
{
name: 'Intrinsic excludeVerboseContent',
config: {
...basicConfig,
logging: {
level: 'ALL',
excludeVerboseContent: { 'Fn::ImportValue': 'ExcludeVerbose' },
},
} as AppSyncConfig,
},
];

assertions.forEach((config) => {
Expand Down
11 changes: 10 additions & 1 deletion src/types/cloudFormation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ export type FnSub = {
'Fn::Sub': [string, Record<string, string | IntrinsicFunction>];
};

export type IntrinsicFunction = FnGetAtt | FnJoin | FnRef | FnSub;
export type FnImportValue = {
'Fn::ImportValue': string | IntrinsicFunction;
};

export type IntrinsicFunction =
| FnGetAtt
| FnJoin
| FnRef
| FnSub
| FnImportValue;

export type CfnDeltaSyncConfig = {
BaseTableTTL: number;
Expand Down
4 changes: 2 additions & 2 deletions src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export type LambdaAuth = {
export type OidcAuth = {
type: 'OPENID_CONNECT';
config: {
issuer: string;
issuer: string | IntrinsicFunction;
clientId: string;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
iatTTL?: number;
authTTL?: number;
Expand Down Expand Up @@ -243,7 +243,7 @@ export type VisibilityConfig = {
export type LoggingConfig = {
level: 'ERROR' | 'NONE' | 'ALL' | 'DEBUG' | 'INFO';
enabled?: boolean;
excludeVerboseContent?: boolean;
excludeVerboseContent?: boolean | IntrinsicFunction;
retentionInDays?: number;
roleArn?: string | IntrinsicFunction;
};
Expand Down
3 changes: 2 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BuildOptions } from 'esbuild';
import { IntrinsicFunction } from './cloudFormation';
import {
ApiKeyConfig,
Auth,
Expand Down Expand Up @@ -35,7 +36,7 @@ export type AppSyncConfig = {
| Record<string, DataSourceConfig>;
substitutions?: Substitutions;
environment?: EnvironmentVariables;
xrayEnabled?: boolean;
xrayEnabled?: boolean | IntrinsicFunction;
logging?: LoggingConfig;
caching?: CachingConfig;
waf?: WafConfig;
Expand Down
3 changes: 2 additions & 1 deletion src/types/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BuildOptions } from 'esbuild';
import { IntrinsicFunction } from './cloudFormation';
import {
Auth,
DomainConfig,
Expand Down Expand Up @@ -33,7 +34,7 @@ export type AppSyncConfig = {
substitutions?: Substitutions;
environment?: EnvironmentVariables;
enhancedMetrics?: EnhancedMetricsConfig;
xrayEnabled?: boolean;
xrayEnabled?: boolean | IntrinsicFunction;
logging?: LoggingConfig;
caching?: CachingConfig;
waf?: WafConfig;
Expand Down
19 changes: 16 additions & 3 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ export const appSyncSchema = {
],
errorMessage: 'must be a string or a CloudFormation intrinsic function',
},
booleanOrIntrinsicFunction: {
oneOf: [
{ type: 'boolean' },
{
type: 'object',
required: [],
additionalProperties: true,
},
],
errorMessage: 'must be a boolean or a CloudFormation intrinsic function',
},
mappingTemplate: {
oneOf: [{ type: 'string' }, { const: false }],
errorMessage:
Expand Down Expand Up @@ -133,7 +144,7 @@ export const appSyncSchema = {
oidcAuth: {
type: 'object',
properties: {
issuer: { type: 'string' },
issuer: { $ref: '#/definitions/stringOrIntrinsicFunction' },
clientId: { type: 'string' },
iatTTL: { type: 'number' },
authTTL: { type: 'number' },
Expand Down Expand Up @@ -699,7 +710,7 @@ export const appSyncSchema = {
'when using CloudFormation, you must provide either certificateArn or hostedZoneId.',
},
},
xrayEnabled: { type: 'boolean' },
xrayEnabled: { $ref: '#/definitions/booleanOrIntrinsicFunction' },
visibility: {
type: 'string',
enum: ['GLOBAL', 'PRIVATE'],
Expand Down Expand Up @@ -820,7 +831,9 @@ export const appSyncSchema = {
"must be one of 'ALL', 'INFO', 'DEBUG', 'ERROR' or 'NONE'",
},
retentionInDays: { type: 'integer' },
excludeVerboseContent: { type: 'boolean' },
excludeVerboseContent: {
$ref: '#/definitions/booleanOrIntrinsicFunction',
},
enabled: { type: 'boolean' },
},
required: ['level'],
Expand Down
Loading