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 1 commit
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
58 changes: 23 additions & 35 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ServerlessCustomDomain {
this.serverless.cli.log("serverless-domain-manager: Custom domain is disabled.");
return;
} else {
await lifecycleFunc();
return await lifecycleFunc.call(this);
}
}

Expand All @@ -84,73 +84,58 @@ class ServerlessCustomDomain {
* Wraps creating a domain and resource record set
*/
public async createDomain(): Promise<boolean> {
try {
const certArn = await this.getCertArn();
const domainInfo = await this.createCustomDomain(certArn);
await this.changeResourceRecordSet("UPSERT", domainInfo);
this.serverless.cli.log(`Custom domain ${this.givenDomainName} was created/updated.
New domains may take up to 40 minutes to be initialized.`);
return true;
} catch (error) {
return false;
}
const certArn = await this.getCertArn();
const domainInfo = await this.createCustomDomain(certArn);
await this.changeResourceRecordSet("UPSERT", domainInfo);
this.serverless.cli.log(
`Custom domain ${this.givenDomainName} was created/updated.
New domains may take up to 40 minutes to be initialized.`,
);
return true;
captainsidd marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Lifecycle function to delete a domain
* Wraps deleting a domain and resource record set
*/
public async deleteDomain(): Promise<boolean> {
try {
const domainInfo = await this.getDomainInfo();
const domainInfo = await this.getDomainInfo();
if (domainInfo) {
await this.deleteCustomDomain();
await this.changeResourceRecordSet("DELETE", domainInfo);
this.serverless.cli.log(`Custom domain ${this.givenDomainName} was deleted.`);
return true;
} catch (error) {
return false;
}
return false;
}

/**
* Lifecycle function to create basepath mapping
* Wraps creation of basepath mapping and adds domain name info as output to cloudformation stack
*/
public async setupBasePathMapping(): Promise<boolean> {
try {
const basePathCreated = await this.createBasePathMapping();
const domainInfo = await this.getDomainInfo();
this.addOutputs(domainInfo);
await this.printDomainSummary(domainInfo);
return basePathCreated ? true : false;
} catch (error) {
return false;
}
const basePathCreated = await this.createBasePathMapping();
const domainInfo = await this.getDomainInfo();
this.addOutputs(domainInfo);
await this.printDomainSummary(domainInfo);
return basePathCreated ? true : false;
}

/**
* Lifecycle function to delete basepath mapping
* Wraps deletion of basepath mapping
*/
public async removeBasePathMapping(): Promise<boolean> {
try {
return await this.deleteBasePathMapping();
} catch (error) {
return false;
}
return await this.deleteBasePathMapping();
}

/**
* Lifecycle function to print domain summary
* Wraps printing of all domain manager related info
*/
public async domainSummary(): Promise<boolean> {
try {
const domainInfo = await this.getDomainInfo();
return this.printDomainSummary(domainInfo);
} catch (error) {
return false;
}
const domainInfo = await this.getDomainInfo();
return this.printDomainSummary(domainInfo);
}

/**
Expand Down Expand Up @@ -287,6 +272,9 @@ class ServerlessCustomDomain {
domainInfo = await this.apigateway.getDomainName({ domainName: this.givenDomainName }).promise();
return new DomainResponse(domainInfo);
} catch (err) {
if (err.code === "NotFoundException") {
return null;
}
throw new Error(`Error: Unable to fetch information about ${this.givenDomainName}`);
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/unit-tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ describe("Custom Domain Plugin", () => {
it("createDomain should do nothing when domain manager is disabled", async () => {
const plugin = constructPlugin({ enabled: false });

const result = await plugin.hookWrapper(plugin.createDomain());
const result = await plugin.hookWrapper(plugin.createDomain);

expect(plugin.initialized).to.equal(true);
expect(plugin.enabled).to.equal(false);
Expand All @@ -876,7 +876,7 @@ describe("Custom Domain Plugin", () => {
it("deleteDomain should do nothing when domain manager is disabled", async () => {
const plugin = constructPlugin({ enabled: false });

const result = await plugin.hookWrapper(plugin.deleteDomain());
const result = await plugin.hookWrapper(plugin.deleteDomain);

expect(plugin.initialized).to.equal(true);
expect(plugin.enabled).to.equal(false);
Expand All @@ -886,7 +886,7 @@ describe("Custom Domain Plugin", () => {
it("setUpBasePathMapping should do nothing when domain manager is disabled", async () => {
const plugin = constructPlugin({ enabled: false });

const result = await plugin.hookWrapper(plugin.setupBasePathMapping());
const result = await plugin.hookWrapper(plugin.setupBasePathMapping);

expect(plugin.initialized).to.equal(true);
expect(plugin.enabled).to.equal(false);
Expand All @@ -896,7 +896,7 @@ describe("Custom Domain Plugin", () => {
it("removeBasePathMapping should do nothing when domain manager is disabled", async () => {
const plugin = constructPlugin({ enabled: false });

const result = await plugin.hookWrapper(plugin.removeBasePathMapping());
const result = await plugin.hookWrapper(plugin.removeBasePathMapping);

expect(plugin.initialized).to.equal(true);
expect(plugin.enabled).to.equal(false);
Expand All @@ -906,7 +906,7 @@ describe("Custom Domain Plugin", () => {
it("domainSummary should do nothing when domain manager is disabled", async () => {
const plugin = constructPlugin({ enabled: false });

const result = await plugin.hookWrapper(plugin.domainSummary());
const result = await plugin.hookWrapper(plugin.domainSummary);

expect(plugin.initialized).to.equal(true);
expect(plugin.enabled).to.equal(false);
Expand Down