Skip to content

Commit 2f5fe54

Browse files
authored
Reformat templates using prettier (#64)
* Reformat templates using prettier * Add prettier config * Reformat witch
1 parent 99e9cad commit 2f5fe54

File tree

7 files changed

+103
-95
lines changed

7 files changed

+103
-95
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ repos:
3030
name: AWS CloudFormation Linter
3131
files: \.(template)$
3232
args: [--ignore-checks=W3002]
33+
34+
- repo: https://github.com/pre-commit/mirrors-prettier
35+
rev: v3.0.1
36+
hooks:
37+
- id: prettier

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false,
4+
"singleQuote": true
5+
}

source/witch/witch.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const aws = require("aws-sdk");
2-
const fs = require("fs");
3-
const path = require("path");
4-
const mime = require("mime-types");
5-
const https = require("https");
6-
const url = require("url");
1+
const aws = require('aws-sdk');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const mime = require('mime-types');
5+
const https = require('https');
6+
const url = require('url');
77

88
const s3 = new aws.S3();
99

10-
const SUCCESS = "SUCCESS";
11-
const FAILED = "FAILED";
10+
const SUCCESS = 'SUCCESS';
11+
const FAILED = 'FAILED';
1212

1313
const { BUCKET } = process.env;
1414

1515
exports.staticHandler = function (event, context) {
16-
if (event.RequestType !== "Create" && event.RequestType !== "Update") {
16+
if (event.RequestType !== 'Create' && event.RequestType !== 'Update') {
1717
return respond(event, context, SUCCESS, {});
1818
}
1919

2020
Promise.all(
21-
walkSync("./").map((file) => {
22-
const fileType = mime.lookup(file) || "application/octet-stream";
21+
walkSync('./').map((file) => {
22+
const fileType = mime.lookup(file) || 'application/octet-stream';
2323

2424
console.log(`${file} -> ${fileType}`);
2525

@@ -29,10 +29,10 @@ exports.staticHandler = function (event, context) {
2929
Bucket: BUCKET,
3030
ContentType: fileType,
3131
Key: file,
32-
ACL: "private",
32+
ACL: 'private',
3333
})
3434
.promise();
35-
})
35+
}),
3636
)
3737
.then((msg) => {
3838
respond(event, context, SUCCESS, {});
@@ -63,12 +63,12 @@ function respond(
6363
responseStatus,
6464
responseData,
6565
physicalResourceId,
66-
noEcho
66+
noEcho,
6767
) {
6868
const responseBody = JSON.stringify({
6969
Status: responseStatus,
7070
Reason:
71-
"See the details in CloudWatch Log Stream: " + context.logStreamName,
71+
'See the details in CloudWatch Log Stream: ' + context.logStreamName,
7272
PhysicalResourceId: physicalResourceId || context.logStreamName,
7373
StackId: event.StackId,
7474
RequestId: event.RequestId,
@@ -77,28 +77,28 @@ function respond(
7777
Data: responseData,
7878
});
7979

80-
console.log("Response body:\n", responseBody);
80+
console.log('Response body:\n', responseBody);
8181

8282
const { pathname, hostname, search } = new url.URL(event.ResponseURL);
8383
const options = {
8484
hostname,
8585
port: 443,
8686
path: pathname + search,
87-
method: "PUT",
87+
method: 'PUT',
8888
headers: {
89-
"content-type": "",
90-
"content-length": responseBody.length,
89+
'content-type': '',
90+
'content-length': responseBody.length,
9191
},
9292
};
9393

9494
const request = https.request(options, function (response) {
95-
console.log("Status code: " + response.statusCode);
96-
console.log("Status message: " + response.statusMessage);
95+
console.log('Status code: ' + response.statusCode);
96+
console.log('Status message: ' + response.statusMessage);
9797
context.done();
9898
});
9999

100-
request.on("error", function (error) {
101-
console.log("send(..) failed executing https.request(..): " + error);
100+
request.on('error', function (error) {
101+
console.log('send(..) failed executing https.request(..): ' + error);
102102
context.done();
103103
});
104104

templates/acm-certificate.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Parameters:
1212
Type: String
1313

1414
Conditions:
15-
CreateApexConfig: !Equals
15+
CreateApexConfig: !Equals
1616
- !Ref CreateApex
1717
- 'yes'
1818

@@ -30,10 +30,10 @@ Resources:
3030
- DomainName: !Sub '${SubDomain}.${DomainName}'
3131
HostedZoneId: !Ref HostedZoneId
3232
- Fn::If:
33-
- CreateApexConfig
34-
- DomainName: !Ref DomainName
35-
HostedZoneId: !Ref HostedZoneId
36-
- Ref: AWS::NoValue
33+
- CreateApexConfig
34+
- DomainName: !Ref DomainName
35+
HostedZoneId: !Ref HostedZoneId
36+
- Ref: AWS::NoValue
3737
ValidationMethod: DNS
3838

3939
Outputs:

templates/cloudfront-site.yaml

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Parameters:
2727
S3BucketRootArn:
2828
Description: Content Bucket locator
2929
Type: String
30-
CreateApex:
30+
CreateApex:
3131
Type: String
3232

3333
Conditions:
34-
CreateApexConfig: !Equals
34+
CreateApexConfig: !Equals
3535
- !Ref CreateApex
3636
- 'yes'
3737

@@ -56,7 +56,7 @@ Resources:
5656
DistributionConfig:
5757
Aliases:
5858
- !Sub '${SubDomain}.${DomainName}'
59-
- !If [ CreateApexConfig, !Ref DomainName, !Ref 'AWS::NoValue' ]
59+
- !If [CreateApexConfig, !Ref DomainName, !Ref 'AWS::NoValue']
6060
DefaultCacheBehavior:
6161
Compress: true
6262
DefaultTTL: 86400
@@ -87,8 +87,7 @@ Resources:
8787
- DomainName: !Ref 'S3BucketRootName'
8888
Id: !Sub 'S3-${AWS::StackName}-root'
8989
S3OriginConfig:
90-
OriginAccessIdentity:
91-
!Join ['', ['origin-access-identity/cloudfront/', !Ref CloudFrontOriginAccessIdentity]]
90+
OriginAccessIdentity: !Sub 'origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}'
9291
PriceClass: 'PriceClass_All'
9392
ViewerCertificate:
9493
AcmCertificateArn: !Ref 'CertificateArn'
@@ -103,60 +102,60 @@ Resources:
103102
Properties:
104103
CloudFrontOriginAccessIdentityConfig:
105104
Comment: !Sub 'CloudFront OAI for ${SubDomain}.${DomainName}'
106-
105+
107106
Route53RecordSetGroup:
108107
Type: AWS::Route53::RecordSetGroup
109108
Properties:
110109
HostedZoneName: !Sub '${DomainName}.'
111110
RecordSets:
112-
- Name: !Sub '${SubDomain}.${DomainName}'
113-
Type: 'A'
114-
AliasTarget:
115-
DNSName: !GetAtt 'CloudFrontDistribution.DomainName'
116-
EvaluateTargetHealth: false
117-
# The following HosteZoneId is always used for alias records pointing to CF.
118-
HostedZoneId: 'Z2FDTNDATAQYW2'
111+
- Name: !Sub '${SubDomain}.${DomainName}'
112+
Type: 'A'
113+
AliasTarget:
114+
DNSName: !GetAtt 'CloudFrontDistribution.DomainName'
115+
EvaluateTargetHealth: false
116+
# The following HosteZoneId is always used for alias records pointing to CF.
117+
HostedZoneId: 'Z2FDTNDATAQYW2'
119118

120119
ApexRoute53RecordSetGroup:
121120
Condition: CreateApexConfig
122121
Type: AWS::Route53::RecordSetGroup
123122
Properties:
124123
HostedZoneName: !Sub '${DomainName}.'
125124
RecordSets:
126-
- Name: !Ref 'DomainName'
127-
Type: 'A'
128-
AliasTarget:
129-
DNSName: !GetAtt 'CloudFrontDistribution.DomainName'
130-
EvaluateTargetHealth: false
131-
# The following HosteZoneId is always used for alias records pointing to CF.
132-
HostedZoneId: 'Z2FDTNDATAQYW2'
125+
- Name: !Ref 'DomainName'
126+
Type: 'A'
127+
AliasTarget:
128+
DNSName: !GetAtt 'CloudFrontDistribution.DomainName'
129+
EvaluateTargetHealth: false
130+
# The following HosteZoneId is always used for alias records pointing to CF.
131+
HostedZoneId: 'Z2FDTNDATAQYW2'
133132

134133
ResponseHeadersPolicy:
135-
Type: AWS::CloudFront::ResponseHeadersPolicy
136-
Properties:
137-
ResponseHeadersPolicyConfig:
138-
Name: !Sub "${AWS::StackName}-static-site-security-headers"
139-
SecurityHeadersConfig:
140-
StrictTransportSecurity:
141-
AccessControlMaxAgeSec: 63072000
142-
IncludeSubdomains: true
143-
Override: true
144-
Preload: true
145-
ContentSecurityPolicy:
146-
ContentSecurityPolicy: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"
147-
Override: true
148-
ContentTypeOptions:
149-
Override: true
150-
FrameOptions:
151-
FrameOption: DENY
152-
Override: true
153-
ReferrerPolicy:
154-
ReferrerPolicy: "same-origin"
155-
Override: true
156-
XSSProtection:
157-
ModeBlock: true
158-
Override: true
159-
Protection: true
134+
Type: AWS::CloudFront::ResponseHeadersPolicy
135+
Properties:
136+
ResponseHeadersPolicyConfig:
137+
Name: !Sub '${AWS::StackName}-static-site-security-headers'
138+
SecurityHeadersConfig:
139+
StrictTransportSecurity:
140+
AccessControlMaxAgeSec: 63072000
141+
IncludeSubdomains: true
142+
Override: true
143+
Preload: true
144+
ContentSecurityPolicy:
145+
ContentSecurityPolicy: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"
146+
Override: true
147+
ContentTypeOptions:
148+
Override: true
149+
FrameOptions:
150+
FrameOption: DENY
151+
Override: true
152+
ReferrerPolicy:
153+
ReferrerPolicy: 'same-origin'
154+
Override: true
155+
XSSProtection:
156+
ModeBlock: true
157+
Override: true
158+
Protection: true
160159

161160
Outputs:
162161
CloudFrontDistribution:

templates/custom-resource.yaml

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ Description: ACFS3 - Cert Provider with DNS validation
33
Transform: AWS::Serverless-2016-10-31
44

55
Resources:
6-
76
CopyCustomResource:
8-
Type: "AWS::CloudFormation::CustomResource"
7+
Type: 'AWS::CloudFormation::CustomResource'
98
Properties:
109
ServiceToken: !GetAtt CopyFunction.Arn
1110

@@ -40,14 +39,14 @@ Resources:
4039
Value: ACFS3
4140

4241
CopyLayerVersion:
43-
Type: "AWS::Serverless::LayerVersion"
42+
Type: 'AWS::Serverless::LayerVersion'
4443
Properties:
4544
ContentUri: ../witch.zip
4645
CompatibleRuntimes:
4746
- nodejs16.x
4847

4948
CopyRole:
50-
Type: "AWS::IAM::Role"
49+
Type: 'AWS::IAM::Role'
5150
Properties:
5251
AssumeRolePolicyDocument:
5352
Statement:
@@ -59,23 +58,23 @@ Resources:
5958
ManagedPolicyArns:
6059
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
6160
Policies:
62-
- PolicyName: S3CopyPolicy
63-
PolicyDocument:
64-
Version: '2012-10-17'
65-
Statement:
66-
- Effect: Allow
67-
Action:
68-
- s3:GetObject
69-
- s3:ListBucket
70-
- s3:PutObject
71-
- s3:PutObjectAcl
72-
Resource:
73-
- !Sub
74-
- arn:aws:s3:::${TargetBucket}/*
75-
- TargetBucket: !Ref S3BucketRoot
76-
- !Sub
77-
- arn:aws:s3:::${TargetBucket}
78-
- TargetBucket: !Ref S3BucketRoot
61+
- PolicyName: S3CopyPolicy
62+
PolicyDocument:
63+
Version: '2012-10-17'
64+
Statement:
65+
- Effect: Allow
66+
Action:
67+
- s3:GetObject
68+
- s3:ListBucket
69+
- s3:PutObject
70+
- s3:PutObjectAcl
71+
Resource:
72+
- !Sub
73+
- arn:aws:s3:::${TargetBucket}/*
74+
- TargetBucket: !Ref S3BucketRoot
75+
- !Sub
76+
- arn:aws:s3:::${TargetBucket}
77+
- TargetBucket: !Ref S3BucketRoot
7978

8079
CopyFunction:
8180
Type: AWS::Serverless::Function

templates/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Parameters:
4242
Description: Create an Apex Alias in CloudFront distribution - yes/no
4343
Type: String
4444
Default: 'no'
45-
AllowedValues: ['yes','no']
45+
AllowedValues: ['yes', 'no']
4646

4747
Resources:
4848
CustomResourceStack:

0 commit comments

Comments
 (0)