Move all configuration variables to a separate file

This commit is contained in:
Petros Angelatos 2014-05-12 00:15:10 +01:00 committed by Pablo Carranza Vélez
parent 5caace400f
commit ca736233e7
3 changed files with 13 additions and 6 deletions

View File

@ -3,6 +3,7 @@ es = require 'event-stream'
url = require 'url'
knex = require './db'
path = require 'path'
config = require './config'
Docker = require 'dockerode'
PUBNUB = require 'pubnub'
Promise = require 'bluebird'
@ -10,7 +11,7 @@ JSONStream = require 'JSONStream'
PlatformAPI = require 'resin-platform-api/request'
DOCKER_SOCKET = '/run/docker.sock'
PLATFORM_ENDPOINT = url.resolve(process.env.API_ENDPOINT, '/ewa/')
PLATFORM_ENDPOINT = url.resolve(config.apiEndpoint, '/ewa/')
resinAPI = new PlatformAPI(PLATFORM_ENDPOINT)
docker = Promise.promisifyAll(new Docker(socketPath: DOCKER_SOCKET))
@ -18,10 +19,7 @@ docker = Promise.promisifyAll(new Docker(socketPath: DOCKER_SOCKET))
Promise.promisifyAll(docker.getImage().__proto__)
Promise.promisifyAll(docker.getContainer().__proto__)
pubnub = PUBNUB.init(
subscribe_key: 'sub-c-bananas'
publish_key: 'pub-c-bananas'
)
pubnub = PUBNUB.init(config.pubnub)
publish = null

View File

@ -5,6 +5,7 @@ url = require 'url'
knex = require './db'
utils = require './utils'
crypto = require 'crypto'
config = require './config'
csrgen = Promise.promisify require 'csr-gen'
request = Promise.promisify require 'request'
@ -51,7 +52,7 @@ module.exports = ->
config.version = version
return request(
method: 'POST'
url: url.resolve(process.env.API_ENDPOINT, 'associate')
url: url.resolve(config.apiEndpoint, 'associate')
json: config
)
.spread (response, body) ->

8
src/config.coffee Normal file
View File

@ -0,0 +1,8 @@
module.exports = config =
apiEndpoint: process.env.API_ENDPOINT
registryEndpoint: process.env.REGISTRY_ENDPOINT
pubnub:
subscribe_key: process.env.PUBNUB_SUBSCRIBE_KEY
publish_key: process.env.PUBNUB_PUBLISH_KEY
# TODO add a check that all variables are set and notify the user if not