return location certificates

This commit is contained in:
Girish Ramakrishnan
2022-07-14 11:57:04 +05:30
parent f0abd7edc8
commit a246cb7e73
2 changed files with 51 additions and 25 deletions

View File

@@ -276,17 +276,17 @@ function getAcmeCertificatePathSync(fqdn, domainObject) {
return { certName, certFilePath, keyFilePath, csrFilePath, acmeChallengesDir };
}
async function setAppCertificate(subdomain, domainObject, bundle) {
async function setAppCertificate(subdomain, domainObject, certificate) {
assert.strictEqual(typeof subdomain, 'string');
assert.strictEqual(typeof domainObject, 'object');
assert(bundle && typeof bundle === 'object');
assert.strictEqual(typeof certificate, 'object');
const fqdn = dns.fqdn(subdomain, domainObject);
const { certFilePath, keyFilePath } = getAppCertificatePathSync(fqdn);
if (bundle.cert && bundle.key) {
if (!safe.fs.writeFileSync(certFilePath, bundle.cert)) throw safe.error;
if (!safe.fs.writeFileSync(keyFilePath, bundle.key)) throw safe.error;
if (certificate !== null) {
if (!safe.fs.writeFileSync(certFilePath, certificate.cert)) throw safe.error;
if (!safe.fs.writeFileSync(keyFilePath, certificate.key)) throw safe.error;
} else { // remove existing cert/key
if (!safe.fs.unlinkSync(certFilePath)) debug(`Error removing cert: ${safe.error.message}`);
if (!safe.fs.unlinkSync(keyFilePath)) debug(`Error removing key: ${safe.error.message}`);