nanocyte-configuration-generator
Version:
Generate Nanocyte configuration from an Octoblu flow
36 lines (29 loc) • 981 B
text/coffeescript
s3 = require 's3'
jsonfile = require 'jsonfile'
_ = require 'lodash'
CHANNEL_S3_BUCKET = 'octoblu-channels'
CHANNEL_S3_KEY = 'channels.json'
class ChannelConfig
constructor: (options, dependencies={}) ->
{,} = dependencies
?= jsonfile
?= s3.createClient
s3Options:
accessKeyId: options.accessKeyId
secretAccessKey: options.secretAccessKey
fetch: (callback) =>
downloader = .downloadFile
localFile: './channels.json'
s3Params:
Bucket: CHANNEL_S3_BUCKET
Key: CHANNEL_S3_KEY
downloader.on 'error', callback
downloader.on 'end', =>
.readFile './channels.json', (error, channels) =>
return callback error if error?
= channels
callback()
get: (type) =>
throw new Error 'Cannot call get before fetch' unless ?
_.findWhere , type: type
module.exports = ChannelConfig