diff --git a/lib/actions/keys.coffee b/lib/actions/keys.coffee index 8b5726e6..8ead5bf4 100644 --- a/lib/actions/keys.coffee +++ b/lib/actions/keys.coffee @@ -28,5 +28,6 @@ exports.info = (id) -> exports.remove = (id) -> confirmArgument = resin.cli.getArgument('yes') resin.ui.patterns.remove 'key', confirmArgument, (callback) -> - resin.server.delete("/user/keys/#{id}", callback) + url = _.template(resin.config.urls.sshKey, { id }) + resin.server.delete(url, callback) , resin.errors.handle diff --git a/lib/actions/logs.coffee b/lib/actions/logs.coffee index a17c8bb6..e2fe9052 100644 --- a/lib/actions/logs.coffee +++ b/lib/actions/logs.coffee @@ -32,7 +32,7 @@ exports.logs = (uuid) -> # all other actions from exiting on completion pubnub = PubNub.init(resin.config.pubnub) - channel = helpers.template(resin.config.events.deviceLogs, { uuid }) + channel = _.template(resin.config.events.deviceLogs, { uuid }) pubnub.history count: LOGS_HISTORY_COUNT diff --git a/lib/helpers/helpers.coffee b/lib/helpers/helpers.coffee index 7a7eb4a6..066183ca 100644 --- a/lib/helpers/helpers.coffee +++ b/lib/helpers/helpers.coffee @@ -12,6 +12,3 @@ exports.isDeviceUUIDValid = (uuid, callback) -> return callback?(error) if error? uuidExists = _.findWhere(devices, { uuid })? return callback(null, uuidExists) - -exports.template = (template, data) -> - return _.template(template, data) diff --git a/lib/helpers/helpers.spec.coffee b/lib/helpers/helpers.spec.coffee index bbd012f5..8daaf351 100644 --- a/lib/helpers/helpers.spec.coffee +++ b/lib/helpers/helpers.spec.coffee @@ -63,22 +63,3 @@ describe 'Helpers:', -> expect(error).to.not.exist expect(isValid).to.be.false done() - - describe '#template()', -> - - templateString = 'Hello, <%= name %>' - templateData = name: 'John Doe' - - it 'should call _.template', -> - templateSpy = sinon.spy(_, 'template') - helpers.template(templateString, templateData) - - expect(templateSpy).to.have.been.calledOnce - expect(templateSpy).to.have.been.calledWithExactly(templateString, templateData) - - templateSpy.restore() - - it 'should correctly compute the result', -> - result = helpers.template(templateString, templateData) - expectedResult = _.template(templateString, templateData) - expect(result).to.equal(expectedResult) diff --git a/lib/resin/config.coffee b/lib/resin/config.coffee index 0c847aff..f4608df6 100644 --- a/lib/resin/config.coffee +++ b/lib/resin/config.coffee @@ -29,9 +29,12 @@ config.urls = keys: '/user/keys' identify: '/blink' authenticate: '/login_' + applicationRestart: '/application/<%= id %>/restart' + sshKey: '/user/keys/<%= id %>' # Append config.remoteUrl before every url config.urls = _.object _.map config.urls, (value, key, object) -> - return [ key, url.resolve(config.remoteUrl, value) ] + absUrl = url.resolve(config.remoteUrl, value) + return [ key, unescape(absUrl) ] module.exports = config diff --git a/lib/resin/models/application.coffee b/lib/resin/models/application.coffee index 504a2c2e..2f7ac3d7 100644 --- a/lib/resin/models/application.coffee +++ b/lib/resin/models/application.coffee @@ -2,6 +2,7 @@ _ = require('lodash') canvas = require('./_canvas') errors = require('../errors/errors') server = require('../server/server') +config = require('../config') exports.getAll = (callback) -> return canvas.get @@ -60,6 +61,5 @@ exports.remove = (id, callback) -> return callback(error) exports.restart = (id, callback) -> - - # TODO: Move this URL to config - server.post("/application/#{id}/restart", callback) + url = _.template(config.urls.applicationRestart, { id }) + server.post(url, callback)