track the config state in cloudron.js
This commit is contained in:
committed by
Johannes Zellner
parent
09997398b1
commit
8f4ed47b63
+13
-1
@@ -18,6 +18,7 @@ exports = module.exports = {
|
|||||||
migrate: migrate,
|
migrate: migrate,
|
||||||
|
|
||||||
isConfiguredSync: isConfiguredSync,
|
isConfiguredSync: isConfiguredSync,
|
||||||
|
getConfigStateSync: getConfigStateSync,
|
||||||
|
|
||||||
checkDiskSpace: checkDiskSpace,
|
checkDiskSpace: checkDiskSpace,
|
||||||
|
|
||||||
@@ -87,7 +88,8 @@ const BOX_AND_USER_TEMPLATE = {
|
|||||||
|
|
||||||
var gUpdatingDns = false, // flag for dns update reentrancy
|
var gUpdatingDns = false, // flag for dns update reentrancy
|
||||||
gBoxAndUserDetails = null, // cached cloudron details like region,size...
|
gBoxAndUserDetails = null, // cached cloudron details like region,size...
|
||||||
gIsConfigured = null; // cached configured state so that return value is synchronous. null means we are not initialized yet
|
gIsConfigured = null, // cached configured state so that return value is synchronous. null means we are not initialized yet
|
||||||
|
gConfigState = { domain: false, dns: false, tls: false };
|
||||||
|
|
||||||
function CloudronError(reason, errorOrMessage) {
|
function CloudronError(reason, errorOrMessage) {
|
||||||
assert.strictEqual(typeof reason, 'string');
|
assert.strictEqual(typeof reason, 'string');
|
||||||
@@ -145,6 +147,10 @@ function isConfiguredSync() {
|
|||||||
return gIsConfigured === true;
|
return gIsConfigured === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConfigStateSync() {
|
||||||
|
return gConfigState;
|
||||||
|
}
|
||||||
|
|
||||||
function isConfigured(callback) {
|
function isConfigured(callback) {
|
||||||
// set of rules to see if we have the configs required for cloudron to function
|
// set of rules to see if we have the configs required for cloudron to function
|
||||||
// note this checks for missing configs and not invalid configs
|
// note this checks for missing configs and not invalid configs
|
||||||
@@ -204,15 +210,21 @@ function configureAdmin(callback) {
|
|||||||
|
|
||||||
nginx.configureAdmin(certFilePath, keyFilePath, ip, callback);
|
nginx.configureAdmin(certFilePath, keyFilePath, ip, callback);
|
||||||
} else {
|
} else {
|
||||||
|
gConfigState.domain = true;
|
||||||
|
|
||||||
subdomains.waitForDns(config.adminFqdn(), ip, 'A', { interval: 30000, times: 50000 }, function (error) {
|
subdomains.waitForDns(config.adminFqdn(), ip, 'A', { interval: 30000, times: 50000 }, function (error) {
|
||||||
if (error) return callback(error);
|
if (error) return callback(error);
|
||||||
|
|
||||||
|
gConfigState.dns = true;
|
||||||
|
|
||||||
certificates.ensureCertificate({ location: constants.ADMIN_LOCATION }, function (error, certFilePath, keyFilePath) {
|
certificates.ensureCertificate({ location: constants.ADMIN_LOCATION }, function (error, certFilePath, keyFilePath) {
|
||||||
if (error) { // currently, this can never happen
|
if (error) { // currently, this can never happen
|
||||||
debug('Error obtaining certificate. Proceed anyway', error);
|
debug('Error obtaining certificate. Proceed anyway', error);
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gConfigState.tls = true;
|
||||||
|
|
||||||
nginx.configureAdmin(certFilePath, keyFilePath, config.adminFqdn(), callback);
|
nginx.configureAdmin(certFilePath, keyFilePath, config.adminFqdn(), callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -101,14 +101,7 @@ function dnsSetup(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dnsReady(req, res, next) {
|
function dnsReady(req, res, next) {
|
||||||
if (config.provider() === 'caas') return next(new HttpError(410, 'Not availabe for caas'));
|
next(new HttpSuccess(200, cloudron.getConfigStateSync()));
|
||||||
|
|
||||||
if (!config.fqdn()) return next(new HttpSuccess(200, { domain: false, ssl: false, dns: false }));
|
|
||||||
if (!certificates.adminCertificateExists()) return next(new HttpSuccess(200, { domain: true, ssl: false, dns: false }));
|
|
||||||
|
|
||||||
// TODO also check for DNS
|
|
||||||
|
|
||||||
next(new HttpSuccess(200, { domain: true, ssl: true, dns: false }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupTokenAuth(req, res, next) {
|
function setupTokenAuth(req, res, next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user