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

Refactor #181

Merged
merged 55 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a8706bd
add typescript files
Jan 16, 2019
5299537
add tsconfig and package.json
Jan 16, 2019
752071e
version bump
Jan 16, 2019
26a9fef
add tslint, fix most tslint errors
Jan 17, 2019
1746bdb
separate out classes, start using await
Jan 17, 2019
8240e5d
incorporate new hostedZoneId algo
Jan 22, 2019
83ade14
add tslint
Jan 22, 2019
59edeaf
include js files
Jan 22, 2019
99ef9a3
ignore generated files
Jan 23, 2019
a5ebe0c
rm js files
Jan 23, 2019
33c7179
fixes from writing unit tests
Jan 23, 2019
b0b5291
add converted unit tests, fixes
Jan 23, 2019
5ef305f
make async
Jan 23, 2019
97c5a74
good code coverage
Jan 24, 2019
77b4773
remove console log
Jan 24, 2019
2e7fc56
Merge branch 'ts-refactor'
Jan 24, 2019
23726f1
rm js files
Jan 24, 2019
3359d67
rm extra lines
Jan 24, 2019
608ce18
Merge branch 'master' into ts-refactor
Jan 24, 2019
374c573
lint tests as well
Jan 24, 2019
ecaf55b
updated README
Jan 24, 2019
bf3b773
CHANGELOG
Jan 24, 2019
ef41f39
fix lint command
Jan 24, 2019
e762040
add api gateway to types, unit tests to check if rest api id is fetch…
Jan 25, 2019
f633c20
fix lint command on travis
Jan 25, 2019
ef5eaaa
lint current dir
Jan 25, 2019
207f463
multiple tslint files
Jan 25, 2019
b3ae5be
fix path?
Jan 25, 2019
dc8a0a6
fix path? works on my machine
Jan 25, 2019
a982022
reverting
Jan 25, 2019
ab75653
update integration tests
Jan 26, 2019
8ef1717
merge conficts
Jan 26, 2019
fdf532b
update lambda permissions in readme (closes #164)
Jan 28, 2019
002daff
turn single quotes to double quotes for codacy
Jan 28, 2019
71c95d7
integrate documentation fix for #112
Jan 28, 2019
bb52e1f
refactor how initialization/enable checks work
Jan 29, 2019
301d10a
CNAME/A Alias migration info
Jan 29, 2019
24906f5
make delete domain idempotent, fix function binding issue
Jan 29, 2019
b6d0d39
rework how delete/create domain are tested
Jan 29, 2019
6bf52af
npm publish commands
Jan 29, 2019
1d2c589
remove unnecessary returns
Jan 29, 2019
95e7845
clean up return types
Jan 29, 2019
4b79969
fix unit tests
Jan 29, 2019
f1772dc
fix summary printing test
Jan 29, 2019
1316d8d
more summary checking
Jan 29, 2019
06b7806
ignore all js files
Feb 1, 2019
315a1be
add newline
Feb 1, 2019
0ce9869
remove this.initialized
Feb 2, 2019
5fd462b
rename DomainResponse to DomainInfo
Feb 2, 2019
3a2c58f
suggested change
Feb 2, 2019
d06dc96
fix unit tests
Feb 2, 2019
bba41d5
output js files to dist/
Feb 4, 2019
3797bb5
make travis build before deploying
Feb 4, 2019
f5ada8c
lint unit tests
Feb 4, 2019
7b388e6
revert weird lint error
Feb 4, 2019
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
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ npm-debug.log
.DS_Store
*.iml
**/.serverless
dist/
.nyc_output/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ deploy:
provider: npm
email: $NPM_EMAIL
api_key: $NPM_KEY
before_deploy: "npm run build"
on:
branch: master
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.0.0] - 2019-01-24

### Changed
- Refactored from Javascript into Typescript
- Created BasePathMapping through API rather than through CloudFormation

### Removed
- Support for migrating CNAMEs to A Alias Records
captainsidd marked this conversation as resolved.
Show resolved Hide resolved
- In 1.0, we only created CNAME records. In 2.0 we deprecated CNAME creation and started creating A Alias records and migrated CNAME records to A Alias records. Now in 3.0, we only create A Alias records.


## [2.6.13] - 2019-01-25

