From d64d41383801c6489588e56bb3208a6f1192a9dd Mon Sep 17 00:00:00 2001 From: Kostas Lekkas Date: Thu, 16 Jun 2016 18:47:12 +0300 Subject: [PATCH] Remove unused vars and fix linting issues --- src/api.coffee | 3 +-- src/application.coffee | 6 +++--- src/bootstrap.coffee | 6 ++---- src/config.coffee | 4 ++-- src/device.coffee | 28 ++++++++++++++-------------- src/docker-utils.coffee | 5 ++--- src/utils.coffee | 2 -- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/api.coffee b/src/api.coffee index 2092e9a7..69cbd461 100644 --- a/src/api.coffee +++ b/src/api.coffee @@ -1,5 +1,4 @@ Promise = require 'bluebird' -fs = Promise.promisifyAll require 'fs' utils = require './utils' knex = require './db' express = require 'express' @@ -52,7 +51,7 @@ module.exports = (application) -> request.post(config.gosuperAddress + '/v1/shutdown') .pipe(res) - parsedRouter.post '/v1/purge',(req, res) -> + parsedRouter.post '/v1/purge', (req, res) -> appId = req.body.appId utils.mixpanelTrack('Purge /data', appId) if !appId? diff --git a/src/application.coffee b/src/application.coffee index b76a9b0c..40816822 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -92,7 +92,7 @@ logSystemEvent = (logType, app, error) -> if _.isEmpty(errMessage) errMessage = 'Unknown cause' message += " due to '#{errMessage}'" - logSystemMessage(message, {app, error}, logType.eventName) + logSystemMessage(message, { app, error }, logType.eventName) return logSpecialAction = (action, value, success) -> @@ -100,7 +100,7 @@ logSpecialAction = (action, value, success) -> msg = "Applied config variable #{action} = #{value}" else msg = "Applying config variable #{action} = #{value}" - logSystemMessage(msg, {}, "Apply special action #{success ? "success" : "in progress"}") + logSystemMessage(msg, {}, "Apply special action #{if success then "success" else "in progress"}") application = {} @@ -694,7 +694,7 @@ application.initialize = -> .catch (error) -> console.error('Error starting apps:', error) .then -> - utils.mixpanelTrack('Start application update poll', {interval: config.appUpdatePollInterval}) + utils.mixpanelTrack('Start application update poll', { interval: config.appUpdatePollInterval }) application.poll() application.update() diff --git a/src/bootstrap.coffee b/src/bootstrap.coffee index 10ca2002..8a3895a6 100644 --- a/src/bootstrap.coffee +++ b/src/bootstrap.coffee @@ -1,11 +1,9 @@ Promise = require 'bluebird' -_ = require 'lodash' knex = require './db' utils = require './utils' deviceRegister = require 'resin-register-device' { resinApi } = require './request' fs = Promise.promisifyAll(require('fs')) -EventEmitter = require('events').EventEmitter config = require './config' configPath = '/boot/config.json' appsPath = '/boot/apps.json' @@ -27,7 +25,7 @@ loadPreloadedApps = -> app.env = JSON.stringify(extendedEnv) knex('app').insert(app) .catch (err) -> - utils.mixpanelTrack('Loading preloaded apps failed', {error: err}) + utils.mixpanelTrack('Loading preloaded apps failed', { error: err }) bootstrap = -> Promise.try -> @@ -87,7 +85,7 @@ readConfigAndEnsureUUID = -> bootstrapOrRetry = -> utils.mixpanelTrack('Device bootstrap') bootstrap().catch (err) -> - utils.mixpanelTrack('Device bootstrap failed, retrying', {error: err, delay: config.bootstrapRetryDelay}) + utils.mixpanelTrack('Device bootstrap failed, retrying', { error: err, delay: config.bootstrapRetryDelay }) setTimeout(bootstrapOrRetry, config.bootstrapRetryDelay) bootstrapper.done = new Promise (resolve) -> diff --git a/src/config.coffee b/src/config.coffee index 1d044224..ce27d41d 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -17,7 +17,7 @@ checkString = (s) -> dockerRoot = checkString(process.env.DOCKER_ROOT) ? '/mnt/root/var/lib/rce' # Defaults needed for both gosuper and node supervisor are declared in entry.sh -module.exports = config = +module.exports = apiEndpoint: checkString(process.env.API_ENDPOINT) ? 'https://api.resin.io' apiTimeout: checkInt(process.env.API_TIMEOUT) ? 15 * 60 * 1000 listenPort: checkInt(process.env.LISTEN_PORT) ? 80 @@ -48,4 +48,4 @@ module.exports = config = 'RESIN_SUPERVISOR_API_KEY' 'RESIN_API_KEY' ] - dataPath: checkString(process.env.RESIN_DATA_PATH) ? "/resin-data" + dataPath: checkString(process.env.RESIN_DATA_PATH) ? '/resin-data' diff --git a/src/device.coffee b/src/device.coffee index b64ce454..332d553c 100644 --- a/src/device.coffee +++ b/src/device.coffee @@ -20,7 +20,7 @@ exports.getID = do -> knex('config').select('value').where(key: 'apiKey') knex('config').select('value').where(key: 'uuid') ]) - .spread ([{value: apiKey}], [{value: uuid}]) -> + .spread ([{ value: apiKey }], [{ value: uuid }]) -> resinApi.get( resource: 'device' options: @@ -35,10 +35,10 @@ exports.getID = do -> throw new Error('Could not find this device?!') return devices[0].id -exports.reboot = rebootDevice = -> +exports.reboot = -> request.postAsync(config.gosuperAddress + '/v1/reboot') -exports.hostConfigEnvVarPrefix = hostConfigEnvVarPrefix = 'RESIN_HOST_' +exports.hostConfigEnvVarPrefix = 'RESIN_HOST_' bootConfigEnvVarPrefix = 'RESIN_HOST_CONFIG_' bootBlockDevice = '/dev/mmcblk0p1' bootMountPoint = '/mnt/root/boot' @@ -77,17 +77,17 @@ exports.setHostConfig = (env, logMessage) -> setLogToDisplay = (env, logMessage) -> if env['RESIN_HOST_LOG_TO_DISPLAY']? enable = env['RESIN_HOST_LOG_TO_DISPLAY'] != '0' - request.postAsync(config.gosuperAddress + '/v1/set-log-to-display', {json: true, body: Enable: enable}) + request.postAsync(config.gosuperAddress + '/v1/set-log-to-display', { json: true, body: Enable: enable }) .spread (response, body) -> if response.statusCode != 200 - logMessage("Error setting log to display: #{body.Error}, Status:, #{response.statusCode}", {error: body.Error}, "Set log to display error") + logMessage("Error setting log to display: #{body.Error}, Status:, #{response.statusCode}", { error: body.Error }, 'Set log to display error') return false else if body.Data == true - logMessage("#{if enable then "Enabled" else "Disabled"} logs to display") + logMessage("#{if enable then 'Enabled' else 'Disabled'} logs to display") return body.Data .catch (err) -> - logMessage("Error setting log to display: #{err}", {error: err}, "Set log to display error") + logMessage("Error setting log to display: #{err}", { error: err }, 'Set log to display error') return false else return Promise.resolve(false) @@ -118,7 +118,7 @@ setBootConfig = (env, logMessage) -> configFromApp[key] != configFromFS[key] throw new Error('Nothing to change') if _.isEmpty(toBeChanged) and _.isEmpty(toBeAdded) - logMessage("Applying boot config: #{JSON.stringify(configFromApp)}", {}, "Apply boot config in progress") + logMessage("Applying boot config: #{JSON.stringify(configFromApp)}", {}, 'Apply boot config in progress') # We add the keys to be added first so they are out of any filters outputConfig = _.map toBeAdded, (key) -> "#{key}=#{configFromApp[key]}" outputConfig = outputConfig.concat _.map configPositions, (key, index) -> @@ -137,10 +137,10 @@ setBootConfig = (env, logMessage) -> .then -> execAsync('sync') .then -> - logMessage("Applied boot config: #{JSON.stringify(configFromApp)}", {}, "Apply boot config success") + logMessage("Applied boot config: #{JSON.stringify(configFromApp)}", {}, 'Apply boot config success') return true .catch (err) -> - logMessage("Error setting boot config: #{err}", {error: err}, "Apply boot config error") + logMessage("Error setting boot config: #{err}", { error: err }, 'Apply boot config error') throw err .catch (err) -> console.log('Will not set boot config: ', err) @@ -175,7 +175,7 @@ do -> applyPromise = Promise.join( knex('config').select('value').where(key: 'apiKey') device.getID() - ([{value: apiKey}], deviceID) -> + ([{ value: apiKey }], deviceID) -> stateDiff = getStateDiff() if _.size(stateDiff) is 0 || !apiKey? return @@ -190,7 +190,7 @@ do -> _.merge(actualState, stateDiff) ) .catch (error) -> - utils.mixpanelTrack('Device info update failure', {error, stateDiff}) + utils.mixpanelTrack('Device info update failure', { error, stateDiff }) # Delay 5s before retrying a failed update Promise.delay(5000) .finally -> @@ -221,7 +221,7 @@ do -> exports.getOSVersion = -> fs.readFileAsync(config.hostOsVersionPath) .then (releaseData) -> - lines = (new String(releaseData)).split("\n") + lines = (new String(releaseData)).split('\n') releaseItems = {} for line in lines [ key, val ] = line.split('=') @@ -229,5 +229,5 @@ exports.getOSVersion = -> # Remove enclosing quotes: http://stackoverflow.com/a/19156197/2549019 return releaseItems['PRETTY_NAME'].replace(/^"(.+(?="$))"$/, '$1') .catch (err) -> - console.log("Could not get OS Version: ", err, err.stack) + console.log('Could not get OS Version: ', err, err.stack) return undefined diff --git a/src/docker-utils.coffee b/src/docker-utils.coffee index 1d0049ca..b6c5c9e0 100644 --- a/src/docker-utils.coffee +++ b/src/docker-utils.coffee @@ -7,7 +7,6 @@ config = require './config' _ = require 'lodash' knex = require './db' { request } = require './request' -fs = Promise.promisifyAll require 'fs' Lock = require 'rwlock' docker = Promise.promisifyAll(new Docker(socketPath: config.dockerSocket)) @@ -50,7 +49,7 @@ DELTA_REQUEST_TIMEOUT = 15 * 60 * 1000 getRepoAndTag = (image) -> getRegistryAndName(image) .then ({ registry, imageName, tagName }) -> - registry = registry.toString().replace(':443','') + registry = registry.toString().replace(':443', '') return { repo: "#{registry}/#{imageName}", tag: tagName } do -> @@ -183,7 +182,7 @@ do -> _.omit(query, 'apikey') exports.createImage = (req, res) -> - { registry, repo, tag, fromImage, fromSrc } = req.query + { registry, repo, tag, fromImage } = req.query if fromImage? repoTag = fromImage repoTag += ':' + tag if tag? diff --git a/src/utils.coffee b/src/utils.coffee index f0310fc7..92f71217 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -11,8 +11,6 @@ randomHexString = require './lib/random-hex-string' request = Promise.promisifyAll require 'request' logger = require './lib/logger' -utils = exports - # Parses package.json and returns resin-supervisor's version version = require('../package.json').version tagExtra = process.env.SUPERVISOR_TAG_EXTRA