From a33090bb5ec4db614593f3fa9523eaa2b00510e2 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 17 Jan 2019 01:15:22 +0100 Subject: [PATCH] fix(core): update --- package-lock.json | 8 ++++---- package.json | 2 +- ts/smartacme.classes.certmanager.ts | 5 ++++- ts/smartacme.classes.certremoteclient.ts | 8 +++++--- ts/smartacme.classes.smartacme.ts | 22 ++++++++++++++-------- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index be0d1b0..60771bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -206,11 +206,11 @@ } }, "@pushrocks/smartlog": { - "version": "2.0.10", - "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.10.tgz", - "integrity": "sha512-4Ir4/JvfL+d5VsN+O8BpFSgUc1mWgr9s6S/cwYBCAIrWdqGomUM5RsZs57RMDn9MWW0JGJjGhUA0M+A8LSSgHw==", + "version": "2.0.11", + "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.11.tgz", + "integrity": "sha512-V8SMzAAqDpl1+CJ9b3w5e/1ARjk4JOPZ35qZIllVBhHr8meCqnPE2immlfBYWmEp1xy3ntdAA+Lgewtu+iVk6A==", "requires": { - "@pushrocks/smartlog-interfaces": "^2.0.2" + "@pushrocks/smartlog-interfaces": "^2.0.5" } }, "@pushrocks/smartlog-interfaces": { diff --git a/package.json b/package.json index dd0c673..186478e 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdns": "^3.0.8", "@pushrocks/smartexpress": "^3.0.6", - "@pushrocks/smartlog": "^2.0.10", + "@pushrocks/smartlog": "^2.0.11", "@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartrequest": "^1.1.14", "@pushrocks/smartstring": "^3.0.8", diff --git a/ts/smartacme.classes.certmanager.ts b/ts/smartacme.classes.certmanager.ts index 5b25b12..2c09b48 100644 --- a/ts/smartacme.classes.certmanager.ts +++ b/ts/smartacme.classes.certmanager.ts @@ -62,6 +62,7 @@ export class CertManager { public async storeCertificate(optionsArg: interfaces.ICert) { const cert = new Cert(optionsArg); await cert.save(); + this.pendingMap.removeString(optionsArg.domainName); } public async deleteCertificate(domainNameArg: string) { @@ -97,5 +98,7 @@ export class CertManager { /** * checks all certs for expiration */ - private async checkCerts() {}; + private async checkCerts() { + // TODO + }; } diff --git a/ts/smartacme.classes.certremoteclient.ts b/ts/smartacme.classes.certremoteclient.ts index 085d744..7900b7d 100644 --- a/ts/smartacme.classes.certremoteclient.ts +++ b/ts/smartacme.classes.certremoteclient.ts @@ -26,7 +26,7 @@ export class CertRemoteClient { public async getCertificateForDomain(domainNameArg: string): Promise { let certificate: interfaces.ICert; const doRequestCycle = async (): Promise => { - const response: interfaces.ICertRemoteResponse = (await plugins.smartrequest.postJson( + const responseBody: interfaces.ICertRemoteResponse = (await plugins.smartrequest.postJson( this.remoteUrl, { requestBody: { @@ -35,13 +35,15 @@ export class CertRemoteClient { } } )).body; - switch (response.status as interfaces.TCertStatus) { + console.log(responseBody); + switch (responseBody.status as interfaces.TCertStatus) { case 'pending': await plugins.smartdelay.delayFor(5000); const finalResponse = await doRequestCycle(); return finalResponse; case 'existing': - return response.certificate; + this.logger.log('ok', `got certificate for ${domainNameArg}`); + return responseBody.certificate; case 'failed': default: console.log(`could not retrieve certificate for ${domainNameArg}`); diff --git a/ts/smartacme.classes.smartacme.ts b/ts/smartacme.classes.smartacme.ts index 3c2072d..3da7998 100644 --- a/ts/smartacme.classes.smartacme.ts +++ b/ts/smartacme.classes.smartacme.ts @@ -16,6 +16,7 @@ export interface ISmartAcmeOptions { setChallenge: (domainName: string, keyAuthorization: string) => Promise; removeChallenge: (domainName: string) => Promise; environment: 'production' | 'integration'; + logger?: plugins.smartlog.Smartlog; } /** @@ -34,6 +35,7 @@ export class SmartAcme { // the acme client private client: any; private smartdns = new plugins.smartdns.Smartdns(); + public logger: plugins.smartlog.Smartlog; // the account private key private privateKey: string; @@ -49,15 +51,19 @@ export class SmartAcme { /** * the remote handler to hand the request and response to. */ - public certremoteHandler = async (req: plugins.smartexpress.Request, res: plugins.smartexpress.Response) => { + public certremoteHandler = async ( + req: plugins.smartexpress.Request, + res: plugins.smartexpress.Response + ) => { const requestBody: interfaces.ICertRemoteRequest = req.body; - const certDomain = this.certmatcher.getCertificateDomainNameByDomainName(requestBody.domainName); - let status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus( - certDomain + const certDomain = this.certmatcher.getCertificateDomainNameByDomainName( + requestBody.domainName ); + let status: interfaces.TCertStatus = await this.certmanager.getCertificateStatus(certDomain); let response: interfaces.ICertRemoteResponse; switch (status) { case 'existing': + this.logger.log('ok', `certificate exists for ${certDomain}. Sending certificate!`); response = { status, certificate: await (await this.certmanager.retrieveCertificate( @@ -66,7 +72,7 @@ export class SmartAcme { }; break; default: - if (status === "nonexisting") { + if (status === 'nonexisting') { this.getCertificateForDomain(certDomain); status = 'pending'; } @@ -82,6 +88,9 @@ export class SmartAcme { constructor(optionsArg: ISmartAcmeOptions) { this.options = optionsArg; + this.options.logger + ? (this.logger = optionsArg.logger) + : (this.logger = plugins.smartlog.defaultLogger); } /** @@ -189,9 +198,6 @@ export class SmartAcme { const cert = await this.client.getCertificate(order); /* Done */ - console.log(`CSR:\n${csr.toString()}`); - console.log(`Private key:\n${key.toString()}`); - console.log(`Certificate:\n${cert.toString()}`); await this.certmanager.storeCertificate({ id: plugins.smartunique.shortId(),