Skip to content

Commit

Permalink
feat: add visibility configuration (#604)
Browse files Browse the repository at this point in the history
Co-authored-by: bboure <[email protected]>
  • Loading branch information
N3RG4L and bboure authored Jun 28, 2023
1 parent ca13f78 commit ffedf54
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/general-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ appSync:
- `waf`: See [Web Application Firefall](WAF.md)
- `logging`: See [Logging](#Logging)
- `xrayEnabled`: Boolean. Enable or disable X-Ray tracing.
- `visibility`: Optional. `GLOBAL` or `PRIVATE`. Defaults to `GLOBAL`.
- `tags`: A key-value pair for tagging this AppSync API

## Schema
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/api.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Object {
"Value": "Dev",
},
],
"Visibility": "GLOBAL",
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
Expand Down Expand Up @@ -64,6 +65,7 @@ Object {
"Value": "Dev",
},
],
"Visibility": "GLOBAL",
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
Expand Down
31 changes: 31 additions & 0 deletions src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ describe('Api', () => {
"Value": "Dev",
},
],
"Visibility": "GLOBAL",
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
},
}
`);
});

it('should compile the Api Resource for a private endpoint', () => {
const api = new Api(
given.appSyncConfig({
visibility: 'PRIVATE',
}),
plugin,
);
expect(api.compileEndpoint()).toMatchInlineSnapshot(`
Object {
"GraphQlApi": Object {
"Properties": Object {
"AuthenticationType": "API_KEY",
"Name": "MyApi",
"Tags": Array [
Object {
"Key": "stage",
"Value": "Dev",
},
],
"Visibility": "PRIVATE",
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
Expand Down Expand Up @@ -63,6 +92,7 @@ describe('Api', () => {
"Value": "Dev",
},
],
"Visibility": "GLOBAL",
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
Expand Down Expand Up @@ -168,6 +198,7 @@ describe('Api', () => {
"DefaultAction": "ALLOW",
"UserPoolId": "pool123",
},
"Visibility": "GLOBAL",
"XrayEnabled": false,
},
"Type": "AWS::AppSync::GraphQLApi",
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/validation/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ exports[`Valdiation Waf Invalid should validate a Throttle limit 1`] = `
exports[`Valdiation should validate 1`] = `
": must have required property 'name'
: must have required property 'authentication'
/unknownPorp: invalid (unknown) property"
/unknownPorp: invalid (unknown) property
/xrayEnabled: must be boolean
/visibility: must be \\"GLOBAL\\" or \\"PRIVATE\\""
`;
14 changes: 14 additions & 0 deletions src/__tests__/validation/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ import { basicConfig } from '../basicConfig';

describe('Valdiation', () => {
it('should validate ', () => {
expect(
validateConfig({
...basicConfig,
visibility: 'GLOBAL',
xrayEnabled: true,
tags: {
foo: 'bar',
},
}),
).toBe(true);

expect(function () {
validateConfig({
visibility: 'FOO',
xrayEnabled: 'BAR',
unknownPorp: 'foo',
});
}).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -55,6 +68,7 @@ describe('Valdiation', () => {
retentionInDays: 'bar',
excludeVerboseContent: 'buzz',
loggingRoleArn: 123,
visibility: 'FOO',
},
},
},
Expand Down
1 change: 1 addition & 0 deletions src/resources/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class Api {
Type: 'AWS::AppSync::GraphQLApi',
Properties: {
Name: this.config.name,
Visibility: this.config.visibility || 'GLOBAL',
XrayEnabled: this.config.xrayEnabled || false,
Tags: this.getTagsConfig(),
},
Expand Down
1 change: 1 addition & 0 deletions src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type AppSyncConfig = {
caching?: CachingConfig;
waf?: WafConfig;
tags?: Record<string, string>;
visibility?: 'GLOBAL' | 'PRIVATE';
};

export type IamStatement = {
Expand Down
5 changes: 5 additions & 0 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ export const appSyncSchema = {
},
},
xrayEnabled: { type: 'boolean' },
visibility: {
type: 'string',
enum: ['GLOBAL', 'PRIVATE'],
errorMessage: 'must be "GLOBAL" or "PRIVATE"',
},
substitutions: { $ref: '#/definitions/substitutions' },
waf: {
type: 'object',
Expand Down

0 comments on commit ffedf54

Please sign in to comment.