smartcert/ts/index.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

2016-06-22 11:22:09 +00:00
import * as plugins from "./cert.plugins";
2016-06-18 13:59:03 +00:00
import * as paths from "./cert.paths";
export class Cert {
2016-06-23 01:46:37 +00:00
cfEmail: string;
cfKey: string;
sslDir: string;
2016-06-23 02:37:18 +00:00
certificatesPresent:Certificate[];
certificatesValid:Certificate[];
2016-06-18 13:59:03 +00:00
gitOriginRepo;
2016-06-23 01:46:37 +00:00
constructor(optionsArg: {
cfEmail: string,
cfKey: string,
sslDir: string,
gitOriginRepo?: string
}) {
2016-06-18 13:59:03 +00:00
this.cfEmail = optionsArg.cfEmail;
this.cfKey = optionsArg.cfKey;
this.sslDir = optionsArg.sslDir;
this.gitOriginRepo = optionsArg.gitOriginRepo;
2016-06-22 11:22:09 +00:00
let config = {
cfEmail: this.cfEmail,
cfKey: this.cfKey
}
2016-06-23 01:46:37 +00:00
plugins.smartfile.memory.toFsSync(JSON.stringify(config), { fileName: "config.json", filePath: plugins.path.join(__dirname, "assets/") });
2016-06-22 11:22:09 +00:00
};
2016-06-23 01:46:37 +00:00
getDomainCert(domainNameArg: string,optionsArg:{force:boolean}) {
2016-06-22 11:22:09 +00:00
let done = plugins.q.defer();
2016-06-23 01:46:37 +00:00
if (!checkDomainStillValid(domainNameArg) || optionsArg.force) {
plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh);
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.sslDir + "\"");
done.resolve();
} else {
plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!");
done.resolve();
}
2016-06-22 11:22:09 +00:00
return done.promise;
2016-06-18 13:59:03 +00:00
};
}
class Certificate {
2016-06-23 01:46:37 +00:00
domainName: string;
creationDate: Date;
expiryDate: Date;
constructor() {
2016-06-18 13:59:03 +00:00
};
}
2016-06-23 01:46:37 +00:00
let checkDomainStillValid = (domainNameArg: string): boolean => {
return false;
}
2016-06-23 01:46:37 +00:00
let updateSslDir = () => {
2016-06-23 02:37:18 +00:00
}
let updateGitOrigin = () => {
2016-06-23 01:46:37 +00:00
2016-06-18 13:59:03 +00:00
}