Skip to content

Commit f0018a4

Browse files
author
amazon-meaisiah
committed
Prettier -> Standard
1 parent 7d416d5 commit f0018a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4772
-3715
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ To send us a pull request, please:
3232
1. Fork the repository.
3333
2. Working off the latest version of the *staging* branch, modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
3434
3. Ensure local tests pass.
35-
4. Run `prettier` on your new code to ensure style consistency. Remember to only reformat files relevant to your changes.
35+
4. Run `standard --fix` on your new code to ensure style consistency. Remember to only reformat files relevant to your changes.
3636
5. Commit to your fork using clear commit messages.
3737
6. Send us a pull request merging into the *staging* branch, answering any default questions in the pull request interface.
3838
7. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

__tests__/cfn-integration-test.js

+101-101
Original file line numberDiff line numberDiff line change
@@ -2,111 +2,111 @@ const fs = require('fs')
22
const rp = require('request-promise')
33

44
describe('template.yaml', () => {
5-
// NOTE: These tests all assume that the CFN template has already been packaged *PER REGION*!
6-
const cfnTimeout = 75,
7-
// run the test with a timeout of slightly longer than double the CFN stack timeout
8-
testTimeout = 1000*60*cfnTimeout*2 + 1
9-
const _console = console.log
10-
11-
async function commonTest(region, stackMiddlefix) {
12-
let unixTimestamp = Math.floor(new Date() / 1000),
13-
stackName = `cfn-integ-${ stackMiddlefix }-${ unixTimestamp }`,
14-
s3Params = {
15-
// CFN, when reading the template from S3, requires the S3 bucket to be in the same region as the CFN stack...
16-
Bucket: `dev-portal-integ-${ region }`,
17-
Body: fs.readFileSync(`./cloudformation/packaged-${region}.yaml`),
18-
Key: stackName
19-
},
20-
cfnParams = {
21-
StackName: stackName,
22-
Capabilities: ['CAPABILITY_NAMED_IAM', 'CAPABILITY_AUTO_EXPAND'],
23-
Parameters: [
24-
{
25-
ParameterKey: 'DevPortalSiteS3BucketName',
26-
ParameterValue: `integ-${ stackMiddlefix }-${ unixTimestamp }-dev-portal-test`
27-
},
28-
{
29-
ParameterKey: 'ArtifactsS3BucketName',
30-
ParameterValue: `integ-${ stackMiddlefix }-${ unixTimestamp }-artifact-bucket`
31-
},
32-
{
33-
ParameterKey: 'DevPortalCustomersTableName',
34-
ParameterValue: `Customers${ unixTimestamp }`
35-
},
36-
{
37-
ParameterKey: 'CognitoDomainNameOrPrefix',
38-
ParameterValue: `integ-${ stackMiddlefix }-${ unixTimestamp }`
39-
}
40-
],
41-
// RoleARN: 'STRING_VALUE',
42-
TimeoutInMinutes: cfnTimeout
43-
}
44-
45-
console.log('commonTest', region)
46-
47-
const AWS = require('aws-sdk')
48-
AWS.config.update({ region: region })
49-
50-
// pin versions of SDKs
51-
const cfn = new AWS.CloudFormation({ region: region }),
52-
s3 = new AWS.S3({ region: region }),
53-
logger = function (input) {
54-
_console(`${region}:${stackName}:${input}`)
55-
}
56-
57-
// Upload the packaged template to S3, then use the resulting URL in the CFN createStack call
58-
// This is necessary because the file is too large to deliver in-line to CFN
59-
cfnParams.TemplateURL =(await s3.upload(s3Params).promise()).Location
60-
61-
logger('createStack call starting.')
62-
await cfn.createStack(cfnParams).promise()
63-
logger('createStack call succeeded.')
64-
65-
logger('stackExists waiter starting.')
66-
await cfn.waitFor('stackExists', { StackName: stackName }).promise()
67-
logger('stackExists waiter succeeded.')
68-
69-
logger('stackCreateComplete waiter starting.')
70-
let devPortalUrl =
71-
(await cfn.waitFor('stackCreateComplete', { StackName: stackName }).promise()).Stacks[0].Outputs
72-
.find((output) => output.OutputKey === 'WebsiteURL').OutputValue
73-
logger('stackCreateComplete waiter succeeded.')
5+
// NOTE: These tests all assume that the CFN template has already been packaged *PER REGION*!
6+
const cfnTimeout = 75
7+
// run the test with a timeout of slightly longer than double the CFN stack timeout
8+
const testTimeout = 1000 * 60 * cfnTimeout * 2 + 1
9+
const _console = console.log
10+
11+
async function commonTest (region, stackMiddlefix) {
12+
const unixTimestamp = Math.floor(new Date() / 1000)
13+
const stackName = `cfn-integ-${stackMiddlefix}-${unixTimestamp}`
14+
const s3Params = {
15+
// CFN, when reading the template from S3, requires the S3 bucket to be in the same region as the CFN stack...
16+
Bucket: `dev-portal-integ-${region}`,
17+
Body: fs.readFileSync(`./cloudformation/packaged-${region}.yaml`),
18+
Key: stackName
19+
}
20+
const cfnParams = {
21+
StackName: stackName,
22+
Capabilities: ['CAPABILITY_NAMED_IAM', 'CAPABILITY_AUTO_EXPAND'],
23+
Parameters: [
24+
{
25+
ParameterKey: 'DevPortalSiteS3BucketName',
26+
ParameterValue: `integ-${stackMiddlefix}-${unixTimestamp}-dev-portal-test`
27+
},
28+
{
29+
ParameterKey: 'ArtifactsS3BucketName',
30+
ParameterValue: `integ-${stackMiddlefix}-${unixTimestamp}-artifact-bucket`
31+
},
32+
{
33+
ParameterKey: 'DevPortalCustomersTableName',
34+
ParameterValue: `Customers${unixTimestamp}`
35+
},
36+
{
37+
ParameterKey: 'CognitoDomainNameOrPrefix',
38+
ParameterValue: `integ-${stackMiddlefix}-${unixTimestamp}`
39+
}
40+
],
41+
// RoleARN: 'STRING_VALUE',
42+
TimeoutInMinutes: cfnTimeout
43+
}
7444

75-
logger(`verifying that stack is available at ${devPortalUrl} .`)
76-
let staticIndex = await rp(devPortalUrl)
45+
console.log('commonTest', region)
7746

78-
expect(staticIndex.includes('<title>Developer Portal</title>')).toBeTruthy()
79-
logger(`verified that stack is available at ${devPortalUrl} .`)
47+
const AWS = require('aws-sdk')
48+
AWS.config.update({ region: region })
8049

81-
// add RoleArn: ... later
82-
logger('deleteStack call starting.')
83-
await cfn.deleteStack({ StackName: stackName }).promise()
84-
logger('deleteStack call succeeded.')
50+
// pin versions of SDKs
51+
const cfn = new AWS.CloudFormation({ region: region })
52+
const s3 = new AWS.S3({ region: region })
53+
const logger = function (input) {
54+
_console(`${region}:${stackName}:${input}`)
55+
}
8556

86-
logger('stackDeleteComplete waiter starting.')
87-
await cfn.waitFor('stackDeleteComplete', { StackName: stackName }).promise()
88-
logger('stackDeleteComplete waiter succeeded.')
57+
// Upload the packaged template to S3, then use the resulting URL in the CFN createStack call
58+
// This is necessary because the file is too large to deliver in-line to CFN
59+
cfnParams.TemplateURL = (await s3.upload(s3Params).promise()).Location
8960

90-
// pass the test; we successfully stood the stack up and tore it down
91-
expect(true).toBe(true)
61+
logger('createStack call starting.')
62+
await cfn.createStack(cfnParams).promise()
63+
logger('createStack call succeeded.')
9264

93-
return true
94-
}
65+
logger('stackExists waiter starting.')
66+
await cfn.waitFor('stackExists', { StackName: stackName }).promise()
67+
logger('stackExists waiter succeeded.')
9568

96-
test.concurrent('should stand up and tear down the stack in IAD', async () => {
97-
return commonTest('us-east-1', 'us-east-1')
98-
}, testTimeout)
99-
100-
test.concurrent('should stand up and tear down the stack in a non-IAD region', async () => {
101-
return commonTest('us-west-2', 'us-west-2')
102-
}, testTimeout)
103-
104-
// Implement these! Hardest part will be having test ACM certs in the account
105-
// test('should stand up and tear down a custom domain stack in IAD', async () => {
106-
// return commonTest('us-east-1', 'domain-us-east-1')
107-
// }, testTimeout)
108-
//
109-
// test('should stand up and tear down a custom domain stack in a non-IAD region', async () => {
110-
// return commonTest('us-west-2', 'domain-us-west-2')
111-
// }, testTimeout)
112-
})
69+
logger('stackCreateComplete waiter starting.')
70+
const devPortalUrl =
71+
(await cfn.waitFor('stackCreateComplete', { StackName: stackName }).promise()).Stacks[0].Outputs
72+
.find((output) => output.OutputKey === 'WebsiteURL').OutputValue
73+
logger('stackCreateComplete waiter succeeded.')
74+
75+
logger(`verifying that stack is available at ${devPortalUrl} .`)
76+
const staticIndex = await rp(devPortalUrl)
77+
78+
expect(staticIndex.includes('<title>Developer Portal</title>')).toBeTruthy()
79+
logger(`verified that stack is available at ${devPortalUrl} .`)
80+
81+
// add RoleArn: ... later
82+
logger('deleteStack call starting.')
83+
await cfn.deleteStack({ StackName: stackName }).promise()
84+
logger('deleteStack call succeeded.')
85+
86+
logger('stackDeleteComplete waiter starting.')
87+
await cfn.waitFor('stackDeleteComplete', { StackName: stackName }).promise()
88+
logger('stackDeleteComplete waiter succeeded.')
89+
90+
// pass the test; we successfully stood the stack up and tore it down
91+
expect(true).toBe(true)
92+
93+
return true
94+
}
95+
96+
test.concurrent('should stand up and tear down the stack in IAD', async () => {
97+
return commonTest('us-east-1', 'us-east-1')
98+
}, testTimeout)
99+
100+
test.concurrent('should stand up and tear down the stack in a non-IAD region', async () => {
101+
return commonTest('us-west-2', 'us-west-2')
102+
}, testTimeout)
103+
104+
// Implement these! Hardest part will be having test ACM certs in the account
105+
// test('should stand up and tear down a custom domain stack in IAD', async () => {
106+
// return commonTest('us-east-1', 'domain-us-east-1')
107+
// }, testTimeout)
108+
//
109+
// test('should stand up and tear down a custom domain stack in a non-IAD region', async () => {
110+
// return commonTest('us-west-2', 'domain-us-west-2')
111+
// }, testTimeout)
112+
})

