mirror of
https://github.com/caprover/caprover
synced 2026-08-05 07:11:02 +00:00
reformat code
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
const ApiStatusCode = require('./ApiStatusCodes');
|
||||
const BaseApi = require('./BaseApi');
|
||||
|
||||
class TokenApi extends BaseApi{
|
||||
class TokenApi extends BaseApi {
|
||||
|
||||
constructor(token){
|
||||
constructor(token) {
|
||||
super(ApiStatusCode.STATUS_OK, '');
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ const EnvVars = require('../utils/EnvVars');
|
||||
function safeParseChunk(chunk) {
|
||||
try {
|
||||
return JSON.parse(chunk);
|
||||
}
|
||||
catch (ignore) {
|
||||
} catch (ignore) {
|
||||
return {
|
||||
stream: 'Cannot parse ' + chunk
|
||||
}
|
||||
@@ -601,8 +600,7 @@ class DockerApi {
|
||||
}
|
||||
|
||||
ports.push(item);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let tcpItem = {
|
||||
Protocol: 'tcp',
|
||||
TargetPort: portsToMap[i].containerPort,
|
||||
@@ -934,8 +932,7 @@ class DockerApi {
|
||||
|
||||
if (secretExists) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return self.dockerode
|
||||
.createSecret({
|
||||
Name: secretKey,
|
||||
@@ -1131,8 +1128,7 @@ class DockerApi {
|
||||
TargetPort: p.containerPort,
|
||||
PublishedPort: p.hostPort
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
updatedData.EndpointSpec.Ports.push({
|
||||
Protocol: 'tcp',
|
||||
TargetPort: p.containerPort,
|
||||
@@ -1165,8 +1161,7 @@ class DockerApi {
|
||||
ReadOnly: false,
|
||||
Consistency: 'default'
|
||||
});
|
||||
}
|
||||
else if (v.type === TYPE_VOLUME) {
|
||||
} else if (v.type === TYPE_VOLUME) {
|
||||
|
||||
// named volumes are created here:
|
||||
// /var/lib/docker/volumes/YOUR_VOLUME_NAME/_data
|
||||
@@ -1177,8 +1172,7 @@ class DockerApi {
|
||||
ReadOnly: false
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw new Error("Unknown volume type!!");
|
||||
}
|
||||
|
||||
@@ -1223,8 +1217,7 @@ class DockerApi {
|
||||
|
||||
if (foundIndexSecret >= 0) {
|
||||
updatedData.TaskTemplate.ContainerSpec.Secrets[foundIndexSecret] = objToAdd;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
updatedData.TaskTemplate.ContainerSpec.Secrets.push(objToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,7 @@ router.post('/:appName/', upload.single('sourceFile'), function (req, res, next)
|
||||
}
|
||||
|
||||
return serviceManager.createTarFarFromCaptainContent(captainDefinitionContent, appName, tarballSourceFilePath);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
if (!tarballSourceFilePath) {
|
||||
throw ApiStatusCodes.createError(ApiStatusCodes.ILLEGAL_OPERATION, "Either tarballfile or captainDefinitionContent should be present.")
|
||||
@@ -126,8 +125,7 @@ router.post('/:appName/', upload.single('sourceFile'), function (req, res, next)
|
||||
.catch(function (error) {
|
||||
Logger.e(error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return startBuildProcess()
|
||||
.then(function () {
|
||||
res.send(new BaseApi(ApiStatusCodes.STATUS_OK, 'Deploy is done'));
|
||||
|
||||
@@ -123,8 +123,7 @@ router.get('/', function (req, res, next) {
|
||||
.then(function (decryptedData) {
|
||||
app.appPushWebhook.repoInfo = decryptedData;
|
||||
}));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
app.appPushWebhook.repoInfo = {};
|
||||
}
|
||||
appsArray.push(app);
|
||||
|
||||
@@ -32,8 +32,7 @@ router.post('/', function (req, res, next) {
|
||||
.catch(function (error) {
|
||||
if (error && error.captainErrorType) {
|
||||
res.send(new BaseApi(error.captainErrorType, error.apiMessage));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Logger.e(error);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ router.post('/changerootdomain/', function (req, res, next) {
|
||||
.catch(function (error) {
|
||||
if (error && error.captainErrorType) {
|
||||
res.send(new BaseApi(error.captainErrorType, error.apiMessage));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Logger.e(error);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
@@ -76,8 +75,7 @@ router.post('/enablessl/', function (req, res, next) {
|
||||
.catch(function (error) {
|
||||
if (error && error.captainErrorType) {
|
||||
res.send(new BaseApi(error.captainErrorType, error.apiMessage));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Logger.e(error); //
|
||||
res.sendStatus(500); //
|
||||
}
|
||||
@@ -96,8 +94,7 @@ router.post('/forcessl/', function (req, res, next) {
|
||||
.catch(function (error) {
|
||||
if (error && error.captainErrorType) {
|
||||
res.send(new BaseApi(error.captainErrorType, error.apiMessage));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Logger.e(error);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
@@ -148,11 +145,9 @@ router.post('/enableregistry/', function (req, res, next) {
|
||||
.then(function () {
|
||||
if (isLocal) {
|
||||
return captainManager.getDockerRegistry().ensureDockerRegistryRunningOnThisNode();
|
||||
}
|
||||
else if (isRemote) {
|
||||
} else if (isRemote) {
|
||||
return true; // remote registry is already created :p we just need to update the credentials
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw ApiStatusCodes.createError(ApiStatusCodes.STATUS_ERROR_GENERIC, 'Registry type is not known.');
|
||||
}
|
||||
})
|
||||
@@ -304,13 +299,11 @@ router.get('/versionInfo/', function (req, res, next) {
|
||||
canUpdate = true;
|
||||
latestVersion = tag;
|
||||
break;
|
||||
}
|
||||
else if (Number(tag[0]) === Number(currentVersion[0]) && Number(tag[1]) > Number(currentVersion[1])) {
|
||||
} else if (Number(tag[0]) === Number(currentVersion[0]) && Number(tag[1]) > Number(currentVersion[1])) {
|
||||
canUpdate = true;
|
||||
latestVersion = tag;
|
||||
break;
|
||||
}
|
||||
else if (Number(tag[0]) === Number(currentVersion[0]) && Number(tag[1]) === Number(currentVersion[1]) && Number(tag[2]) > Number(currentVersion[2])) {
|
||||
} else if (Number(tag[0]) === Number(currentVersion[0]) && Number(tag[1]) === Number(currentVersion[1]) && Number(tag[2]) > Number(currentVersion[2])) {
|
||||
canUpdate = true;
|
||||
latestVersion = tag;
|
||||
break;
|
||||
@@ -531,11 +524,9 @@ router.post('/nodes/', function (req, res, next) {
|
||||
|
||||
if (req.body.nodeType === MANAGER) {
|
||||
isManager = true;
|
||||
}
|
||||
else if (req.body.nodeType === WORKER) {
|
||||
} else if (req.body.nodeType === WORKER) {
|
||||
isManager = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
res.send(new BaseApi(ApiStatusCodes.STATUS_ERROR_GENERIC, 'Node type should be either manager or worker'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,8 +87,7 @@ router.post('/changepassword/', function (req, res, next) {
|
||||
.catch(function (error) {
|
||||
if (error && error.captainErrorType) {
|
||||
res.send(new BaseApi(error.captainErrorType, error.apiMessage));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Logger.e(error);
|
||||
res.sendStatus(500);
|
||||
}
|
||||
|
||||
@@ -29,13 +29,11 @@ router.post('/triggerbuild', urlencodedParser, function (req, res, next) {
|
||||
}
|
||||
let ref = bodyJson.ref; // "refs/heads/somebranch"
|
||||
res.locals.pushedBranches.push(ref.substring(11, ref.length));
|
||||
}
|
||||
else if (isBitbucket) {
|
||||
} else if (isBitbucket) {
|
||||
for (let i = 0; i < req.body.push.changes.length; i++) {
|
||||
res.locals.pushedBranches.push(req.body.push.changes[i].new.name);
|
||||
}
|
||||
}
|
||||
else if (isGitlab) {
|
||||
} else if (isGitlab) {
|
||||
let ref = req.body.ref; // "refs/heads/somebranch"
|
||||
res.locals.pushedBranches.push(ref.substring(11, ref.length));
|
||||
}
|
||||
|
||||
@@ -759,7 +759,7 @@ class CaptainManager {
|
||||
throw ApiStatusCodes.createError(ApiStatusCodes.ILLEGAL_PARAMETER, 'User, password and domain are required.');
|
||||
}
|
||||
|
||||
let passwordEncrypted = Encryptor.create(self.getCaptainSalt()).encrypt(registryPassword);
|
||||
let passwordEncrypted = Encryptor.create(self.getCaptainSalt()).encrypt(registryPassword);
|
||||
|
||||
return self.dataStore.addRegistryToDb(registryUser, passwordEncrypted, registryDomain, registryImagePrefix);
|
||||
|
||||
|
||||
@@ -157,8 +157,7 @@ class CertbotManager {
|
||||
throw new Error('Unexpected output when registering with ACME Certbot \n' + registerOutput);
|
||||
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
/*
|
||||
|
||||
@@ -303,8 +302,7 @@ class CertbotManager {
|
||||
return dockerApi
|
||||
.getNodeIdByServiceName(CaptainConstants.certbotServiceName);
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
Logger.d('No Captain Certbot service is running. Creating one...');
|
||||
|
||||
@@ -333,8 +331,7 @@ class CertbotManager {
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -139,8 +139,7 @@ class DockerRegistry {
|
||||
return dockerApi
|
||||
.getNodeIdByServiceName(CaptainConstants.registryServiceName);
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
Logger.d('No Captain Registry service is running. Creating one...');
|
||||
|
||||
@@ -171,8 +170,7 @@ class DockerRegistry {
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
return true;
|
||||
|
||||
@@ -226,8 +224,7 @@ class DockerRegistry {
|
||||
if (secretExist) {
|
||||
Logger.d('WARNING! Unexpected secret exist! Perhaps secret was created but Captain was not updated.');
|
||||
return self.updateRegistryAuthHeader(username, password, domain, nextVersion);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return dockerApi
|
||||
.ensureSecret(secretName, JSON.stringify({
|
||||
username: username,
|
||||
|
||||
@@ -244,8 +244,8 @@ class LoadBalancerManager {
|
||||
serviceExposedPort: CaptainConstants.captainServiceExposedPort,
|
||||
defaultHtmlDir: CaptainConstants.nginxStaticRootDir + CaptainConstants.nginxDefaultHtmlDir,
|
||||
staticWebRoot: CaptainConstants.nginxStaticRootDir
|
||||
+ CaptainConstants.nginxDomainSpecificHtmlDir + '/'
|
||||
+ captainDomain
|
||||
+ CaptainConstants.nginxDomainSpecificHtmlDir + '/'
|
||||
+ captainDomain
|
||||
},
|
||||
registry: {
|
||||
crtPath: self.getSslCertPath(registryDomain),
|
||||
@@ -253,8 +253,8 @@ class LoadBalancerManager {
|
||||
hasRootSsl: hasRegistrySsl,
|
||||
domain: registryDomain,
|
||||
staticWebRoot: CaptainConstants.nginxStaticRootDir
|
||||
+ CaptainConstants.nginxDomainSpecificHtmlDir + '/'
|
||||
+ registryDomain
|
||||
+ CaptainConstants.nginxDomainSpecificHtmlDir + '/'
|
||||
+ registryDomain
|
||||
}
|
||||
});
|
||||
|
||||
@@ -403,8 +403,7 @@ class LoadBalancerManager {
|
||||
return dockerApi
|
||||
.getNodeIdByServiceName(CaptainConstants.nginxServiceName);
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
|
||||
return createNginxServiceOnNode(myNodeId)
|
||||
@@ -432,8 +431,7 @@ class LoadBalancerManager {
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -31,15 +31,13 @@ function checkSystemReq() {
|
||||
|
||||
if (maj > 17) {
|
||||
versionOk = true;
|
||||
}
|
||||
else if (maj === 17 && min >= 6) {
|
||||
} else if (maj === 17 && min >= 6) {
|
||||
versionOk = true;
|
||||
}
|
||||
|
||||
if (versionOk) {
|
||||
console.log(' Docker Version passed.');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log('Warning!! Minimum Docker version is 17.06.x CaptainDuckDuck may not run properly on your Docker version.');
|
||||
}
|
||||
|
||||
@@ -50,15 +48,13 @@ function checkSystemReq() {
|
||||
|
||||
if (output.OperatingSystem.toLowerCase().indexOf('ubuntu') < 0) {
|
||||
console.log('Warning!! CaptainDuckDuck and Docker work best on Ubuntu - specially when it comes to storage drivers.');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(' Ubuntu detected.');
|
||||
}
|
||||
|
||||
if (output.Architecture.toLowerCase().indexOf('x86') < 0) {
|
||||
console.log('Warning!! Default CaptainDuckDuck is compiled for X86 CPU. To use CaptainDuckDuck on other CPUs you can build from the source code');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(' X86 CPU detected.')
|
||||
}
|
||||
|
||||
@@ -66,8 +62,7 @@ function checkSystemReq() {
|
||||
|
||||
if (totalMemInMb < 1000) {
|
||||
console.log('Warning!! With less than 1GB RAM, complex Docker builds might fail, see CaptainDuckDuck system requirements.');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(' Total RAM ' + totalMemInMb + ' MB');
|
||||
}
|
||||
|
||||
@@ -166,8 +161,7 @@ function checkPortOrThrow(ipAddr, portToTest) {
|
||||
|
||||
if ((body + '') === FIREWALL_PASSED) {
|
||||
resolve();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printError();
|
||||
reject(new Error("Port seems to be closed: " + portToTest));
|
||||
}
|
||||
@@ -210,14 +204,12 @@ module.exports.install = function () {
|
||||
.catch(function (error) {
|
||||
if (error && error.statusCode === 503) {
|
||||
resolve(ip4);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return ip4;
|
||||
}
|
||||
})
|
||||
@@ -281,8 +273,7 @@ module.exports.install = function () {
|
||||
key: EnvVar.keys.CAPTAIN_DOCKER_API,
|
||||
value: EnvVar.CAPTAIN_DOCKER_API
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
volumeToMount.push({
|
||||
hostPath: CaptainConstants.dockerSocketPath,
|
||||
containerPath: CaptainConstants.dockerSocketPath
|
||||
|
||||
@@ -13,8 +13,7 @@ module.exports = {
|
||||
], function (err, result) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
@@ -41,8 +40,7 @@ module.exports = {
|
||||
], function (err, result) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user