From 9529e6c335e7b53d78220b193ffa5f3f2f19ba95 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 26 Nov 2014 13:42:05 -0400 Subject: [PATCH] Move config to resin module --- lib/actions/app.coffee | 1 - lib/actions/auth.coffee | 3 +-- lib/actions/device.coffee | 3 +-- lib/actions/keys.coffee | 7 +++---- lib/actions/preferences.coffee | 3 +-- lib/app.coffee | 3 +-- lib/fs-utils/fs-utils.spec.coffee | 5 ++--- lib/hooks/auth.spec.coffee | 5 ++--- lib/resin/auth/auth.spec.coffee | 2 +- lib/{ => resin}/config.coffee | 0 lib/resin/data/data-prefix.spec.coffee | 2 +- lib/resin/data/data.spec.coffee | 2 +- lib/resin/index.coffee | 1 + lib/resin/models/_canvas.coffee | 2 +- lib/resin/models/_canvas.spec.coffee | 2 +- lib/resin/server/server.coffee | 2 +- lib/resin/server/server.spec.coffee | 2 +- lib/resin/token/token.spec.coffee | 2 +- tests/utils/mock.coffee | 4 ++-- 19 files changed, 22 insertions(+), 29 deletions(-) rename lib/{ => resin}/config.coffee (100%) diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index 55e48a31..a59d16fd 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -2,7 +2,6 @@ _ = require('lodash') async = require('async') resin = require('../resin') authHooks = require('../hooks/auth') -config = require('../config') exports.create = authHooks.failIfNotLoggedIn (name, program) -> async.waterfall [ diff --git a/lib/actions/auth.coffee b/lib/actions/auth.coffee index 35567dad..0d31c006 100644 --- a/lib/actions/auth.coffee +++ b/lib/actions/auth.coffee @@ -2,7 +2,6 @@ open = require('open') async = require('async') resin = require('../resin') authHooks = require('../hooks/auth') -config = require('../config') exports.login = (credentials) -> async.waterfall [ @@ -22,4 +21,4 @@ exports.logout = authHooks.failIfNotLoggedIn -> resin.auth.logout() exports.signup = -> - open(config.urls.signup) + open(resin.config.urls.signup) diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 4bdd797f..88fe4904 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -1,6 +1,5 @@ resin = require('../resin') authHooks = require('../hooks/auth') -config = require('../config') exports.list = authHooks.failIfNotLoggedIn (applicationId) -> resin.models.device.getAll(applicationId).then (devices) -> @@ -25,4 +24,4 @@ exports.remove = authHooks.failIfNotLoggedIn (id, program) -> , resin.errors.handle exports.identify = authHooks.failIfNotLoggedIn (uuid) -> - resin.server.post(config.urls.identify, { uuid }, resin.errors.handle) + resin.server.post(resin.config.urls.identify, { uuid }, resin.errors.handle) diff --git a/lib/actions/keys.coffee b/lib/actions/keys.coffee index 925dda3a..534552d3 100644 --- a/lib/actions/keys.coffee +++ b/lib/actions/keys.coffee @@ -2,10 +2,9 @@ _ = require('lodash') resin = require('../resin') authHooks = require('../hooks/auth') helpers = require('../helpers/helpers') -config = require('../config') exports.list = authHooks.failIfNotLoggedIn -> - resin.server.get config.urls.keys, (error, response, keys) -> + resin.server.get resin.config.urls.keys, (error, response, keys) -> resin.errors.handle(error) if error? resin.log.out resin.ui.widgets.table.horizontal keys, (key) -> delete key.public_key @@ -18,13 +17,13 @@ exports.info = authHooks.failIfNotLoggedIn (id) -> # TODO: We don't have a way to query a single ssh key yet. # As a workaround, we request all of them, and filter # the one we need. Fix once we have a better way. - resin.server.get config.urls.keys, (error, response, keys) -> + resin.server.get resin.config.urls.keys, (error, response, keys) -> resin.errors.handle(error) if error? key = _.findWhere(keys, { id }) if not key? resin.errors.handle(new resin.errors.NotFound("key #{id}")) - key.public_key = '\n' + helpers.formatLongString(key.public_key, config.sshKeyWidth) + key.public_key = '\n' + helpers.formatLongString(key.public_key, resin.config.sshKeyWidth) resin.log.out(resin.ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ])) exports.remove = authHooks.failIfNotLoggedIn (id, program) -> diff --git a/lib/actions/preferences.coffee b/lib/actions/preferences.coffee index 8caa41f8..028ccf68 100644 --- a/lib/actions/preferences.coffee +++ b/lib/actions/preferences.coffee @@ -1,6 +1,5 @@ open = require('open') -config = require('../config') authHooks = require('../hooks/auth') exports.preferences = authHooks.failIfNotLoggedIn -> - open(config.urls.preferences) + open(resin.config.urls.preferences) diff --git a/lib/app.coffee b/lib/app.coffee index a439c5ae..305b2ae1 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -1,6 +1,5 @@ _ = require('lodash') resin = require('./resin') -config = require('./config') packageJSON = require('../package.json') program = require('commander') @@ -126,7 +125,7 @@ program .description('Remove environment variable') .action(env.remove) -resin.data.prefix.set config.dataPrefix, (error) -> +resin.data.prefix.set resin.config.dataPrefix, (error) -> throw error if error? program.parse(process.argv) resin.log.setQuiet(program.quiet) diff --git a/lib/fs-utils/fs-utils.spec.coffee b/lib/fs-utils/fs-utils.spec.coffee index d817e2db..1b4276f4 100644 --- a/lib/fs-utils/fs-utils.spec.coffee +++ b/lib/fs-utils/fs-utils.spec.coffee @@ -1,7 +1,6 @@ expect = require('chai').expect mock = require('../../tests/utils/mock') fsUtils = require('./fs-utils') -config = require('../config') resin = require('../resin') FILESYSTEM = @@ -30,7 +29,7 @@ describe 'FsUtils:', -> it 'should return true for valid paths', -> for validPath in [ - config.dataPrefix + resin.config.dataPrefix '/Users/johndoe' '../parent' './file/../file2' @@ -41,7 +40,7 @@ describe 'FsUtils:', -> beforeEach (done) -> mock.fs.init(FILESYSTEM) - resin.data.prefix.set(config.dataPrefix, done) + resin.data.prefix.set(resin.config.dataPrefix, done) afterEach -> mock.fs.restore() diff --git a/lib/hooks/auth.spec.coffee b/lib/hooks/auth.spec.coffee index 8a42b5b1..4c61c764 100644 --- a/lib/hooks/auth.spec.coffee +++ b/lib/hooks/auth.spec.coffee @@ -2,7 +2,6 @@ _ = require('lodash') nock = require('nock') sinon = require('sinon') expect = require('chai').expect -config = require('../config') resin = require('../resin') authHooks = require('./auth') johnDoeFixture = require('../../tests/fixtures/johndoe') @@ -20,7 +19,7 @@ describe 'Auth Hooks:', -> beforeEach (done) -> mock.fs.init() - resin.data.prefix.set(config.dataPrefix, done) + resin.data.prefix.set(resin.config.dataPrefix, done) afterEach -> mock.fs.restore() @@ -58,7 +57,7 @@ describe 'Auth Hooks:', -> describe 'if logged in', -> beforeEach (done) -> - nock(config.remoteUrl) + nock(resin.config.remoteUrl) .post('/login_', johnDoeFixture.credentials) .reply(200, johnDoeFixture.token) diff --git a/lib/resin/auth/auth.spec.coffee b/lib/resin/auth/auth.spec.coffee index fd84f66d..8c018d38 100644 --- a/lib/resin/auth/auth.spec.coffee +++ b/lib/resin/auth/auth.spec.coffee @@ -4,7 +4,7 @@ _ = require('lodash') async = require('async') auth = require('./auth') data = require('../data/data') -config = require('../../config') +config = require('../config') mock = require('../../../tests/utils/mock') johnDoeFixture = require('../../../tests/fixtures/johndoe') janeDoeFixture = require('../../../tests/fixtures/janedoe') diff --git a/lib/config.coffee b/lib/resin/config.coffee similarity index 100% rename from lib/config.coffee rename to lib/resin/config.coffee diff --git a/lib/resin/data/data-prefix.spec.coffee b/lib/resin/data/data-prefix.spec.coffee index a960cf49..ef2a9037 100644 --- a/lib/resin/data/data-prefix.spec.coffee +++ b/lib/resin/data/data-prefix.spec.coffee @@ -5,7 +5,7 @@ fs = require('fs') fsUtils = require('../../fs-utils/fs-utils') rimraf = require('rimraf') dataPrefix = require('./data-prefix') -config = require('../../config') +config = require('../config') mock = require('../../../tests/utils/mock') PREFIXES = diff --git a/lib/resin/data/data.spec.coffee b/lib/resin/data/data.spec.coffee index fc8a4c74..566120cd 100644 --- a/lib/resin/data/data.spec.coffee +++ b/lib/resin/data/data.spec.coffee @@ -3,7 +3,7 @@ _ = require('lodash') fsUtils = require('../../fs-utils/fs-utils') mock = require('../../../tests/utils/mock') async = require('async') -config = require('../../config') +config = require('../config') data = require('./data') FILES_FIXTURES = diff --git a/lib/resin/index.coffee b/lib/resin/index.coffee index de7a547d..f5f0decb 100644 --- a/lib/resin/index.coffee +++ b/lib/resin/index.coffee @@ -8,3 +8,4 @@ module.exports = auth: require('./auth/auth') device: require('./device/device') ui: require('./ui') + config: require('./config') diff --git a/lib/resin/models/_canvas.coffee b/lib/resin/models/_canvas.coffee index bf2ec1f6..144b6010 100644 --- a/lib/resin/models/_canvas.coffee +++ b/lib/resin/models/_canvas.coffee @@ -1,7 +1,7 @@ _ = require('lodash') Canvas = require('resin-platform-api') Promise = require('bluebird') -config = require('../../config') +config = require('../config') server = require('../server/server') promisifiedServerRequest = Promise.promisify(server.request, server) diff --git a/lib/resin/models/_canvas.spec.coffee b/lib/resin/models/_canvas.spec.coffee index b2660e1a..481c22ee 100644 --- a/lib/resin/models/_canvas.spec.coffee +++ b/lib/resin/models/_canvas.spec.coffee @@ -9,7 +9,7 @@ chai.use(chaiAsPromised) data = require('../data/data') mock = require('../../../tests/utils/mock') canvas = require('./_canvas') -config = require('../../config') +config = require('../config') URI = application: url.resolve(config.apiPrefix, 'application') diff --git a/lib/resin/server/server.coffee b/lib/resin/server/server.coffee index fd81ff9e..a1d041e7 100644 --- a/lib/resin/server/server.coffee +++ b/lib/resin/server/server.coffee @@ -3,7 +3,7 @@ request = require('request') urlResolve = require('url').resolve async = require('async') connection = require('../../connection/connection') -config = require('../../config') +config = require('../config') token = require('../token/token') exports.request = (options = {}, callback) -> diff --git a/lib/resin/server/server.spec.coffee b/lib/resin/server/server.spec.coffee index df093408..ed7259e3 100644 --- a/lib/resin/server/server.spec.coffee +++ b/lib/resin/server/server.spec.coffee @@ -2,7 +2,7 @@ expect = require('chai').expect nock = require('nock') url = require('url') server = require('./server') -config = require('../../config') +config = require('../config') token = require('../token/token') data = require('../data/data') mock = require('../../../tests/utils/mock') diff --git a/lib/resin/token/token.spec.coffee b/lib/resin/token/token.spec.coffee index ec2f9251..9485ddf6 100644 --- a/lib/resin/token/token.spec.coffee +++ b/lib/resin/token/token.spec.coffee @@ -1,7 +1,7 @@ expect = require('chai').expect async = require('async') token = require('./token') -config = require('../../config') +config = require('../config') data = require('../data/data') mock = require('../../../tests/utils/mock') diff --git a/tests/utils/mock.coffee b/tests/utils/mock.coffee index f649c6d2..32f27d7f 100644 --- a/tests/utils/mock.coffee +++ b/tests/utils/mock.coffee @@ -1,6 +1,6 @@ mockFs = require('mock-fs') sinon = require('sinon') -config = require('../../lib/config') +resin = require('../../lib/resin') connection = require('../../lib/connection/connection') exports.fs = @@ -10,7 +10,7 @@ exports.fs = # Mock data prefix automatically to remove # duplication in most of the tests - mockFsOptions[config.dataPrefix] = mockFs.directory() + mockFsOptions[resin.config.dataPrefix] = mockFs.directory() for key, value of filesystemConfig mockFsOptions[value.name] = value.contents