now has sslDir implemented

This commit is contained in:
Philipp Kunz 2016-06-28 09:32:01 +02:00
parent 05b7c7ab45
commit ad792f32dd
6 changed files with 81 additions and 32 deletions

6
dist/index.d.ts vendored
View File

@ -1,7 +1,7 @@
export declare class Cert { export declare class Cert {
cfEmail: string; private _cfEmail;
cfKey: string; private _cfKey;
sslDir: string; private _sslDir;
certificatesPresent: Certificate[]; certificatesPresent: Certificate[];
certificatesValid: Certificate[]; certificatesValid: Certificate[];
gitOriginRepo: any; gitOriginRepo: any;

37
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,7 @@
"q": "^1.4.1", "q": "^1.4.1",
"shelljs": "^0.7.0", "shelljs": "^0.7.0",
"smartcli": "^1.0.4", "smartcli": "^1.0.4",
"smartfile": "^4.0.5", "smartfile": "^4.0.7",
"smartgit": "0.1.0", "smartgit": "0.1.0",
"smartstring": "^2.0.10", "smartstring": "^2.0.10",
"typings-global": "^1.0.3" "typings-global": "^1.0.3"

View File

@ -2,6 +2,7 @@
require("typings-test"); require("typings-test");
require("should"); require("should");
var qenv_1 = require("qenv"); var qenv_1 = require("qenv");
var path = require("path");
var install_1 = require("../dist/install"); var install_1 = require("../dist/install");
var cert = require("../dist/index"); var cert = require("../dist/index");
var testQenv = new qenv_1.Qenv(process.cwd(), process.cwd() + "/.nogit"); var testQenv = new qenv_1.Qenv(process.cwd(), process.cwd() + "/.nogit");
@ -20,17 +21,17 @@ describe("cert", function () {
testCert = new cert.Cert({ testCert = new cert.Cert({
cfEmail: process.env.CF_EMAIL, cfEmail: process.env.CF_EMAIL,
cfKey: process.env.CF_KEY, cfKey: process.env.CF_KEY,
sslDir: "" sslDir: path.join(process.cwd(), "test/assets")
}); });
testCert.should.be.instanceof(cert.Cert); testCert.should.be.instanceof(cert.Cert);
}); });
it("should get a valid certificate", function (done) { it("should get a valid certificate", function (done) {
this.timeout(120000); this.timeout(120000);
testCert.getDomainCert("sub6.bleu.de").then(function () { testCert.getDomainCert("sub7.bleu.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IsZnVuY3Rpb24oZG9uZSl7XG4gICAgICAgICAgICB0aGlzLnRpbWVvdXQoNTAwMCk7XG4gICAgICAgICAgICBzdGFydEluc3RhbGwoKS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICB9KVxuICAgICAgICB9KVxuICAgIH0pXG4gICAgZGVzY3JpYmUoXCJDZXJ0XCIsZnVuY3Rpb24oKXtcbiAgICAgICAgaXQoXCJzaG91bGQgY3JlYXRlIGEgbmV3IENlcnQgb2JqZWN0IGZyb20gY2xhc3NcIixmdW5jdGlvbigpe1xuICAgICAgICAgICAgdGVzdENlcnQgPSBuZXcgY2VydC5DZXJ0KHtcbiAgICAgICAgICAgICAgICBjZkVtYWlsOiBwcm9jZXNzLmVudi5DRl9FTUFJTCxcbiAgICAgICAgICAgICAgICBjZktleTogcHJvY2Vzcy5lbnYuQ0ZfS0VZLFxuICAgICAgICAgICAgICAgIHNzbERpcjogXCJcIlxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB0ZXN0Q2VydC5zaG91bGQuYmUuaW5zdGFuY2VvZihjZXJ0LkNlcnQpO1xuICAgICAgICB9KVxuICAgICAgICBpdChcInNob3VsZCBnZXQgYSB2YWxpZCBjZXJ0aWZpY2F0ZVwiLGZ1bmN0aW9uKGRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDEyMDAwMCk7XG4gICAgICAgICAgICB0ZXN0Q2VydC5nZXREb21haW5DZXJ0KFwic3ViNi5ibGV1LmRlXCIpLnRoZW4oKCkgPT4ge1xuICAgICAgICAgICAgICAgIGRvbmUoKTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICB9KVxuICAgIH0pXG59KTsiXX0= //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQ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GRvbmUpe1xuICAgICAgICAgICAgdGhpcy50aW1lb3V0KDUwMDApO1xuICAgICAgICAgICAgc3RhcnRJbnN0YWxsKCkudGhlbigoKSA9PiB7XG4gICAgICAgICAgICAgICAgZG9uZSgpO1xuICAgICAgICAgICAgfSlcbiAgICAgICAgfSlcbiAgICB9KVxuICAgIGRlc2NyaWJlKFwiQ2VydFwiLGZ1bmN0aW9uKCl7XG4gICAgICAgIGl0KFwic2hvdWxkIGNyZWF0ZSBhIG5ldyBDZXJ0IG9iamVjdCBmcm9tIGNsYXNzXCIsZnVuY3Rpb24oKXtcbiAgICAgICAgICAgIHRlc3RDZXJ0ID0gbmV3IGNlcnQuQ2VydCh7XG4gICAgICAgICAgICAgICAgY2ZFbWFpbDogcHJvY2Vzcy5lbnYuQ0ZfRU1BSUwsXG4gICAgICAgICAgICAgICAgY2ZLZXk6IHByb2Nlc3MuZW52LkNGX0tFWSxcbiAgICAgICAgICAgICAgICBzc2xEaXI6IHBhdGguam9pbihwcm9jZXNzLmN3ZCgpLFwidGVzdC9hc3NldHNcIilcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgdGVzdENlcnQuc2hvdWxkLmJlLmluc3RhbmNlb2YoY2VydC5DZXJ0KTtcbiAgICAgICAgfSlcbiAgICAgICAgaXQoXCJzaG91bGQgZ2V0IGEgdmFsaWQgY2VydGlmaWNhdGVcIixmdW5jdGlvbihkb25lKXtcbiAgICAgICAgICAgIHRoaXMudGltZW91dCgxMjAwMDApO1xuICAgICAgICAgICAgdGVzdENlcnQuZ2V0RG9tYWluQ2VydChcInN1YjcuYmxldS5kZVwiKS50aGVuKCgpID0+IHtcbiAgICAgICAgICAgICAgICBkb25lKCk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSlcbiAgICB9KVxufSk7Il19

View File

@ -1,6 +1,7 @@
import "typings-test"; import "typings-test";
import "should"; import "should";
import {Qenv} from "qenv"; import {Qenv} from "qenv";
import path = require("path");
import {startInstall} from "../dist/install"; import {startInstall} from "../dist/install";
import * as cert from "../dist/index"; import * as cert from "../dist/index";
@ -24,13 +25,13 @@ describe("cert",function(){
testCert = new cert.Cert({ testCert = new cert.Cert({
cfEmail: process.env.CF_EMAIL, cfEmail: process.env.CF_EMAIL,
cfKey: process.env.CF_KEY, cfKey: process.env.CF_KEY,
sslDir: "" sslDir: path.join(process.cwd(),"test/assets")
}); });
testCert.should.be.instanceof(cert.Cert); testCert.should.be.instanceof(cert.Cert);
}) })
it("should get a valid certificate",function(done){ it("should get a valid certificate",function(done){
this.timeout(120000); this.timeout(120000);
testCert.getDomainCert("sub6.bleu.de").then(() => { testCert.getDomainCert("sub7.bleu.de").then(() => {
done(); done();
}); });
}) })

View File

@ -2,9 +2,9 @@ import * as plugins from "./cert.plugins";
import * as paths from "./cert.paths"; import * as paths from "./cert.paths";
export class Cert { export class Cert {
cfEmail: string; private _cfEmail: string;
cfKey: string; private _cfKey: string;
sslDir: string; private _sslDir: string;
certificatesPresent:Certificate[]; certificatesPresent:Certificate[];
certificatesValid:Certificate[]; certificatesValid:Certificate[];
gitOriginRepo; gitOriginRepo;
@ -14,25 +14,25 @@ export class Cert {
sslDir: string, sslDir: string,
gitOriginRepo?: string gitOriginRepo?: string
}) { }) {
this.cfEmail = optionsArg.cfEmail; this._cfEmail = optionsArg.cfEmail;
this.cfKey = optionsArg.cfKey; this._cfKey = optionsArg.cfKey;
this.sslDir = optionsArg.sslDir; this._sslDir = optionsArg.sslDir;
this.gitOriginRepo = optionsArg.gitOriginRepo; this.gitOriginRepo = optionsArg.gitOriginRepo;
let config = { let config = {
cfEmail: this.cfEmail, cfEmail: this._cfEmail,
cfKey: this.cfKey cfKey: this._cfKey
} }
plugins.smartfile.memory.toFsSync(JSON.stringify(config),plugins.path.join(__dirname, "assets/config.json")); plugins.smartfile.memory.toFsSync(JSON.stringify(config),plugins.path.join(__dirname, "assets/config.json"));
}; };
getDomainCert(domainNameArg: string,optionsArg?:{force:boolean}) { getDomainCert(domainNameArg: string,optionsArg?:{force:boolean}) {
let done = plugins.q.defer(); let done = plugins.q.defer();
if (!checkDomainStillValid(domainNameArg) || optionsArg.force) { if (!checkDomainsStillValid(domainNameArg) || optionsArg.force) {
plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh); plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh);
plugins.shelljs.exec("chmod 700 " + paths.certHook); plugins.shelljs.exec("chmod 700 " + paths.certHook);
plugins.shelljs.exec("bash -c \"" + paths.letsencryptSh + " -c -d " + domainNameArg + " -t dns-01 -k " + paths.certHook + " -o " + paths.certDir + "\""); plugins.shelljs.exec("bash -c \"" + paths.letsencryptSh + " -c -d " + domainNameArg + " -t dns-01 -k " + paths.certHook + " -o " + paths.certDir + "\"");
let fetchedCertsArray:string[] = plugins.smartfile.fs.listFoldersSync(paths.certDir); let fetchedCertsArray:string[] = plugins.smartfile.fs.listFoldersSync(paths.certDir);
if(fetchedCertsArray.indexOf(domainNameArg) != -1){ if(fetchedCertsArray.indexOf(domainNameArg) != -1){
updateSslDir(domainNameArg); updateSslDirSync(this._sslDir,domainNameArg);
} }
done.resolve(); done.resolve();
} else { } else {
@ -52,12 +52,42 @@ export class Certificate {
}; };
} }
let checkDomainStillValid = (domainNameArg: string): boolean => { interface certConfig {
domainName:string;
created:number;
expires:number;
}
let checkDomainsStillValid = (domainNameArg: string): boolean => {
return false; return false;
} }
let updateSslDir = (domainNameArg) => { let updateSslDirSync = (sslDirArg:string,domainNameArg:string) => {
plugins.smartfile.fs.ensureDirSync(sslDirArg);
let domainCertFolder = plugins.path.join(paths.certDir,domainNameArg)
if(plugins.smartfile.fs.listFoldersSync(paths.certDir).indexOf(domainNameArg) != -1) {
plugins.smartfile.fs.copySync(
plugins.path.join(domainCertFolder,"fullchain.pem"),
plugins.path.join(sslDirArg,domainNameArg,"fullchain.pem")
);
plugins.smartfile.fs.copySync(
plugins.path.join(domainCertFolder,"privkey.pem"),
plugins.path.join(sslDirArg,domainNameArg,"privkey.pem")
);
// create cert config
let certRegex = /.*\-([]0-9]*)\.pem/;
let certFileNameWithTime = plugins.smartfile.fs.listFilesSync(domainCertFolder,certRegex)[1];
let certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]);
let certConfig:certConfig = {
domainName: domainNameArg,
created: certTime,
expires: certTime + 7776000
};
plugins.smartfile.memory.toFs(
JSON.stringify(certConfig),
plugins.path.join(sslDirArg,domainNameArg,"config.json")
);
};
} }
let updateGitOrigin = () => { let updateGitOrigin = () => {