Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const _listCatalogItems = async function () {
const _listCatalogItem = async function (obj) {
logger.info(JSON.stringify(obj));
const result = await CatalogItemService.getCatalogItem(obj.itemId, {}, true);
logger.info(JSON.stringify(result));
logger.info(JSON.stringify(result, null, 2));
logger.info('Catalog item has been successfully retrieved.');
};

Expand Down
124 changes: 74 additions & 50 deletions src/cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const config = require('../config');
const constants = require('../helpers/constants');
const AppHelper = require('../helpers/app-helper');
const ErrorMessages = require('../helpers/error-messages');
const Validator = require('../schemas');
const logger = require('../logger');

class Config extends BaseCLIHandler {
Expand Down Expand Up @@ -77,84 +78,107 @@ const _executeCase = async function (catalogCommand, commandName, f) {
};

const _addConfigOption = async function (options) {
if (options.port != null) {
await Validator.validate(options, Validator.schemas.configUpdate);

updateConfig(options.port, 'port', 'Server:Port', async (onSuccess) => {
const port = options.port;
if (!AppHelper.isValidPort(port)) {
logger.error(ErrorMessages.INVALID_PORT_FORMAT);
return;
const status = await AppHelper.checkPortAvailability(port);
if (status === 'closed') {
config.set('Server:Port', port);
onSuccess();
} else {
logger.error(AppHelper.formatMessage(ErrorMessages.PORT_NOT_AVAILABLE, port));
}
AppHelper.checkPortAvailability(port).then(availability => {
if (availability === 'closed') {
config.set('Server:Port', port);
}
else {
logger.error(AppHelper.formatMessage(ErrorMessages.PORT_NOT_AVAILABLE, port));
}
});
}
});

if (options.sslCert != null) {
updateConfig(options.sslCert, 'ssl-cert', 'Server:SslCert', (onSuccess) => {
const sslCert = options.sslCert;
if (!AppHelper.isFileExists(sslCert)) {
logger.error(ErrorMessages.INVALID_FILE_PATH);
return;
}
config.set('Server:SslCert', sslCert)
}
config.set('Server:SslCert', sslCert);
onSuccess();
});

if (options.sslKey != null) {
if (options.sslKey) {
const sslKey = options.sslKey;
if (!AppHelper.isFileExists(sslKey)) {
logger.error(ErrorMessages.INVALID_FILE_PATH);
return;
}
config.set('Server:SslKey', sslKey)
config.set('Server:SslKey', sslKey);
logger.info('Config option ssl-key has been updated.');
}

if (options.intermediateCert != null) {
updateConfig(options.intermediateCert, 'intermediate-cert', 'Server:IntermediateCert', (onSuccess) => {
const intermediateCert = options.intermediateCert;
if (!AppHelper.isFileExists(intermediateCert)) {
logger.error(ErrorMessages.INVALID_FILE_PATH);
return;
}
config.set('Server:IntermediateCert', intermediateCert)
}

if (options.emailActivationOn != null) {
config.set('Email:ActivationEnabled', true)
}

if (options.emailActivationOff != null) {
config.set('Email:ActivationEnabled', false)
}

if (options.homeUrl != null && config.get('Email:HomeUrl') !== options.homeUrl) {
config.set('Email:HomeUrl', options.homeUrl)
}

if (options.emailAddress != null && config.get('Email:Address') !== options.emailAddress) {
if (options.emailPassword == null) {
return console.log('When changing email address, password must be provided.')
config.set('Server:IntermediateCert', intermediateCert);
onSuccess();
});

updateConfig(options.emailActivationOn, 'email-activation-on', 'Email:ActivationEnabled', (onSuccess) => {
config.set('Email:ActivationEnabled', true);
onSuccess();
});

updateConfig(options.emailActivationOff, 'email-activation-off', 'Email:ActivationEnabled', (onSuccess) => {
config.set('Email:ActivationEnabled', false);
onSuccess();
});

updateConfig(options.homeUrl, 'home-url', 'Email:HomeUrl', (onSuccess) => {
config.set('Email:HomeUrl', options.homeUrl);
onSuccess();
});

updateConfig(options.emailAddress, 'email-address', 'Email:Address', (onSuccess) => {
if (options.emailPassword) {
logger.info('When changing email address, password must be provided.');
return;
}
config.set('Email:Address', options.emailAddress)
}
config.set('Email:Address', options.emailAddress);
onSuccess();
});

if (options.emailPassword != null) {
config.set('Email:Password', AppHelper.encryptText(options.emailPassword, config.get('Email:Address')))
if (options.emailPassword) {
config.set('Email:Password', AppHelper.encryptText(options.emailPassword, config.get('Email:Address')));
logger.info('Config option email-password has been updated.');
}

if (options.emailService != null) {
config.set('Email:Service', options.emailService)
}
updateConfig(options.emailService, 'email-service', 'Email:Service', (onSuccess) => {
config.set('Email:Service', options.emailService);
onSuccess();
});

if (options.logDir != null) {
config.set('Service:LogsDirectory', options.logDir)
}
updateConfig(options.logDir, 'log-dir', 'Service:LogsDirectory', (onSuccess) => {
config.set('Service:LogsDirectory', options.logDir);
onSuccess();
});

if (options.logSize != null) {
config.set('Service:LogsFileSize', options.logSize * 1024)
updateConfig(options.logSize, 'log-size', 'Service:LogsFileSize', (onSuccess) => {
config.set('Service:LogsFileSize', options.logSize * 1024);
onSuccess();
})
};

const updateConfig = async function (newConfigValue, cliConfigName, configName, fn) {
if (newConfigValue) {
const oldConfigValue = config.get(configName);
if (newConfigValue !== oldConfigValue) {
await fn(function() {
const currentConfigValue = config.get(configName);
logger.info(`Config option ${cliConfigName} has been set to ${currentConfigValue}`);
});
} else {
logger.info(`Config option ${cliConfigName} is already set to ${newConfigValue}`);
}
}
}
};

const _listConfigOptions = function () {
const configuration = {
Expand Down
8 changes: 4 additions & 4 deletions src/cli/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ const _executeCase = async function (userCommand, commandName, f, isUserRequired

const _getStatus = async function () {
const response = await ControllerService.statusController(true);
logger.info(JSON.stringify(response));
logger.info(JSON.stringify(response, null, 2));
};

const _emailActivation = async function () {
const response = await ControllerService.emailActivation(true);
logger.info(JSON.stringify(response));
logger.info(JSON.stringify(response, null, 2));
};

const _getFogTypes = async function () {
const response = await ControllerService.getFogTypes(true);
logger.info(JSON.stringify(response));
logger.info(JSON.stringify(response, null, 2));
};

const _getVersion = async function() {
const response = await ControllerService.getVersion(true);
logger.info(response);
logger.info(response, null, 2);
};

module.exports = new Controller();
2 changes: 1 addition & 1 deletion src/cli/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function _createRegistry(obj, user) {

async function _getRegistries(obj, user) {
const result = await RegistryService.findRegistries(user, true);
logger.info(JSON.stringify(result));
logger.info(JSON.stringify(result, null, 2));
logger.info('List of Registries has been received successfully.');
}

Expand Down
2 changes: 0 additions & 2 deletions src/cli/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
const BaseCLIHandler = require('./base-cli-handler');
const constants = require('../helpers/constants');
const UserService = require('../services/user-service');
const UserManager = require('../sequelize/managers/user-manager');
const logger = require('../logger');
const AppHelper = require('../helpers/app-helper');
const EmailActivationCodeService = require('../services/email-activation-code-service');
const AuthDecorator = require('../decorators/cli-decorator');
const Validator = require('../schemas');

Expand Down
6 changes: 3 additions & 3 deletions src/helpers/app-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ function generateRandomString(size) {
// Checks the status of a single port
// returns 'closed' if port is available
// returns 'open' if port is not available
function checkPortAvailability(port) {
return portscanner.checkPortStatus(port).then(function (status) {
return status;
async function checkPortAvailability(port) {
return new Promise((resolve) => {
return resolve(portscanner.checkPortStatus(port));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
EMAIL_SENDER_NOT_CONFIGURED: 'Email sender not configured',
INVALID_PORT_FORMAT: 'Invalid port format',
INVALID_FILE_PATH: 'Invalid file path',
PORT_NOT_AVAILABLE: 'Port {} not available',
PORT_NOT_AVAILABLE: 'Port {} is not available',
UNABLE_TO_WRITE_STRACE: 'Error while writing strace data to file. File name: {}, err: {}',
UNABLE_TO_DELETE_STRACE: 'Error while deleting strace data file. File name: {}, err: {}',
FTP_ERROR: 'FTP error: {}',
Expand Down
39 changes: 39 additions & 0 deletions src/schemas/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* *******************************************************************************
* * Copyright (c) 2018 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/

const configUpdate = {
"id": "/configUpdate",
"type": "object",
"properties": {
"port": {"type": "integer", "minimum" : 0, "maximum" : 65535},
"sslCert": {"type": "string"},
"sslKey": {"type": "string"},
"intermediateCert": {"type": "string"},
"emailActivationOn": {"type": "boolean"},
"emailActivationOff": {"type": "boolean"},
"homeUrl": {"type": "string"},
"emailAddress": {
"type": "string",
"pattern": "^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"
},
"emailPassword": {"type": "string", "minLength": 1},
"emailService": {"type": "string"},
"logDir": {"type": "string"},
"logSize": {"type": "integer"}
}
}

module.exports = {
mainSchemas: [configUpdate],
innerSchemas: []
};
4 changes: 2 additions & 2 deletions src/schemas/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const tunnelCreate = {
"username": {"type": "string", "minLength": 1},
"password": {"type": "string"},
"rsakey": {"type": "string"},
"lport": {"type": "integer", "minimum" : 0},
"rport": {"type": "integer", "minimum" : 0}
"lport": {"type": "integer", "minimum" : 0, "maximum" : 65535},
"rport": {"type": "integer", "minimum" : 0, "maximum" : 65535}
},
"required": ["iofogUuid", "username", "password", "lport", "rport"]
};
Expand Down