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
1 change: 1 addition & 0 deletions scripts/cli-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const options = {
},
}

/* eslint-disable no-unused-vars */
let testsCounter = 0
let testsFailed = 0

Expand Down
1 change: 0 additions & 1 deletion scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*
*/
const sqlite3 = require('sqlite3')// .verbose(); //use verbose in dev to get stack traces
const os = require('os')
const execSync = require('child_process').execSync
const fs = require('fs')
const semver = require('semver')
Expand Down
2 changes: 0 additions & 2 deletions scripts/preuninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*
*/

const os = require('os')
const execSync = require('child_process').execSync
const fs = require('fs')
const version = require('../package').version
const {backupDBs, backupConfigs, INSTALLATION_VARIABLES_FILE} = require('./util')
Expand Down
4 changes: 2 additions & 2 deletions src/cli/base-cli-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const commandLineUsage = require('command-line-usage')
const AppHelper = require('../helpers/app-helper')
const Errors = require('../helpers/errors')
const ErrorMessages = require('../helpers/error-messages')
const constants = require('../helpers/constants')

class CLIHandler {
constructor() {
Expand Down Expand Up @@ -172,7 +171,8 @@ class CLIHandler {
const isValidType = _validateType(expectedValueType, valType)

if (!isValidType) {
throw new Errors.InvalidArgumentTypeError(AppHelper.formatMessage(ErrorMessages.INVALID_CLI_ARGUMENT_TYPE, currentArgName, expectedValueType))
throw new Errors.InvalidArgumentTypeError(AppHelper.formatMessage(ErrorMessages.INVALID_CLI_ARGUMENT_TYPE,
currentArgName, expectedValueType))
}
})
}
Expand Down
6 changes: 0 additions & 6 deletions src/cli/cli-data-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@
*
*/

/**
* @return {number}
*/
function Integer(value) {
return Number(value)
}

/**
* @return {number}
*/
function Float(value) {
return Number(value)
}
Expand Down
1 change: 0 additions & 1 deletion src/cli/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const BaseCLIHandler = require('./base-cli-handler')
const constants = require('../helpers/constants')
const ControllerService = require('../services/controller-service')
const logger = require('../logger')
const AppHelper = require('../helpers/app-helper')


