integrate cert
This commit is contained in:
parent
244b21ca36
commit
e0757600b6
@ -24,7 +24,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "*",
|
"@types/q": "*",
|
||||||
"beautylog": "^5.0.13",
|
"beautylog": "^5.0.13",
|
||||||
"cert": "0.0.13",
|
"cert": "0.0.15",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"shelljs": "^0.7.0",
|
"shelljs": "^0.7.0",
|
||||||
"smartfile": "^4.0.10",
|
"smartfile": "^4.0.10",
|
||||||
|
@ -7,9 +7,15 @@ let allConfigs:NginxConfig[] = [];
|
|||||||
|
|
||||||
export class NginxConfig {
|
export class NginxConfig {
|
||||||
zones:NginxZone[] = [];
|
zones:NginxZone[] = [];
|
||||||
|
cert:plugins.cert.Cert; // the Cert Instance from which the config gets its certificates
|
||||||
isDeployed:boolean = false;
|
isDeployed:boolean = false;
|
||||||
constructor(){
|
constructor(optionsArg:plugins.cert.CertConstructorOptions){
|
||||||
|
this.cert = new plugins.cert.Cert({
|
||||||
|
cfEmail:optionsArg.cfEmail,
|
||||||
|
cfKey:optionsArg.cfKey,
|
||||||
|
sslDir:optionsArg.sslDir,
|
||||||
|
gitOriginRepo:optionsArg.gitOriginRepo
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// interact with Zones
|
// interact with Zones
|
||||||
@ -25,22 +31,34 @@ export class NginxConfig {
|
|||||||
|
|
||||||
// handle deployment of zones
|
// handle deployment of zones
|
||||||
deploy(nginxRestartArg:boolean = false){
|
deploy(nginxRestartArg:boolean = false){
|
||||||
|
let done = plugins.q.defer();
|
||||||
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
|
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
|
||||||
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
|
||||||
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
|
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
|
||||||
|
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
|
||||||
for(let config of allConfigs){
|
for(let config of allConfigs){
|
||||||
config.isDeployed = false;
|
config.isDeployed = false;
|
||||||
};
|
};
|
||||||
this.isDeployed = true;
|
this.isDeployed = true;
|
||||||
for(let zone of this.zones){
|
// write base config
|
||||||
zone.deploy();
|
|
||||||
};
|
|
||||||
plugins.smartfile.memory.toFsSync(
|
plugins.smartfile.memory.toFsSync(
|
||||||
snippets.getBaseConfigString(),
|
snippets.getBaseConfigString(),
|
||||||
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
|
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
|
||||||
);
|
);
|
||||||
|
// deploy zones
|
||||||
|
let promiseArray = [];
|
||||||
|
for(let zone of this.zones){
|
||||||
|
promiseArray.push(zone.deploy(this.cert));
|
||||||
|
};
|
||||||
|
plugins.q.all(promiseArray)
|
||||||
|
.then(() => {
|
||||||
|
// restart nginx
|
||||||
if(nginxRestartArg){
|
if(nginxRestartArg){
|
||||||
command.restart(this);
|
command.restart(this);
|
||||||
};
|
};
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
return done.promise;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,14 @@ export class NginxZone {
|
|||||||
this.destination = optionsArg.destination;
|
this.destination = optionsArg.destination;
|
||||||
this.configString = snippets.getZoneConfigString(optionsArg.zoneName,optionsArg.destination);
|
this.configString = snippets.getZoneConfigString(optionsArg.zoneName,optionsArg.destination);
|
||||||
};
|
};
|
||||||
deploy(){
|
deploy(certInstanceArg:plugins.cert.Cert){
|
||||||
|
let done = plugins.q.defer();
|
||||||
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
|
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
|
||||||
|
// writeConfig
|
||||||
plugins.smartfile.memory.toFsSync(this.configString,filePath);
|
plugins.smartfile.memory.toFsSync(this.configString,filePath);
|
||||||
|
// get cert
|
||||||
|
certInstanceArg.getDomainCert(this.zoneName)
|
||||||
|
.then(done.resolve);
|
||||||
|
return done.promise;
|
||||||
};
|
};
|
||||||
};
|
};
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from "./smartnginx.plugins"
|
import * as plugins from "./smartnginx.plugins"
|
||||||
|
|
||||||
export let packageBase = plugins.path.join(__dirname,"../");
|
export let packageBase = plugins.path.join(__dirname,"../");
|
||||||
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig/");
|
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig");
|
||||||
export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones");
|
export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones");
|
||||||
|
export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert");
|
Loading…
Reference in New Issue
Block a user