Move all urls to config

This commit is contained in:
Juan Cruz Viotti 2014-12-01 10:06:03 -04:00
parent db51ed9d1e
commit d3eac45955
6 changed files with 10 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)