class Controller extends BaseCLIHandler {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ class Microservice extends BaseCLIHandler {
},
{
desc: '2. Multiple mappings',
example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src:rw /host_bin:/container_bin:r',
example: '$ iofog-controller microservice add [other required options] --volumes /host_src:/container_src:rw ' +
'/host_bin:/container_bin:r',
},
{
desc: '3. Port mapping (80:8080:false - internal port : external port : public mode)',
Expand Down
3 changes: 2 additions & 1 deletion src/cli/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function checkDaemon(daemon, configuration) {
iterationsCount++
const pid = daemon.status()
if (pid === 0) {
return logger.error('Error: port is probably allocated, or ssl_key or ssl_cert or intermediate_cert is either missing or invalid.')
return logger.error('Error: port is probably allocated, or ssl_key or ssl_cert or intermediate_cert ' +
'is either missing or invalid.')
}

if (iterationsCount === 5) {
Expand Down
1 change: 0 additions & 1 deletion src/cli/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const TunnelService = require('../services/tunnel-service')
const CliDecorator = require('../decorators/cli-decorator')
const Errors = require('../helpers/errors')
const ErrorMessages = require('../helpers/error-messages')
const AppHelper = require('../helpers/app-helper')
const CliDataTypes = require('./cli-data-types')

class Tunnel extends BaseCLIHandler {
Expand Down
16 changes: 8 additions & 8 deletions src/decorators/authorization-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ const Errors = require('../helpers/errors')
const {isTest} = require('../helpers/app-helper')

function checkAuthToken(f) {
return async function() {
return async function(...fArgs) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, fArgs)
}

const fArgs = Array.prototype.slice.call(arguments)
const req = fArgs[0]
const token = req.headers.authorization

Expand All @@ -41,18 +40,18 @@ function checkAuthToken(f) {
}

fArgs.push(user)
AccessTokenManager.updateExpirationTime(user.accessToken.id, user.accessToken.expirationTime + config.get('Settings:UserTokenExpirationIntervalSeconds') * 1000)
AccessTokenManager.updateExpirationTime(user.accessToken.id, user.accessToken.expirationTime
+ config.get('Settings:UserTokenExpirationIntervalSeconds') * 1000)
return await f.apply(this, fArgs)
}
}

function checkFogToken(f) {
return async function() {
return async function(...fArgs) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, fArgs)
}

const fArgs = Array.prototype.slice.call(arguments)
const req = fArgs[0]
const token = req.headers.authorization

Expand All @@ -69,7 +68,8 @@ function checkFogToken(f) {

fArgs.push(fog)

FogAccessTokenManager.updateExpirationTime(fog.accessToken.id, fog.accessToken.expirationTime + config.get('Settings:FogTokenExpirationIntervalSeconds') * 1000)
FogAccessTokenManager.updateExpirationTime(fog.accessToken.id, fog.accessToken.expirationTime
+ config.get('Settings:FogTokenExpirationIntervalSeconds') * 1000)

const timestamp = Date.now()
await FogManager.updateLastActive(fog.uuid, timestamp)
Expand Down
14 changes: 6 additions & 8 deletions src/decorators/cli-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
*/

const logger = require('../logger')
const config = require('../config')
const UserManager = require('../sequelize/managers/user-manager')
const AccessTokenManager = require('../sequelize/managers/access-token-manager')
const Errors = require('../helpers/errors')
const {isTest} = require('../helpers/app-helper')

function prepareUserById(f) {
return async function() {
return async function(...args) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, args)
}

const fArgs = Array.prototype.slice.call(arguments)
const fArgs = Array.prototype.slice.call(args)
const obj = fArgs[0]
const userId = obj.userId

Expand All @@ -41,12 +39,12 @@ function prepareUserById(f) {
}

function prepareUserByEmail(f) {
return async function() {
return async function(...args) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, args)
}

const fArgs = Array.prototype.slice.call(arguments)
const fArgs = Array.prototype.slice.call(args)
const obj = fArgs[0]
const email = obj.email

Expand Down
6 changes: 3 additions & 3 deletions src/decorators/response-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const logger = require('../logger')
const {isTest} = require('../helpers/app-helper')

function handleErrors(f, successCode, errorsCodes) {
return async function() {
return async function(...args) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, args)
}

let responseObject = {}
try {
const responseBody = await f.apply(this, arguments)
const responseBody = await f.apply(this, args)
responseObject = {code: successCode, body: responseBody}
} catch (err) {
logger.error('error: ' + err)
Expand Down
7 changes: 3 additions & 4 deletions src/decorators/tracking-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ const {isTest} = require('../helpers/app-helper')
const Tracking = require('../tracking')

function trackEvent(f, eventType) {
return async function() {
return async function(...fArgs) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, fArgs)
}

const fArgs = Array.prototype.slice.call(arguments)
const res = await f.apply(this, arguments)
const res = await f.apply(this, fArgs)
const event = Tracking.buildEvent(eventType, res, fArgs, f.name)
await Tracking.processEvent(event, fArgs, res)
return res
Expand Down
19 changes: 8 additions & 11 deletions src/decorators/transaction-decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ const Transaction = require('sequelize/lib/transaction')
const {isTest} = require('../helpers/app-helper')

function transaction(f) {
return async function() {
return async function(...fArgs) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, fArgs)
}

const fArgs = Array.prototype.slice.call(arguments)
// TODO [when transactions concurrency issue fixed]: Remove 'fArgs[fArgs.length - 1].fakeTransaction'
if (fArgs.length > 0 && fArgs[fArgs.length - 1] && (fArgs[fArgs.length - 1] instanceof Transaction || fArgs[fArgs.length - 1].fakeTransaction)) {
if (fArgs.length > 0 && fArgs[fArgs.length - 1]
&& (fArgs[fArgs.length - 1] instanceof Transaction || fArgs[fArgs.length - 1].fakeTransaction)) {
return await f.apply(this, fArgs)
} else {
// return f.apply(this, fArgs)
Expand All @@ -38,8 +38,7 @@ function transaction(f) {
}

function generateTransaction(f) {
return function() {
const args = Array.prototype.slice.call(arguments)
return function(...args) {
return retry(() => {
const t = transaction(f)
return t.apply(this, args)
Expand All @@ -55,12 +54,11 @@ function generateTransaction(f) {

function fakeTransaction(f) {
const fakeTransactionObject = {fakeTransaction: true}
return async function() {
return async function(...fArgs) {
if (isTest()) {
return await f.apply(this, arguments)
return await f.apply(this, fArgs)
}

const fArgs = Array.prototype.slice.call(arguments)
if (fArgs.length > 0 && fArgs[fArgs.length - 1] instanceof Transaction) {
fArgs[fArgs.length - 1] = fakeTransactionObject
return await f.apply(this, fArgs)
Expand All @@ -73,8 +71,7 @@ function fakeTransaction(f) {

// TODO [when transactions concurrency issue fixed]: Remove
function generateFakeTransaction(f) {
return function() {
const args = Array.prototype.slice.call(arguments)
return function(...args) {
return retry(() => {
const t = fakeTransaction(f)
return t.apply(this, args)
Expand Down
7 changes: 3 additions & 4 deletions src/helpers/app-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

const crypto = require('crypto')
const Errors = require('./errors')
const ErrorMessages = require('./error-messages')

const logger = require('../logger')
const fs = require('fs')
Expand Down Expand Up @@ -105,6 +104,7 @@ function isValidDomain(domain) {
}

const isValidPublicIP = function(publicIP) {
/* eslint-disable max-len */
const re = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$|^\s*((([0-9A-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up @@ -150,9 +150,8 @@ function validateBooleanCliOptions(trueOption, falseOption) {
return trueOption ? true : (falseOption ? false : undefined)
}

function formatMessage() {
const argsArray = Array.prototype.slice.call(arguments)
return format.apply(null, argsArray)
function formatMessage(...args) {
return format(...args)
}

function stringifyCliJsonSchema(json) {
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ module.exports = {
ACCOUNT_NOT_FOUND: 'Account not found',
USER_NOT_UPDATED: 'User not updated',
EMAIL_NOT_ACTIVATED: 'Email is not activated. Please activate your account first.',
REGISTRATION_FAILED: 'Registration failed: There is already an account associated with your email address. Please try logging in instead.',
REGISTRATION_FAILED: 'Registration failed: There is already an account associated with your email address. ' +
'Please try logging in instead.',
INVALID_PROVISIONING_KEY: 'Invalid Provisioning Key',
EMAIL_SENDER_NOT_CONFIGURED: 'Email sender not configured',
INVALID_PORT_FORMAT: 'Invalid port format',
Expand All @@ -48,7 +49,8 @@ module.exports = {
STRACE_WITHOUT_FOG: 'Can\'t run strace for microservice without ioFog.',
INVALID_ACTION_PROPERTY: 'Unknown action property. Action can be "open" or "close"',
IMAGE_SNAPSHOT_NOT_FOUND: 'Image snapshot not found',
INVALID_MICROSERVICES_FOG_TYPE: 'Some of microservices haven\'t proper docker images for this ioFog type. List of invalid microservices:\n',
INVALID_MICROSERVICES_FOG_TYPE: 'Some of microservices haven\'t proper docker images for this ioFog type. ' +
'List of invalid microservices:\n',
INVALID_MICROSERVICE_CONFIG: 'Can\'t create network microservice without appropriate configuration.',
INVALID_MICROSERVICE_USER: 'Invalid microservice user or UUID',
ROUTE_NOT_FOUND: 'Route not found',
Expand Down
1 change: 0 additions & 1 deletion src/jobs/send-tracking-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

const BaseJobHandler = require('./base/base-job-handler')
const Tracking = require('../tracking')
const TrackingEventType = require('../enums/tracking-event-type')
const TrackingEventManager = require('../sequelize/managers/tracking-event-manager')

class SendTrackingJob extends BaseJobHandler {
Expand Down
1 change: 0 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if (!process.env.NODE_ENV) {
}

const Cli = require('./cli')
const logger = require('./logger')
const daemon = require('./daemon')

function main() {
Expand Down
Loading