dev-portal/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ module.exports = {
3131
// customersTableName: `DevPortalCustomers`,
3232

3333
// Set this to overwrite-content if you want to reset your custom content back to the defaults. Defaults to ``
34-
// staticAssetRebuildMode: `overwrite-content` // ONLY SET
34+
// staticAssetRebuildMode: `overwrite-content`, // ONLY SET
3535

3636
// AWS SAM CLI profile option: optional specific profile from your AWS credential file. Not used by default
37-
//awsSamCliProfile: "my-profile"
37+
//awsSamCliProfile: "my-profile",
38+
39+
// Set this to `true` if you want to enable development mode. It's `false` by default, and unless you're actively developing on the developer portal itself locally, you should generally leave it unset as it disables most CORS protections.
40+
//developmentMode: false
3841
}
3942
```
4043
5. Run `npm run release`. This will build the static assets, deploy them, and generate the `dev-portal/public/config.js` file needed for local development. Take note of the bucket names you use
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
const util = require('util');
2-
const exec = util.promisify(require('child_process').exec);
3-
const readline = require('readline');
4-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
1+
const util = require('util')
2+
const exec = util.promisify(require('child_process').exec)
3+
const readline = require('readline')
4+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
55

66
let filter = process.argv[2]
77
let logGroups
88

9-
exec(`zsh -li <(echo "aws logs describe-log-groups")`, { shell: `/bin/zsh` }).then(({ stdout }) => {
9+
exec('zsh -li <(echo "aws logs describe-log-groups")', { shell: '/bin/zsh' }).then(({ stdout }) => {
1010
logGroups = JSON.parse(stdout).logGroups.map(group => group.logGroupName)
1111

1212
if (filter) {
13+
// eslint-disable-next-line no-eval
1314
filter = (new RegExp(eval(filter)))
1415
logGroups = logGroups.filter(groupName => filter.test(groupName))
1516
}
1617

17-
if (logGroups.length)
18+
if (logGroups.length) {
1819
return new Promise(resolve => rl.question(`${logGroups.join('\n')} \n\nAre you sure you want to delete the listed log groups?\n-> `, resolve))
19-
.then((answer) => {
20-
rl.close();
20+
.then((answer) => {
21+
rl.close()
2122

22-
if (answer[0].toLowerCase() === 'y') {
23-
console.log('\nDeleting...')
24-
logGroups = logGroups.map(logGroupName => `aws logs delete-log-group --log-group-name ${logGroupName};`).join('\n')
23+
if (answer[0].toLowerCase() === 'y') {
24+
console.log('\nDeleting...')
25+
logGroups = logGroups.map(logGroupName => `aws logs delete-log-group --log-group-name ${logGroupName};`).join('\n')
2526

26-
return exec(`zsh -li <(echo "${logGroups}")`, { shell: `/bin/zsh` })
27-
.then(() => {
28-
console.log('\nDelete complete.')
29-
})
30-
} else {
31-
console.log('\nDelete cancelled.')
32-
}
33-
})
34-
35-
else {
36-
rl.close();
27+
return exec(`zsh -li <(echo "${logGroups}")`, { shell: '/bin/zsh' })
28+
.then(() => {
29+
console.log('\nDelete complete.')
30+
})
31+
} else {
32+
console.log('\nDelete cancelled.')
33+
}
34+
})
35+
} else {
36+
rl.close()
3737
console.log(`No Log Groups that match ${filter}`)
3838
}
3939
})

dev-portal/scripts/deploy-stack.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const writeConfig = require('./write-config.js')
88

99
const errors = []
1010

11-
function getRequired(key) {
11+
function getRequired (key) {
1212
const value = deployerConfig[key]
1313
if (value) return value
1414
errors.push(key + ' must be defined')
1515
}
1616

17-
function getOptional(key, orElse) {
17+
function getOptional (key, orElse) {
1818
return deployerConfig[key] || orElse
1919
}
2020

@@ -26,17 +26,18 @@ const apiAssetsBucket = getRequired('apiAssetsBucket')
2626
const cognitoDomainName = getRequired('cognitoDomainName')
2727

2828
// required (and defaulted) inputs
29-
const samTemplate = getOptional('samTemplate', r(`../../cloudformation/template.yaml`))
30-
const packageConfig = getOptional('packageConfig', r(`../../cloudformation/packaged.yaml`))
29+
const samTemplate = getOptional('samTemplate', r('../../cloudformation/template.yaml'))
30+
const packageConfig = getOptional('packageConfig', r('../../cloudformation/packaged.yaml'))
3131
const customersTableName = getOptional('customersTableName', 'DevPortalCustomers')
3232

3333
// optional inputs
3434
const staticAssetRebuildMode = getOptional('staticAssetRebuildMode', '')
35+
const developmentMode = getOptional('developmentMode')
3536

3637
// AWS SAM CLI configuration
3738
const awsSamCliProfile = getOptional('awsSamCliProfile')
3839

39-
async function main() {
40+
async function main () {
4041
execute('sam', [
4142
'package',
4243
'--template-file', samTemplate,
@@ -55,6 +56,7 @@ async function main() {
5556
`DevPortalSiteS3BucketName=${siteAssetsBucket}`,
5657
`ArtifactsS3BucketName=${apiAssetsBucket}`,
5758
`DevPortalCustomersTableName=${customersTableName}`,
59+
...(developmentMode ? [`DevelopmentMode=${developmentMode}`] : []),
5860
`CognitoDomainNameOrPrefix=${cognitoDomainName}`,
5961
'--s3-bucket', buildAssetsBucket,
6062
...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : [])

dev-portal/scripts/dump-v3-account-data.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const { execute } = require('./utils.js')
1313

1414
const fetchLambdaOutput = async ({ stackName, workDir }) => {
1515
const resourceData = JSON.parse((await execute(
16-
`aws cloudformation describe-stack-resource`
17-
+ ` --logical-resource-id DumpV3AccountDataFn`
18-
+ ` --stack-name ${stackName}`, true)).stdout)
16+
'aws cloudformation describe-stack-resource' +
17+
' --logical-resource-id DumpV3AccountDataFn' +
18+
` --stack-name ${stackName}`, true)).stdout)
1919
const lambdaId = resourceData.StackResourceDetail.PhysicalResourceId
2020
const outFile = `${workDir}${path.sep}lambdaOut`
2121
await execute(
@@ -27,7 +27,7 @@ const fetchLambdaOutput = async ({ stackName, workDir }) => {
2727

2828
const main = async () => {
2929
if (process.argv.length !== 4) {
30-
const [ node, script ] = process.argv
30+
const [node, script] = process.argv
3131
console.error(`Usage: ${node} ${script} STACK_NAME OUTPUT_FILE`)
3232
process.exitCode = 127
3333
return
@@ -52,7 +52,7 @@ const main = async () => {
5252
throw new Error(`Failed to write to ${outFile}: ${error.message}`)
5353
}
5454

55-
console.log(`Done.`)
55+
console.log('Done.')
5656
}
5757

5858
if (!module.parent) {

0 commit comments

Comments
 (0)