Compare commits
No commits in common. "master" and "v0.0.3" have entirely different histories.
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,9 +1,3 @@
|
|||||||
node_modules/
|
node_modules
|
||||||
assets/
|
|
||||||
docs/
|
docs/
|
||||||
public/
|
coverage/
|
||||||
pages/
|
|
||||||
coverage/
|
|
||||||
.nogit/
|
|
||||||
dist/assets/
|
|
||||||
test/assets/
|
|
@ -1,29 +1,29 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
image: hosttoday/ht-docker-node:npmts
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test1
|
- test
|
||||||
- test2
|
|
||||||
- release
|
- release
|
||||||
|
|
||||||
before_script:
|
testLEGACY:
|
||||||
- npmci prepare ssh
|
stage: test
|
||||||
|
script:
|
||||||
|
- npmci test legacy
|
||||||
|
tags:
|
||||||
|
- docker
|
||||||
|
- lossless
|
||||||
|
|
||||||
testLTS:
|
testLTS:
|
||||||
stage: test1
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci test lts
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- lossless
|
- lossless
|
||||||
|
|
||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test2
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci test stable
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- lossless
|
- lossless
|
||||||
|
47
README.md
47
README.md
@ -1,51 +1,16 @@
|
|||||||
# Cert
|
# Cert
|
||||||
Easily obain SSL certificates from LetsEncrypt. Supports DNS-01 challenge. TypeScript ready.
|
Easily obain SSL certificates from LetsEncrypt. Supports DNS-01 challenge. TypeScript ready.
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
[](https://www.npmjs.com/package/cert)
|
|
||||||
[](https://gitlab.com/pushrocks/cert)
|
|
||||||
[](https://github.com/pushrocks/cert)
|
|
||||||
[](https://pushrocks.gitlab.io/cert/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/cert/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/cert/commits/master)
|
|
||||||
[](https://david-dm.org/pushrocks/cert)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/cert/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/cert)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import {Cert} from "cert";
|
import {Cert} from "cert";
|
||||||
|
|
||||||
let myCert = new Cert({
|
myCert = new Cert({
|
||||||
cfEmail: "some@cloudflare.email",
|
cfEmail = "some@cloudflare.email",
|
||||||
cfKey: "someCloudflareApiKey",
|
cfKey = "someCloudflareApiKey",
|
||||||
sslDir: "someOutputPath", // NOTE: if you already have certificates, make sure you put them in here, so cert only requires the missing ones
|
outputPath = "someOutputPath" // NOTE: if you already have certificates, make sure you put them in here, so cert only requires the missing ones
|
||||||
gitOriginRepo: "git@githhub.com/someuser/somereopo" // good for persistence in highly volatile environments like docker
|
|
||||||
});
|
});
|
||||||
|
|
||||||
myCert.getDomainCert("example.com"); // returns promise
|
myCert.getDomainCert("example.com");
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note:** cert supports async parallel cert fetching.
|
|
||||||
However any subsequent calls will wait for the queue of the same dns zone to clear.
|
|
||||||
In other words: test1.domain1.tld and test2.domain2.tld will run in parallel, but test2.domain1.tld will wait for test1.domain1.tld !
|
|
||||||
|
|
||||||
## sslDir
|
|
||||||
to use the certificates it is important to understand what the structure of the ssl directory looks like.
|
|
||||||
|
|
||||||
## using a git origin repo.
|
|
||||||
Often times you want to keep track of certificates in order to keep them
|
|
||||||
even if the point of initial certificate request is gone. Imagine you have a dockerenvironement
|
|
||||||
and you keep starting new container versions for the same domain. YOu ideally want to use a proxy
|
|
||||||
that handles SSL managemet for you. But even the proxy needs to be updated from time to time.
|
|
||||||
|
|
||||||
So you need some kind of persistence between versions. This is why you can sync up all certificates to a git repo over ssh
|
|
||||||
Just make sure your id_rsa is in place for the node user and is allowed for the origin repo.
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
43
dist/cert.classes.cert.d.ts
vendored
43
dist/cert.classes.cert.d.ts
vendored
@ -1,43 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import { Stringmap, Objectmap } from 'lik';
|
|
||||||
import { Certificate } from './cert.classes.certificate';
|
|
||||||
import { Letsencrypt, TLeEnv } from './cert.classes.letsencrypt';
|
|
||||||
export interface ICertConstructorOptions {
|
|
||||||
cfEmail: string;
|
|
||||||
cfKey: string;
|
|
||||||
sslDirPath?: string;
|
|
||||||
gitOriginRepo?: string;
|
|
||||||
leEnv?: TLeEnv;
|
|
||||||
}
|
|
||||||
export declare class Cert {
|
|
||||||
domainStringRequestMap: Stringmap;
|
|
||||||
certificateMap: Objectmap<Certificate>;
|
|
||||||
letsencrypt: Letsencrypt;
|
|
||||||
private _challengeHandler;
|
|
||||||
private _certRepo;
|
|
||||||
/**
|
|
||||||
* Constructor for Cert object
|
|
||||||
*/
|
|
||||||
constructor(optionsArg: ICertConstructorOptions);
|
|
||||||
/**
|
|
||||||
* setup the Cert instanceof
|
|
||||||
* @executes ASYNC
|
|
||||||
* @return Promise
|
|
||||||
*/
|
|
||||||
setup(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* adds a Certificate for a given domain
|
|
||||||
*/
|
|
||||||
addCertificate(domainNameArg: string, optionsArg?: {
|
|
||||||
force: boolean;
|
|
||||||
}): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* cleans up old certificates
|
|
||||||
*/
|
|
||||||
cleanOldCertificates(): void;
|
|
||||||
/**
|
|
||||||
* executes the current batch of jobs
|
|
||||||
*/
|
|
||||||
deploy(): void;
|
|
||||||
}
|
|
75
dist/cert.classes.cert.js
vendored
75
dist/cert.classes.cert.js
vendored
@ -1,75 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const q = require("q");
|
|
||||||
const lik_1 = require("lik");
|
|
||||||
// classes
|
|
||||||
const cert_classes_certificate_1 = require("./cert.classes.certificate");
|
|
||||||
const cert_classes_certrepo_1 = require("./cert.classes.certrepo");
|
|
||||||
const cert_classes_letsencrypt_1 = require("./cert.classes.letsencrypt");
|
|
||||||
const cert_classes_challengehandler_1 = require("./cert.classes.challengehandler");
|
|
||||||
class Cert {
|
|
||||||
/**
|
|
||||||
* Constructor for Cert object
|
|
||||||
*/
|
|
||||||
constructor(optionsArg) {
|
|
||||||
this.domainStringRequestMap = new lik_1.Stringmap();
|
|
||||||
this.certificateMap = new lik_1.Objectmap();
|
|
||||||
// set up challengehandler
|
|
||||||
this._challengeHandler = new cert_classes_challengehandler_1.ChallengeHandler({
|
|
||||||
cfEmail: optionsArg.cfEmail,
|
|
||||||
cfKey: optionsArg.cfKey
|
|
||||||
});
|
|
||||||
// setup Letsencrypt
|
|
||||||
this.letsencrypt = new cert_classes_letsencrypt_1.Letsencrypt({
|
|
||||||
leEnv: optionsArg.leEnv,
|
|
||||||
sslDir: optionsArg.sslDirPath,
|
|
||||||
challengeHandler: this._challengeHandler
|
|
||||||
});
|
|
||||||
this._certRepo = new cert_classes_certrepo_1.CertRepo({
|
|
||||||
sslDirPath: optionsArg.sslDirPath,
|
|
||||||
remoteGitUrl: optionsArg.gitOriginRepo,
|
|
||||||
certInstance: this
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setup the Cert instanceof
|
|
||||||
* @executes ASYNC
|
|
||||||
* @return Promise
|
|
||||||
*/
|
|
||||||
setup() {
|
|
||||||
return this._certRepo.setup();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* adds a Certificate for a given domain
|
|
||||||
*/
|
|
||||||
addCertificate(domainNameArg, optionsArg = { force: false }) {
|
|
||||||
let done = q.defer();
|
|
||||||
let certificateForDomain = this.certificateMap.find((certificate) => {
|
|
||||||
return certificate.domainName === domainNameArg;
|
|
||||||
});
|
|
||||||
if (certificateForDomain instanceof cert_classes_certificate_1.Certificate) {
|
|
||||||
certificateForDomain.renew()
|
|
||||||
.then(done.resolve);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
certificateForDomain = new cert_classes_certificate_1.Certificate({
|
|
||||||
certInstance: this,
|
|
||||||
domainName: domainNameArg
|
|
||||||
});
|
|
||||||
certificateForDomain.renew()
|
|
||||||
.then(done.resolve);
|
|
||||||
}
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* cleans up old certificates
|
|
||||||
*/
|
|
||||||
cleanOldCertificates() {
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* executes the current batch of jobs
|
|
||||||
*/
|
|
||||||
deploy() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Cert = Cert;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5jbGFzc2VzLmNlcnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZXJ0LmNsYXNzZXMuY2VydC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUJBQXNCO0FBQ3RCLDZCQUEwQztBQUsxQyxVQUFVO0FBQ1YseUVBQXdEO0FBQ3hELG1FQUFrRDtBQUNsRCx5RUFBZ0U7QUFDaEUsbUZBQWtFO0FBV2xFO0lBT0k7O09BRUc7SUFDSCxZQUFZLFVBQW1DO1FBVC9DLDJCQUFzQixHQUFHLElBQUksZUFBUyxFQUFFLENBQUE7UUFDeEMsbUJBQWMsR0FBRyxJQUFJLGVBQVMsRUFBZSxDQUFBO1FBVXpDLDBCQUEwQjtRQUMxQixJQUFJLENBQU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CQUFvQixZQUFZLHNDQUFXLENBQUMsQ0FBQyxDQUFDO1lBQzlDLG9CQUFvQixDQUFDLEtBQUssRUFBRTtpQkFDdkIsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsQ0FBQTtRQUMzQixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixvQkFBb0IsR0FBRyxJQUFJLHNDQUFXLENBQUM7Z0JBQ25DLFlBQVksRUFBRSxJQUFJO2dCQUNsQixVQUFVLEVBQUUsYUFBYTthQUM1QixDQUFDLENBQUE7WUFDRixvQkFBb0IsQ0FBQyxLQUFLLEVBQUU7aUJBQ3ZCLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDM0IsQ0FBQztRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7T0FFRztJQUNILG9CQUFvQjtJQUVwQixDQUFDO0lBRUQ7O09BRUc7SUFDSCxNQUFNO0lBRU4sQ0FBQztDQUNKO0FBNUVELG9CQTRFQyJ9
|
|
48
dist/cert.classes.certificate.d.ts
vendored
48
dist/cert.classes.certificate.d.ts
vendored
@ -1,48 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import * as plugins from './cert.plugins';
|
|
||||||
import { Cert } from './cert.classes.cert';
|
|
||||||
export interface ICertificateFsConfig {
|
|
||||||
domainName: string;
|
|
||||||
creationTime: number;
|
|
||||||
expiryTime: number;
|
|
||||||
}
|
|
||||||
export interface ICertificateConstructorOptions {
|
|
||||||
domainName: string;
|
|
||||||
certInstance: Cert;
|
|
||||||
}
|
|
||||||
export declare type TCertificateStatus = 'unregistered' | 'valid' | 'expiring' | 'expired';
|
|
||||||
export declare class Certificate {
|
|
||||||
domainName: string;
|
|
||||||
certInstance: Cert;
|
|
||||||
domainData: plugins.smartstring.Domain;
|
|
||||||
creationDate: Date;
|
|
||||||
expiryDate: Date;
|
|
||||||
publicKey: string;
|
|
||||||
privKey: string;
|
|
||||||
/**
|
|
||||||
* run when creating a new instance of Certificate
|
|
||||||
*/
|
|
||||||
constructor(optionsArg: ICertificateConstructorOptions);
|
|
||||||
/**
|
|
||||||
* the status of the Certificate
|
|
||||||
*/
|
|
||||||
readonly status: TCertificateStatus;
|
|
||||||
readonly sameZoneRequesting: boolean;
|
|
||||||
/**
|
|
||||||
* schedule a retry of certificate request
|
|
||||||
*/
|
|
||||||
scheduleRetry(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* renew certificate if needed
|
|
||||||
*/
|
|
||||||
renew(force?: boolean): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* syncFs syncs the certificate with disk
|
|
||||||
*/
|
|
||||||
syncFs(): void;
|
|
||||||
/**
|
|
||||||
* deletes the certificate
|
|
||||||
*/
|
|
||||||
delete(): void;
|
|
||||||
}
|
|
103
dist/cert.classes.certificate.js
vendored
103
dist/cert.classes.certificate.js
vendored
@ -1,103 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const q = require("q");
|
|
||||||
const plugins = require("./cert.plugins");
|
|
||||||
class Certificate {
|
|
||||||
/**
|
|
||||||
* run when creating a new instance of Certificate
|
|
||||||
*/
|
|
||||||
constructor(optionsArg) {
|
|
||||||
this.creationDate = null;
|
|
||||||
this.expiryDate = null;
|
|
||||||
this.publicKey = null;
|
|
||||||
this.privKey = null;
|
|
||||||
this.domainName = optionsArg.domainName;
|
|
||||||
this.domainData = new plugins.smartstring.Domain(this.domainName);
|
|
||||||
this.certInstance = optionsArg.certInstance;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* the status of the Certificate
|
|
||||||
*/
|
|
||||||
get status() {
|
|
||||||
let validTimeRemaining = 0;
|
|
||||||
if (this.creationDate !== null && this.expiryDate !== null) {
|
|
||||||
validTimeRemaining = this.expiryDate.getTime() - Date.now();
|
|
||||||
}
|
|
||||||
let MonthMilliseconds = 2629746000;
|
|
||||||
if (this.publicKey === null || this.privKey === null) {
|
|
||||||
return 'unregistered';
|
|
||||||
}
|
|
||||||
else if (validTimeRemaining >= MonthMilliseconds) {
|
|
||||||
return 'valid';
|
|
||||||
}
|
|
||||||
else if (validTimeRemaining < MonthMilliseconds && validTimeRemaining >= 0) {
|
|
||||||
return 'expiring';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 'expired';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
get sameZoneRequesting() {
|
|
||||||
return this.certInstance.domainStringRequestMap.checkMinimatch('*' + this.domainData.zoneName);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* schedule a retry of certificate request
|
|
||||||
*/
|
|
||||||
scheduleRetry() {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
setTimeout(() => {
|
|
||||||
this.renew()
|
|
||||||
.then(done.resolve);
|
|
||||||
}, 60000);
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* renew certificate if needed
|
|
||||||
*/
|
|
||||||
renew(force = false) {
|
|
||||||
let done = q.defer();
|
|
||||||
if (this.status === 'valid') {
|
|
||||||
plugins.beautylog.log('Certificate still valid for more than 1 month, so it is not renewed now');
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
else if (this.status === 'expiring' || this.status === 'expired' || this.status === 'unregistered') {
|
|
||||||
plugins.beautylog.info('Certificate not valid currently, going to renew now!');
|
|
||||||
if (this.sameZoneRequesting) {
|
|
||||||
this.certInstance.domainStringRequestMap.registerUntilTrue(() => {
|
|
||||||
return !this.sameZoneRequesting;
|
|
||||||
}, () => {
|
|
||||||
this.renew().then(done.resolve);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.certInstance.letsencrypt.registerDomain(this.domainName)
|
|
||||||
.then(() => {
|
|
||||||
return this.syncFs();
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
done.resolve();
|
|
||||||
}).catch((err) => { console.log(err); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw Error(`weird status for certificate with domain name ${this.domainName}`);
|
|
||||||
}
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* syncFs syncs the certificate with disk
|
|
||||||
*/
|
|
||||||
syncFs() {
|
|
||||||
let configJsonMemory = {
|
|
||||||
domainName: this.domainName,
|
|
||||||
creationTime: this.creationDate.getTime(),
|
|
||||||
expiryTime: this.expiryDate.getTime()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* deletes the certificate
|
|
||||||
*/
|
|
||||||
delete() { }
|
|
||||||
}
|
|
||||||
exports.Certificate = Certificate;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5jbGFzc2VzLmNlcnRpZmljYXRlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2VydC5jbGFzc2VzLmNlcnRpZmljYXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSx1QkFBc0I7QUFFdEIsMENBQXlDO0FBcUJ6QztJQVNJOztPQUVHO0lBQ0gsWUFBWSxVQUEwQztRQVJ0RCxpQkFBWSxHQUFTLElBQUksQ0FBQTtRQUN6QixlQUFVLEdBQVMsSUFBSSxDQUFBO1FBQ3ZCLGNBQVMsR0FBVyxJQUFJLENBQUE7UUFDeEIsWUFBTyxHQUFXLElBQUksQ0FBQTtRQU1sQixJQUFJLENBQUMsVUFBVSxHQUFHLFVBQVUsQ0FBQyxVQUFVLENBQUE7UUFDdkMsSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLE9BQU8sQ0FBQyxXQUFXLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUNqRSxJQUFJLENBQUMsWUFBWSxHQUFHLFVBQVUsQ0FBQyxZQUFZLENBQUE7SUFDL0MsQ0FBQztJQUVEO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BQUUsSUFBSSxDQUFDLFVBQVUsQ0FBQyxPQUFPLEVBQUU7U0FDeEMsQ0FBQTtJQUVMLENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU0sS0FBSyxDQUFDO0NBQ2Y7QUF6R0Qsa0NBeUdDIn0=
|
|
31
dist/cert.classes.certrepo.d.ts
vendored
31
dist/cert.classes.certrepo.d.ts
vendored
@ -1,31 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import { Cert } from './cert.classes.cert';
|
|
||||||
export interface ICertRepoConstructorOptions {
|
|
||||||
sslDirPath: string;
|
|
||||||
remoteGitUrl: string;
|
|
||||||
certInstance: Cert;
|
|
||||||
}
|
|
||||||
export declare class CertRepo {
|
|
||||||
private _sslDirPath;
|
|
||||||
private _remoteGitUrl;
|
|
||||||
private gitRepo;
|
|
||||||
private _certInstance;
|
|
||||||
constructor(optionsArg: ICertRepoConstructorOptions);
|
|
||||||
/**
|
|
||||||
* setup the Cert instance
|
|
||||||
*/
|
|
||||||
setup(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* syncs an objectmap of Certificates with repo
|
|
||||||
*/
|
|
||||||
syncFs(): q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* Pulls already requested certificates from git origin
|
|
||||||
*/
|
|
||||||
sslGitOriginPull: () => void;
|
|
||||||
/**
|
|
||||||
* Pushes all new requested certificates to git origin
|
|
||||||
*/
|
|
||||||
sslGitOriginAddCommitPush: () => void;
|
|
||||||
}
|
|
59
dist/cert.classes.certrepo.js
vendored
59
dist/cert.classes.certrepo.js
vendored
@ -1,59 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const q = require("q");
|
|
||||||
const plugins = require("./cert.plugins");
|
|
||||||
const paths = require("./cert.paths");
|
|
||||||
class CertRepo {
|
|
||||||
constructor(optionsArg) {
|
|
||||||
/**
|
|
||||||
* Pulls already requested certificates from git origin
|
|
||||||
*/
|
|
||||||
this.sslGitOriginPull = () => {
|
|
||||||
if (this.gitRepo) {
|
|
||||||
this.gitRepo.pull('origin', 'master');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* Pushes all new requested certificates to git origin
|
|
||||||
*/
|
|
||||||
this.sslGitOriginAddCommitPush = () => {
|
|
||||||
if (this._remoteGitUrl) {
|
|
||||||
this.gitRepo.addAll();
|
|
||||||
this.gitRepo.commit('added new SSL certificates and deleted obsolete ones.');
|
|
||||||
this.gitRepo.push('origin', 'master');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this._sslDirPath = optionsArg.sslDirPath;
|
|
||||||
this._remoteGitUrl = optionsArg.remoteGitUrl;
|
|
||||||
this._certInstance = optionsArg.certInstance;
|
|
||||||
// setup sslDir
|
|
||||||
if (!this._sslDirPath) {
|
|
||||||
this._sslDirPath = paths.defaultSslDir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* setup the Cert instance
|
|
||||||
*/
|
|
||||||
setup() {
|
|
||||||
// setup Git
|
|
||||||
let done = q.defer();
|
|
||||||
if (this._remoteGitUrl) {
|
|
||||||
plugins.smartfile.fs.ensureEmptyDirSync(paths.defaultSslDir);
|
|
||||||
plugins.smartgit.createRepoFromClone(this._remoteGitUrl, paths.defaultSslDir)
|
|
||||||
.then(gitRepoArg => {
|
|
||||||
this.gitRepo = gitRepoArg;
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* syncs an objectmap of Certificates with repo
|
|
||||||
*/
|
|
||||||
syncFs() {
|
|
||||||
let done = q.defer();
|
|
||||||
done.resolve();
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.CertRepo = CertRepo;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5jbGFzc2VzLmNlcnRyZXBvLmpzIiwic291cmNlUm9vdCI6IiIsInNv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UcsS0FBSyxDQUFDLGFBQWEsQ0FBQTtRQUMxQyxDQUFDO0lBQ0wsQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSztRQUNELFlBQVk7UUFDWixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDcEIsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLGFBQWEsQ0FBQyxDQUFDLENBQUM7WUFDckIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsa0JBQWtCLENBQUMsS0FBSyxDQUFDLGFBQWEsQ0FBQyxDQUFBO1lBQzVELE9BQU8sQ0FBQyxRQUFRLENBQUMsbUJBQW1CLENBQUMsSUFBSSxDQUFDLGFBQWEsRUFBRSxLQUFLLENBQUMsYUFBYSxDQUFDO2lCQUN4RSxJQUFJLENBQUMsVUFBVTtnQkFDWixJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQTtnQkFDekIsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1lBQ2xCLENBQUMsQ0FBQyxDQUFBO1FBQ1YsQ0FBQztRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7SUFFRDs7T0FFRztJQUNILE1BQU07UUFDRixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDcEIsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztDQXFCSjtBQTdERCw0QkE2REMifQ==
|
|
20
dist/cert.classes.challengehandler.d.ts
vendored
20
dist/cert.classes.challengehandler.d.ts
vendored
@ -1,20 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
export interface IChallengehandlerConstructorOptions {
|
|
||||||
cfEmail: string;
|
|
||||||
cfKey: string;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* class ChallengeHandler handles challenges
|
|
||||||
*/
|
|
||||||
export declare class ChallengeHandler {
|
|
||||||
private _cfInstance;
|
|
||||||
constructor(optionsArg: IChallengehandlerConstructorOptions);
|
|
||||||
/**
|
|
||||||
* set a challenge
|
|
||||||
*/
|
|
||||||
setChallenge(domainNameArg: string, challengeArg: string): Q.Promise<{}>;
|
|
||||||
/**
|
|
||||||
* cleans a challenge
|
|
||||||
*/
|
|
||||||
cleanChallenge(domainNameArg: any): Q.Promise<{}>;
|
|
||||||
}
|
|
75
dist/cert.classes.challengehandler.js
vendored
75
dist/cert.classes.challengehandler.js
vendored
@ -1,75 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const plugins = require("./cert.plugins");
|
|
||||||
/**
|
|
||||||
* class ChallengeHandler handles challenges
|
|
||||||
*/
|
|
||||||
class ChallengeHandler {
|
|
||||||
constructor(optionsArg) {
|
|
||||||
this._cfInstance = new plugins.cflare.CflareAccount();
|
|
||||||
this._cfInstance.auth({
|
|
||||||
email: optionsArg.cfEmail,
|
|
||||||
key: optionsArg.cfKey
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* set a challenge
|
|
||||||
*/
|
|
||||||
setChallenge(domainNameArg, challengeArg) {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
plugins.beautylog.log('setting challenge for ' + domainNameArg);
|
|
||||||
this._cfInstance.createRecord(prefixName(domainNameArg), 'TXT', challengeArg).then(() => {
|
|
||||||
plugins.beautylog.ok('Challenge has been set!');
|
|
||||||
plugins.beautylog.info('We need to cool down to let DNS propagate to edge locations!');
|
|
||||||
cooldown().then(() => {
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* cleans a challenge
|
|
||||||
*/
|
|
||||||
cleanChallenge(domainNameArg) {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
plugins.beautylog.log('cleaning challenge for ' + domainNameArg);
|
|
||||||
this._cfInstance.removeRecord(prefixName(domainNameArg), 'TXT');
|
|
||||||
cooldown().then(() => {
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.ChallengeHandler = ChallengeHandler;
|
|
||||||
/**
|
|
||||||
* cooldown timer for letting DNS settle before answering the challengerequest
|
|
||||||
*/
|
|
||||||
let cooldown = () => {
|
|
||||||
let done = plugins.q.defer();
|
|
||||||
let cooldowntime = 60000;
|
|
||||||
let passedTime = 0;
|
|
||||||
plugins.beautylog.log('Cooling down! ' + (cooldowntime / 1000).toString() + ' seconds left');
|
|
||||||
let coolDownCounter = () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (cooldowntime <= passedTime) {
|
|
||||||
plugins.beautylog.ok('Cooled down!');
|
|
||||||
done.resolve();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
passedTime = passedTime + 5000;
|
|
||||||
plugins.beautylog.log('Cooling down! '
|
|
||||||
+ ((cooldowntime - passedTime) / 1000).toString()
|
|
||||||
+ ' seconds left');
|
|
||||||
coolDownCounter();
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
coolDownCounter();
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* prefix a domain name to make sure it complies with letsencrypt
|
|
||||||
*/
|
|
||||||
let prefixName = (domainNameArg) => {
|
|
||||||
return '_acme-challenge.' + domainNameArg;
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5jbGFzc2VzLmNoYWxsZW5nZWhhbmRsZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZXJ0LmNsYXNzZXMuY2hhbGxlbmdlaGFuZGxlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMENBQXlDO0FBUXpDOztHQUVHO0FBQ0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VBQVUsR0FBRyxVQUFVLEdBQUcsSUFBSSxDQUFBO2dCQUM5QixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxnQkFBZ0I7c0JBQ2hDLENBQUMsQ0FBQyxZQUFZLEdBQUcsVUFBVSxDQUFDLEdBQUcsSUFBSSxDQUFDLENBQUMsUUFBUSxFQUFFO3NCQUMvQyxlQUFlLENBQ3BCLENBQUE7Z0JBQ0QsZUFBZSxFQUFFLENBQUE7WUFDckIsQ0FBQztRQUNMLENBQUMsRUFBRSxJQUFJLENBQUMsQ0FBQTtJQUNaLENBQUMsQ0FBQTtJQUNELGVBQWUsRUFBRSxDQUFBO0lBQ2pCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3ZCLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ0gsSUFBSSxVQUFVLEdBQUcsQ0FBQyxhQUFxQjtJQUNuQyxNQUFNLENBQUMsa0JBQWtCLEdBQUcsYUFBYSxDQUFBO0FBQzdDLENBQUMsQ0FBQSJ9
|
|
26
dist/cert.classes.letsencrypt.d.ts
vendored
26
dist/cert.classes.letsencrypt.d.ts
vendored
@ -1,26 +0,0 @@
|
|||||||
/// <reference types="q" />
|
|
||||||
import * as q from 'q';
|
|
||||||
import { ChallengeHandler } from './cert.classes.challengehandler';
|
|
||||||
export declare type TLeEnv = 'production' | 'staging';
|
|
||||||
export interface ILetsencryptConstructorOptions {
|
|
||||||
leEnv: TLeEnv;
|
|
||||||
challengeHandler: ChallengeHandler;
|
|
||||||
sslDir: string;
|
|
||||||
}
|
|
||||||
export declare class Letsencrypt {
|
|
||||||
leEnv: TLeEnv;
|
|
||||||
challengeHandler: ChallengeHandler;
|
|
||||||
sslDir: string;
|
|
||||||
private _leInstance;
|
|
||||||
private _leServerUrl;
|
|
||||||
constructor(optionsArg: ILetsencryptConstructorOptions);
|
|
||||||
/**
|
|
||||||
* register a domain
|
|
||||||
*/
|
|
||||||
registerDomain(domainNameArg: string): q.Promise<{}>;
|
|
||||||
private _leCopyToDestination(domainNameArg);
|
|
||||||
/**
|
|
||||||
* translates to the format expected by letsencrypt node implementation
|
|
||||||
*/
|
|
||||||
private _leChallengeHandler();
|
|
||||||
}
|
|
136
dist/cert.classes.letsencrypt.js
vendored
136
dist/cert.classes.letsencrypt.js
vendored
File diff suppressed because one or more lines are too long
4
dist/cert.paths.d.ts
vendored
4
dist/cert.paths.d.ts
vendored
@ -1,4 +0,0 @@
|
|||||||
export declare let projectDir: string;
|
|
||||||
export declare let assetDir: string;
|
|
||||||
export declare let defaultSslDir: string;
|
|
||||||
export declare let leConfigDir: string;
|
|
10
dist/cert.paths.js
vendored
10
dist/cert.paths.js
vendored
@ -1,10 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const plugins = require("./cert.plugins");
|
|
||||||
// dirs
|
|
||||||
exports.projectDir = plugins.path.join(__dirname, '../');
|
|
||||||
exports.assetDir = plugins.path.join(exports.projectDir, 'assets');
|
|
||||||
exports.defaultSslDir = plugins.path.join(exports.assetDir, 'defaultSslDir');
|
|
||||||
exports.leConfigDir = plugins.path.join(exports.assetDir, 'letsencrypt');
|
|
||||||
plugins.smartfile.fs.ensureDirSync(exports.leConfigDir);
|
|
||||||
plugins.smartfile.fs.ensureDirSync(exports.defaultSslDir);
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NlcnQucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBDQUF5QztBQUV6QyxPQUFPO0FBQ0ksUUFBQSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFBO0FBQy9DLFFBQUEsUUFBUSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGtCQUFVLEVBQUMsUUFBUSxDQUFDLENBQUE7QUFDakQsUUFBQSxhQUFhLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsZ0JBQVEsRUFBQyxlQUFlLENBQUMsQ0FBQTtBQUMzRCxRQUFBLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxnQkFBUSxFQUFDLGFBQWEsQ0FBQyxDQUFBO0FBQ2xFLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGFBQWEsQ0FBQyxtQkFBVyxDQUFDLENBQUE7QUFDL0MsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsYUFBYSxDQUFDLHFCQUFhLENBQUMsQ0FBQSJ9
|
|
13
dist/cert.plugins.d.ts
vendored
13
dist/cert.plugins.d.ts
vendored
@ -1,13 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
import * as beautylog from 'beautylog';
|
|
||||||
import * as cflare from 'cflare';
|
|
||||||
declare let fs: any;
|
|
||||||
import * as lik from 'lik';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as q from 'q';
|
|
||||||
import * as shelljs from 'shelljs';
|
|
||||||
import * as smartcli from 'smartcli';
|
|
||||||
import * as smartfile from 'smartfile';
|
|
||||||
import * as smartgit from 'smartgit';
|
|
||||||
import * as smartstring from 'smartstring';
|
|
||||||
export { beautylog, cflare, fs, lik, path, q, shelljs, smartcli, smartfile, smartgit, smartstring };
|
|
25
dist/cert.plugins.js
vendored
25
dist/cert.plugins.js
vendored
@ -1,25 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
const beautylog = require("beautylog");
|
|
||||||
exports.beautylog = beautylog;
|
|
||||||
const cflare = require("cflare");
|
|
||||||
exports.cflare = cflare;
|
|
||||||
let fs = require('fs-extra');
|
|
||||||
exports.fs = fs;
|
|
||||||
const lik = require("lik");
|
|
||||||
exports.lik = lik;
|
|
||||||
const path = require("path");
|
|
||||||
exports.path = path;
|
|
||||||
const q = require("q");
|
|
||||||
exports.q = q;
|
|
||||||
const shelljs = require("shelljs");
|
|
||||||
exports.shelljs = shelljs;
|
|
||||||
const smartcli = require("smartcli");
|
|
||||||
exports.smartcli = smartcli;
|
|
||||||
const smartfile = require("smartfile");
|
|
||||||
exports.smartfile = smartfile;
|
|
||||||
const smartgit = require("smartgit");
|
|
||||||
exports.smartgit = smartgit;
|
|
||||||
const smartstring = require("smartstring");
|
|
||||||
exports.smartstring = smartstring;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2VydC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIsdUNBQXNDO0FBYWxDLDhCQUFTO0FBWmIsaUNBQWdDO0FBYTVCLHdCQUFNO0FBWlYsSUFBSSxFQUFFLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFBO0FBYXhCLGdCQUFFO0FBWk4sMkJBQTBCO0FBYXRCLGtCQUFHO0FBWlAsNkJBQTRCO0FBYXhCLG9CQUFJO0FBWlIsdUJBQXNCO0FBYWxCLGNBQUM7QUFaTCxtQ0FBa0M7QUFhOUIsMEJBQU87QUFaWCxxQ0FBb0M7QUFhaEMsNEJBQVE7QUFaWix1Q0FBc0M7QUFhbEMsOEJBQVM7QUFaYixxQ0FBb0M7QUFhaEMsNEJBQVE7QUFaWiwyQ0FBMEM7QUFhdEMsa0NBQVcifQ==
|
|
0
dist/hook.d.ts
vendored
Normal file
0
dist/hook.d.ts
vendored
Normal file
3
dist/hook.js
vendored
Normal file
3
dist/hook.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJob29rLmpzIiwic291cmNlc0NvbnRlbnQiOltdfQ==
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './cert.classes.cert';
|
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -1,6 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
function __export(m) {
|
|
||||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbmRleC5qcyIsInNvdXJjZXNDb250ZW50IjpbXX0=
|
||||||
}
|
|
||||||
__export(require("./cert.classes.cert"));
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEseUNBQW1DIn0=
|
|
||||||
|
0
dist/install.d.ts
vendored
Normal file
0
dist/install.d.ts
vendored
Normal file
3
dist/install.js
vendored
Normal file
3
dist/install.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJpbnN0YWxsLmpzIiwic291cmNlc0NvbnRlbnQiOltdfQ==
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"npmts": {
|
|
||||||
"mode": "default"
|
|
||||||
}
|
|
||||||
}
|
|
35
package.json
35
package.json
@ -1,17 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "cert",
|
"name": "cert",
|
||||||
"version": "1.0.8",
|
"version": "0.0.3",
|
||||||
"description": "Easily obain SSL certificates from LetsEncrypt. Supports DNS-01 challenge. TypeScript ready.",
|
"description": "automatic cert generation for coreos clusters",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npm run cleanTest && npmts --nodocs)",
|
"test": "(npmts)"
|
||||||
"cleanTest": "(rm -rf ./test/assets)",
|
|
||||||
"compile": "(npmts --notest)"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://gitlab.com/pushrocks/cert.git"
|
"url": "git+https://github.com/pushrocks/cert.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"coreos",
|
"coreos",
|
||||||
@ -22,29 +19,13 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/cert/issues"
|
"url": "https://github.com/pushrocks/cert/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/cert#readme",
|
"homepage": "https://github.com/pushrocks/cert#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/minimatch": "2.x.x",
|
"letsencrypt": "^1.4.4"
|
||||||
"@types/q": "0.0.32",
|
|
||||||
"beautylog": "^6.0.0",
|
|
||||||
"cflare": "0.0.10",
|
|
||||||
"fs-extra": "^1.0.0",
|
|
||||||
"lik": "^1.0.27",
|
|
||||||
"q": "^1.4.1",
|
|
||||||
"smartacme": "^1.0.2",
|
|
||||||
"smartcli": "^2.0.1",
|
|
||||||
"smartfile": "^4.1.1",
|
|
||||||
"smartgit": "1.0.5",
|
|
||||||
"smartstring": "^2.0.22",
|
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"npmts-g": "^5.2.6"
|
||||||
"npmts-g": "^5.2.10",
|
|
||||||
"qenv": "^1.1.1",
|
|
||||||
"should": "^11.1.2",
|
|
||||||
"typings-test": "^1.0.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1656
pnpm-lock.yaml
generated
1656
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
import 'typings-test';
|
|
43
test/test.js
43
test/test.js
@ -1,43 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const should = require("should");
|
|
||||||
const qenv_1 = require("qenv");
|
|
||||||
const path = require("path");
|
|
||||||
const q = require("q");
|
|
||||||
const cert = require("../dist/index");
|
|
||||||
let testQenv = new qenv_1.Qenv(process.cwd(), process.cwd() + '/.nogit');
|
|
||||||
let testCert;
|
|
||||||
describe('cert', function () {
|
|
||||||
describe('Cert', function () {
|
|
||||||
it('should create a new Cert object from class', function () {
|
|
||||||
testCert = new cert.Cert({
|
|
||||||
cfEmail: process.env.CF_EMAIL,
|
|
||||||
cfKey: process.env.CF_KEY,
|
|
||||||
sslDirPath: path.join(process.cwd(), 'test/assets'),
|
|
||||||
gitOriginRepo: 'git@gitlab.com:sandboxzone/sandbox-sslorigin.git',
|
|
||||||
leEnv: 'staging'
|
|
||||||
});
|
|
||||||
should(testCert).be.instanceof(cert.Cert);
|
|
||||||
});
|
|
||||||
it('should run class Cert.setup() successful', function (done) {
|
|
||||||
this.timeout(40000);
|
|
||||||
testCert.setup().then(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
it('should get a valid certificate', function (done) {
|
|
||||||
this.timeout(1200000);
|
|
||||||
let promiseArray = [];
|
|
||||||
function getRandomArbitrary(min, max) {
|
|
||||||
return Math.floor(Math.random() * (max - min) + min);
|
|
||||||
}
|
|
||||||
promiseArray.push(testCert.addCertificate(`testing${getRandomArbitrary(1, 100000)}.bleu.de`));
|
|
||||||
// promiseArray.push(testCert.addCertificate(`testing${getRandomArbitrary(1,100000)}.bleu.de`))
|
|
||||||
// promiseArray.push(testCert.addCertificate(`testing${getRandomArbitrary(1,100000)}.bleu.de`))
|
|
||||||
q.all(promiseArray).then(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsK0JBQXlCO0FBQ3pCLDZCQUE2QjtBQUM3Qix1QkFBdUI7QUFDdkIsc0NBQXFDO0FBR3JDLElBQUksUUFBUSxHQUFHLElBQUksV0FBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBRSxPQUFPLENBQUMsR0FBRyxFQUFFLEdBQUcsU0FBUyxDQUFDLENBQUE7QUFFakUsSUFBSSxRQUFtQixDQUFBO0FBRXZCLFFBQVEsQ0FBQyxNQUFNLEVBQUM7SUFDWixRQUFRLENBQUMsTUFBTSxFQUFDO1FBQ1osRUFBRSxDQUFDLDRDQUE0QyxFQUFDO1lBQzVDLFFBQVEsR0FBRyxJQUFJLElBQUksQ0FBQyxJQUFJLENBQUM7Z0JBQ3JCLE9BQU8sRUFBRSxPQUFPLENBQUMsR0FBRyxDQUFDLFFBQVE7Z0JBQzdCLEtBQUssRUFBRSxPQUFPLENBQUMsR0FBRyxDQUFDLE1BQU07Z0JBQ3pCLFVBQVUsRUFBRSxJQUF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MvRixDQUFDLENBQUMsR0FBRyxDQUFDLFlBQVksQ0FBQyxDQUFDLElBQUksQ0FBQztnQkFDckIsSUFBSSxFQUFFLENBQUE7WUFDVixDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
|
45
test/test.ts
45
test/test.ts
@ -1,45 +0,0 @@
|
|||||||
import 'typings-test'
|
|
||||||
import * as should from 'should'
|
|
||||||
import {Qenv} from 'qenv'
|
|
||||||
import path = require('path')
|
|
||||||
import q = require('q')
|
|
||||||
import * as cert from '../dist/index'
|
|
||||||
|
|
||||||
|
|
||||||
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit')
|
|
||||||
|
|
||||||
let testCert: cert.Cert
|
|
||||||
|
|
||||||
describe('cert',function(){
|
|
||||||
describe('Cert',function(){
|
|
||||||
it('should create a new Cert object from class',function(){
|
|
||||||
testCert = new cert.Cert({
|
|
||||||
cfEmail: process.env.CF_EMAIL,
|
|
||||||
cfKey: process.env.CF_KEY,
|
|
||||||
sslDirPath: path.join(process.cwd(),'test/assets'),
|
|
||||||
gitOriginRepo: 'git@gitlab.com:sandboxzone/sandbox-sslorigin.git',
|
|
||||||
leEnv: 'staging'
|
|
||||||
})
|
|
||||||
should(testCert).be.instanceof(cert.Cert)
|
|
||||||
})
|
|
||||||
it('should run class Cert.setup() successful', function(done){
|
|
||||||
this.timeout(40000)
|
|
||||||
testCert.setup().then(() => {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
it('should get a valid certificate',function(done){
|
|
||||||
this.timeout(1200000)
|
|
||||||
let promiseArray = []
|
|
||||||
function getRandomArbitrary(min, max) {
|
|
||||||
return Math.floor(Math.random() * (max - min) + min)
|
|
||||||
}
|
|
||||||
promiseArray.push(testCert.addCertificate(`testing${getRandomArbitrary(1,100000)}.bleu.de`))
|
|
||||||
// promiseArray.push(testCert.addCertificate(`testing${getRandomArbitrary(1,100000)}.bleu.de`))
|
|
||||||
// promiseArray.push(testCert.addCertificate(`testing${getRandomArbitrary(1,100000)}.bleu.de`))
|
|
||||||
q.all(promiseArray).then(() => {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,98 +0,0 @@
|
|||||||
import * as q from 'q'
|
|
||||||
import { Stringmap, Objectmap } from 'lik'
|
|
||||||
|
|
||||||
import * as plugins from './cert.plugins'
|
|
||||||
import * as paths from './cert.paths'
|
|
||||||
|
|
||||||
// classes
|
|
||||||
import { Certificate } from './cert.classes.certificate'
|
|
||||||
import { CertRepo } from './cert.classes.certrepo'
|
|
||||||
import { Letsencrypt, TLeEnv } from './cert.classes.letsencrypt'
|
|
||||||
import { ChallengeHandler } from './cert.classes.challengehandler'
|
|
||||||
|
|
||||||
|
|
||||||
export interface ICertConstructorOptions {
|
|
||||||
cfEmail: string,
|
|
||||||
cfKey: string,
|
|
||||||
sslDirPath?: string,
|
|
||||||
gitOriginRepo?: string,
|
|
||||||
leEnv?: TLeEnv
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Cert {
|
|
||||||
domainStringRequestMap = new Stringmap()
|
|
||||||
certificateMap = new Objectmap<Certificate>()
|
|
||||||
letsencrypt: Letsencrypt
|
|
||||||
private _challengeHandler: ChallengeHandler
|
|
||||||
private _certRepo: CertRepo
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for Cert object
|
|
||||||
*/
|
|
||||||
constructor(optionsArg: ICertConstructorOptions) {
|
|
||||||
|
|
||||||
// set up challengehandler
|
|
||||||
this._challengeHandler = new ChallengeHandler({
|
|
||||||
cfEmail: optionsArg.cfEmail,
|
|
||||||
cfKey: optionsArg.cfKey
|
|
||||||
})
|
|
||||||
|
|
||||||
// setup Letsencrypt
|
|
||||||
this.letsencrypt = new Letsencrypt({
|
|
||||||
leEnv: optionsArg.leEnv,
|
|
||||||
sslDir: optionsArg.sslDirPath,
|
|
||||||
challengeHandler: this._challengeHandler
|
|
||||||
})
|
|
||||||
|
|
||||||
this._certRepo = new CertRepo({
|
|
||||||
sslDirPath: optionsArg.sslDirPath,
|
|
||||||
remoteGitUrl: optionsArg.gitOriginRepo,
|
|
||||||
certInstance: this
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* setup the Cert instanceof
|
|
||||||
* @executes ASYNC
|
|
||||||
* @return Promise
|
|
||||||
*/
|
|
||||||
setup() {
|
|
||||||
return this._certRepo.setup()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds a Certificate for a given domain
|
|
||||||
*/
|
|
||||||
addCertificate(domainNameArg: string, optionsArg: { force: boolean } = { force: false }) {
|
|
||||||
let done = q.defer()
|
|
||||||
let certificateForDomain = this.certificateMap.find((certificate) => {
|
|
||||||
return certificate.domainName === domainNameArg
|
|
||||||
})
|
|
||||||
if (certificateForDomain instanceof Certificate) {
|
|
||||||
certificateForDomain.renew()
|
|
||||||
.then(done.resolve)
|
|
||||||
} else {
|
|
||||||
certificateForDomain = new Certificate({
|
|
||||||
certInstance: this,
|
|
||||||
domainName: domainNameArg
|
|
||||||
})
|
|
||||||
certificateForDomain.renew()
|
|
||||||
.then(done.resolve)
|
|
||||||
}
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cleans up old certificates
|
|
||||||
*/
|
|
||||||
cleanOldCertificates() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* executes the current batch of jobs
|
|
||||||
*/
|
|
||||||
deploy() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
import * as q from 'q'
|
|
||||||
|
|
||||||
import * as plugins from './cert.plugins'
|
|
||||||
import * as paths from './cert.paths'
|
|
||||||
|
|
||||||
// import classes
|
|
||||||
import { Cert } from './cert.classes.cert'
|
|
||||||
import { Letsencrypt } from './cert.classes.letsencrypt'
|
|
||||||
import { CertRepo } from './cert.classes.certrepo'
|
|
||||||
|
|
||||||
export interface ICertificateFsConfig {
|
|
||||||
domainName: string
|
|
||||||
creationTime: number
|
|
||||||
expiryTime: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ICertificateConstructorOptions {
|
|
||||||
domainName: string,
|
|
||||||
certInstance: Cert
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TCertificateStatus = 'unregistered' | 'valid' | 'expiring' | 'expired'
|
|
||||||
|
|
||||||
export class Certificate {
|
|
||||||
domainName: string
|
|
||||||
certInstance: Cert
|
|
||||||
domainData: plugins.smartstring.Domain
|
|
||||||
creationDate: Date = null
|
|
||||||
expiryDate: Date = null
|
|
||||||
publicKey: string = null
|
|
||||||
privKey: string = null
|
|
||||||
|
|
||||||
/**
|
|
||||||
* run when creating a new instance of Certificate
|
|
||||||
*/
|
|
||||||
constructor(optionsArg: ICertificateConstructorOptions) {
|
|
||||||
this.domainName = optionsArg.domainName
|
|
||||||
this.domainData = new plugins.smartstring.Domain(this.domainName)
|
|
||||||
this.certInstance = optionsArg.certInstance
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the status of the Certificate
|
|
||||||
*/
|
|
||||||
get status(): TCertificateStatus {
|
|
||||||
let validTimeRemaining: number = 0
|
|
||||||
if (this.creationDate !== null && this.expiryDate !== null) {
|
|
||||||
validTimeRemaining = this.expiryDate.getTime() - Date.now()
|
|
||||||
}
|
|
||||||
let MonthMilliseconds = 2629746000
|
|
||||||
if (this.publicKey === null || this.privKey === null) {
|
|
||||||
return 'unregistered'
|
|
||||||
} else if (validTimeRemaining >= MonthMilliseconds) {
|
|
||||||
return 'valid'
|
|
||||||
} else if (validTimeRemaining < MonthMilliseconds && validTimeRemaining >= 0) {
|
|
||||||
return 'expiring'
|
|
||||||
} else {
|
|
||||||
return 'expired'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get sameZoneRequesting(): boolean {
|
|
||||||
return this.certInstance.domainStringRequestMap.checkMinimatch('*' + this.domainData.zoneName)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* schedule a retry of certificate request
|
|
||||||
*/
|
|
||||||
scheduleRetry() {
|
|
||||||
let done = plugins.q.defer()
|
|
||||||
setTimeout(() => {
|
|
||||||
this.renew()
|
|
||||||
.then(done.resolve)
|
|
||||||
}, 60000)
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* renew certificate if needed
|
|
||||||
*/
|
|
||||||
renew(force: boolean = false) {
|
|
||||||
let done = q.defer()
|
|
||||||
if (this.status === 'valid') {
|
|
||||||
plugins.beautylog.log('Certificate still valid for more than 1 month, so it is not renewed now')
|
|
||||||
done.resolve()
|
|
||||||
} else if (this.status === 'expiring' || this.status === 'expired' || this.status === 'unregistered') {
|
|
||||||
plugins.beautylog.info('Certificate not valid currently, going to renew now!')
|
|
||||||
if (this.sameZoneRequesting) {
|
|
||||||
this.certInstance.domainStringRequestMap.registerUntilTrue(
|
|
||||||
() => {
|
|
||||||
return !this.sameZoneRequesting
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
this.renew().then(done.resolve)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.certInstance.letsencrypt.registerDomain(this.domainName)
|
|
||||||
.then(() => {
|
|
||||||
return this.syncFs()
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
done.resolve()
|
|
||||||
}).catch((err) => { console.log(err) })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw Error(`weird status for certificate with domain name ${this.domainName}`)
|
|
||||||
}
|
|
||||||
done.resolve()
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* syncFs syncs the certificate with disk
|
|
||||||
*/
|
|
||||||
syncFs() {
|
|
||||||
let configJsonMemory: ICertificateFsConfig = {
|
|
||||||
domainName: this.domainName,
|
|
||||||
creationTime: this.creationDate.getTime(),
|
|
||||||
expiryTime: this.expiryDate.getTime()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* deletes the certificate
|
|
||||||
*/
|
|
||||||
delete() { }
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
import * as q from 'q'
|
|
||||||
import { GitRepo } from 'smartgit'
|
|
||||||
|
|
||||||
import * as plugins from './cert.plugins'
|
|
||||||
import * as paths from './cert.paths'
|
|
||||||
|
|
||||||
import { Cert } from './cert.classes.cert'
|
|
||||||
import { Certificate } from './cert.classes.certificate'
|
|
||||||
|
|
||||||
export interface ICertRepoConstructorOptions {
|
|
||||||
sslDirPath: string
|
|
||||||
remoteGitUrl: string
|
|
||||||
certInstance: Cert
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CertRepo {
|
|
||||||
private _sslDirPath: string
|
|
||||||
private _remoteGitUrl: string
|
|
||||||
private gitRepo: GitRepo
|
|
||||||
private _certInstance: Cert
|
|
||||||
constructor(optionsArg: ICertRepoConstructorOptions) {
|
|
||||||
this._sslDirPath = optionsArg.sslDirPath
|
|
||||||
this._remoteGitUrl = optionsArg.remoteGitUrl
|
|
||||||
this._certInstance = optionsArg.certInstance
|
|
||||||
|
|
||||||
// setup sslDir
|
|
||||||
if (!this._sslDirPath) {
|
|
||||||
this._sslDirPath = paths.defaultSslDir
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* setup the Cert instance
|
|
||||||
*/
|
|
||||||
setup() {
|
|
||||||
// setup Git
|
|
||||||
let done = q.defer()
|
|
||||||
if (this._remoteGitUrl) {
|
|
||||||
plugins.smartfile.fs.ensureEmptyDirSync(paths.defaultSslDir)
|
|
||||||
plugins.smartgit.createRepoFromClone(this._remoteGitUrl, paths.defaultSslDir)
|
|
||||||
.then(gitRepoArg => {
|
|
||||||
this.gitRepo = gitRepoArg
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* syncs an objectmap of Certificates with repo
|
|
||||||
*/
|
|
||||||
syncFs() {
|
|
||||||
let done = q.defer()
|
|
||||||
done.resolve()
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pulls already requested certificates from git origin
|
|
||||||
*/
|
|
||||||
sslGitOriginPull = () => {
|
|
||||||
if (this.gitRepo) {
|
|
||||||
this.gitRepo.pull('origin', 'master')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pushes all new requested certificates to git origin
|
|
||||||
*/
|
|
||||||
sslGitOriginAddCommitPush = () => {
|
|
||||||
if (this._remoteGitUrl) {
|
|
||||||
this.gitRepo.addAll()
|
|
||||||
this.gitRepo.commit('added new SSL certificates and deleted obsolete ones.')
|
|
||||||
this.gitRepo.push('origin', 'master')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
import * as plugins from './cert.plugins'
|
|
||||||
import * as paths from './cert.paths'
|
|
||||||
|
|
||||||
export interface IChallengehandlerConstructorOptions {
|
|
||||||
cfEmail: string,
|
|
||||||
cfKey: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class ChallengeHandler handles challenges
|
|
||||||
*/
|
|
||||||
export class ChallengeHandler {
|
|
||||||
private _cfInstance: plugins.cflare.CflareAccount
|
|
||||||
constructor(optionsArg: IChallengehandlerConstructorOptions) {
|
|
||||||
this._cfInstance = new plugins.cflare.CflareAccount()
|
|
||||||
this._cfInstance.auth({
|
|
||||||
email: optionsArg.cfEmail,
|
|
||||||
key: optionsArg.cfKey
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set a challenge
|
|
||||||
*/
|
|
||||||
setChallenge(domainNameArg: string, challengeArg: string) {
|
|
||||||
let done = plugins.q.defer()
|
|
||||||
plugins.beautylog.log('setting challenge for ' + domainNameArg)
|
|
||||||
this._cfInstance.createRecord(prefixName(domainNameArg), 'TXT', challengeArg).then(() => {
|
|
||||||
plugins.beautylog.ok('Challenge has been set!')
|
|
||||||
plugins.beautylog.info('We need to cool down to let DNS propagate to edge locations!')
|
|
||||||
cooldown().then(() => {
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cleans a challenge
|
|
||||||
*/
|
|
||||||
cleanChallenge(domainNameArg) {
|
|
||||||
let done = plugins.q.defer()
|
|
||||||
plugins.beautylog.log('cleaning challenge for ' + domainNameArg)
|
|
||||||
this._cfInstance.removeRecord(prefixName(domainNameArg), 'TXT')
|
|
||||||
cooldown().then(() => {
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cooldown timer for letting DNS settle before answering the challengerequest
|
|
||||||
*/
|
|
||||||
let cooldown = () => {
|
|
||||||
let done = plugins.q.defer()
|
|
||||||
let cooldowntime = 60000
|
|
||||||
let passedTime = 0
|
|
||||||
plugins.beautylog.log('Cooling down! ' + (cooldowntime / 1000).toString() + ' seconds left')
|
|
||||||
let coolDownCounter = () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (cooldowntime <= passedTime) {
|
|
||||||
plugins.beautylog.ok('Cooled down!')
|
|
||||||
done.resolve()
|
|
||||||
} else {
|
|
||||||
passedTime = passedTime + 5000
|
|
||||||
plugins.beautylog.log('Cooling down! '
|
|
||||||
+ ((cooldowntime - passedTime) / 1000).toString()
|
|
||||||
+ ' seconds left'
|
|
||||||
)
|
|
||||||
coolDownCounter()
|
|
||||||
}
|
|
||||||
}, 5000)
|
|
||||||
}
|
|
||||||
coolDownCounter()
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* prefix a domain name to make sure it complies with letsencrypt
|
|
||||||
*/
|
|
||||||
let prefixName = (domainNameArg: string): string => {
|
|
||||||
return '_acme-challenge.' + domainNameArg
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
import * as q from 'q'
|
|
||||||
let letsencrypt = require('letsencrypt')
|
|
||||||
let leStore = require('le-store-certbot')
|
|
||||||
|
|
||||||
import * as plugins from './cert.plugins'
|
|
||||||
import * as paths from './cert.paths'
|
|
||||||
|
|
||||||
import { ChallengeHandler } from './cert.classes.challengehandler'
|
|
||||||
|
|
||||||
export type TLeEnv = 'production' | 'staging'
|
|
||||||
|
|
||||||
export interface ILetsencryptConstructorOptions {
|
|
||||||
leEnv: TLeEnv,
|
|
||||||
challengeHandler: ChallengeHandler,
|
|
||||||
sslDir: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Letsencrypt {
|
|
||||||
leEnv: TLeEnv
|
|
||||||
challengeHandler: ChallengeHandler // this is the format we use
|
|
||||||
sslDir: string
|
|
||||||
private _leServerUrl: string
|
|
||||||
|
|
||||||
constructor(optionsArg: ILetsencryptConstructorOptions) {
|
|
||||||
// determine leEnv
|
|
||||||
this.leEnv = optionsArg.leEnv
|
|
||||||
this.challengeHandler = optionsArg.challengeHandler
|
|
||||||
this.sslDir = optionsArg.sslDir
|
|
||||||
|
|
||||||
// set letsencrypt environment
|
|
||||||
if (this.leEnv === 'production') {
|
|
||||||
this._leServerUrl = letsencrypt.productionServerUrl
|
|
||||||
} else if (this.leEnv === 'staging') {
|
|
||||||
this._leServerUrl = letsencrypt.stagingServerUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* register a domain
|
|
||||||
*/
|
|
||||||
registerDomain(domainNameArg: string) {
|
|
||||||
plugins.beautylog.log(`trying to register domain ${domainNameArg}`)
|
|
||||||
let done = q.defer()
|
|
||||||
plugins.smartfile.fs.ensureDirSync(plugins.path.join(paths.leConfigDir, 'live', domainNameArg))
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
import * as plugins from './cert.plugins'
|
|
||||||
|
|
||||||
// dirs
|
|
||||||
export let projectDir = plugins.path.join(__dirname,'../')
|
|
||||||
export let assetDir = plugins.path.join(projectDir,'assets')
|
|
||||||
export let defaultSslDir = plugins.path.join(assetDir,'defaultSslDir')
|
|
||||||
export let leConfigDir = plugins.path.join(assetDir,'letsencrypt')
|
|
||||||
plugins.smartfile.fs.ensureDirSync(leConfigDir)
|
|
||||||
plugins.smartfile.fs.ensureDirSync(defaultSslDir)
|
|
@ -1,26 +0,0 @@
|
|||||||
import 'typings-global'
|
|
||||||
import * as beautylog from 'beautylog'
|
|
||||||
import * as cflare from 'cflare'
|
|
||||||
let fs = require('fs-extra')
|
|
||||||
import * as lik from 'lik'
|
|
||||||
import * as path from 'path'
|
|
||||||
import * as q from 'q'
|
|
||||||
import * as shelljs from 'shelljs'
|
|
||||||
import * as smartcli from 'smartcli'
|
|
||||||
import * as smartfile from 'smartfile'
|
|
||||||
import * as smartgit from 'smartgit'
|
|
||||||
import * as smartstring from 'smartstring'
|
|
||||||
|
|
||||||
export {
|
|
||||||
beautylog,
|
|
||||||
cflare,
|
|
||||||
fs,
|
|
||||||
lik,
|
|
||||||
path,
|
|
||||||
q,
|
|
||||||
shelljs,
|
|
||||||
smartcli,
|
|
||||||
smartfile,
|
|
||||||
smartgit,
|
|
||||||
smartstring
|
|
||||||
}
|
|
0
ts/hook.ts
Normal file
0
ts/hook.ts
Normal file
@ -1 +0,0 @@
|
|||||||
export * from './cert.classes.cert'
|
|
0
ts/install.ts
Normal file
0
ts/install.ts
Normal file
Loading…
x
Reference in New Issue
Block a user