### Added
Expand Down
26 changes: 26 additions & 0 deletions DomainInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Wrapper class for Custom Domain information
*/
class DomainInfo {

public domainName: string;
public hostedZoneId: string;

/**
* Sometimes, the getDomainName call doesn't return either a distributionHostedZoneId or a regionalHostedZoneId.
* AFAICT, this only happens with edge-optimized endpoints.
* The hostedZoneId for these endpoints is always the one below.
* Docs: https://docs.aws.amazon.com/general/latest/gr/rande.html#apigateway_region
* PR: https://github.com/amplify-education/serverless-domain-manager/pull/171
*/
private defaultHostedZoneId: string = "Z2FDTNDATAQYW2";

constructor(data: any) {
this.domainName = data.distributionDomainName || data.regionalDomainName;
this.hostedZoneId = data.distributionHostedZoneId ||
data.regionalHostedZoneId ||
this.defaultHostedZoneId;
}
}

export = DomainInfo;
22 changes: 0 additions & 22 deletions DomainResponse.js

This file was deleted.

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ apigateway:POST /domainnames/*/basepathmappings
cloudfront:UpdateDistribution *
route53:ListHostedZones *
route53:ChangeResourceRecordSets hostedzone/{HostedZoneId}
route53:GetHostedZone hostedzone/{HostedZoneId}
route53:ListResourceRecordSets hostedzone/{HostedZoneId}
route53:GetHostedZone *
route53:ListResourceRecordSets *
iam:CreateServiceLinkedRole arn:aws:iam::${AWS::AccountId}: role/aws-service-role/ops.apigateway.amazonaws.com/AWSServiceRoleForAPIGateway
```
### CloudFormation
Alternatively you can generate an least privileged IAM Managed Policy for deployment with this:
Expand Down Expand Up @@ -97,15 +98,17 @@ To remove the created custom domain:
serverless delete_domain
```
# How it works
Creating the custom domain takes advantage of Amazon's Certificate Manager to assign a certificate to the given domain name. Based on already created certificate names, the plugin will search for the certificate that resembles the custom domain's name the most and assign the ARN to that domain name. The plugin then creates the proper A Alias records for the domain through Route 53. Once the domain name is set it takes up to 40 minutes before it is initialized. After the certificate is initialized, `sls deploy` will create the base path mapping and assign the lambda to the custom domain name through CloudFront.
Creating the custom domain takes advantage of Amazon's Certificate Manager to assign a certificate to the given domain name. Based on already created certificate names, the plugin will search for the certificate that resembles the custom domain's name the most and assign the ARN to that domain name. The plugin then creates the proper A Alias records for the domain through Route 53. Once the domain name is set it takes up to 40 minutes before it is initialized. After the certificate is initialized, `sls deploy` will create the base path mapping and assign the lambda to the custom domain name through CloudFront. All resources are created independent of CloudFormation.

Note: In 1.0, we only created CNAME records. In 2.0 we deprecated CNAME creation and started creating A Alias records and migrated CNAME records to A Alias records. Now in 3.0, we only create A Alias records.

## Running Tests
To run unit tests:
```
npm test
```

To run integration tests, set an environment variable `TEST_DOMAIN` to the domain you will be testing for (i.e. `example.com` if creating a domain for `api.example.com`). Then,
To run integration tests, set an environment variable `TEST_DOMAIN` to the domain you will be testing for (i.e. `example.com` if creating a domain for `api.example.com`). Then,
```
export TEST_DOMAIN=example.com
npm run integration-test
Expand All @@ -126,7 +129,6 @@ Unit tests are found in `test/unit-tests`. Integration tests are found in `test/
* (5/23/2017) CloudFormation does not support changing the base path from empty to something or vice a versa. You must run `sls remove` to remove the base path mapping.
* (1/17/2018) The `create_domain` command provided by this plugin does not currently update an existing Custom Domain's configuration. Instead, it only supports updating the Route 53 record pointing to the Custom Domain. For example, one must delete and recreate a Custom Domain to migrate it from regional to edge or vice versa, or to modify the certificate.
* (8/22/2018) Creating a custom domain creates a CloudFront Distribution behind the scenes for fronting your API Gateway. This CloudFront Distribution is managed by AWS and cannot be viewed/managed by you. This is not a bug, but a quirk of how the Custom Domain feature works in API Gateway.
* (12/19/2018) Recreating a custom domain after deleting it does not work if the basePathMapping is not set. The workaround is to always run `sls remove` when running `sls delete_domain`.

# Responsible Disclosure
If you have any security issue to report, contact project maintainers privately.
Expand Down
Loading