2015-01-09 15:22:18 +00:00
|
|
|
_ = require('lodash-contrib')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2014-12-05 16:00:15 +00:00
|
|
|
ui = require('../ui')
|
2014-12-12 21:20:29 +00:00
|
|
|
permissions = require('../permissions/permissions')
|
2014-11-24 16:12:12 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.list = permissions.user (params, options, done) ->
|
|
|
|
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
|
|
|
|
return done(error) if error?
|
|
|
|
|
2014-12-12 21:20:29 +00:00
|
|
|
if not options.verbose
|
2015-01-08 16:15:40 +00:00
|
|
|
environmentVariables = _.reject(environmentVariables, resin.models.environmentVariables.isSystemVariable)
|
2014-11-24 16:43:37 +00:00
|
|
|
|
2015-01-15 14:36:43 +00:00
|
|
|
console.log(ui.widgets.table.horizontal(environmentVariables))
|
2015-01-15 13:47:17 +00:00
|
|
|
return done()
|
2014-11-24 17:00:36 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.remove = permissions.user (params, options, done) ->
|
2014-12-12 21:20:29 +00:00
|
|
|
ui.patterns.remove 'environment variable', options.yes, (callback) ->
|
|
|
|
resin.models.environmentVariables.remove(params.id, callback)
|
2015-01-15 13:47:17 +00:00
|
|
|
, done
|
2014-12-19 18:07:53 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.add = permissions.user (params, options, done) ->
|
2014-12-19 18:07:53 +00:00
|
|
|
if not params.value?
|
|
|
|
params.value = process.env[params.key]
|
|
|
|
|
|
|
|
if not params.value?
|
2015-01-15 13:47:17 +00:00
|
|
|
return done(new Error("Environment value not found for key: #{params.key}"))
|
2014-12-19 18:07:53 +00:00
|
|
|
else
|
2015-01-15 14:36:43 +00:00
|
|
|
console.info("Warning: using #{params.key}=#{params.value} from host environment")
|
2014-12-19 18:07:53 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
resin.models.environmentVariables.create(options.application, params.key, params.value, done)
|
2014-12-19 18:28:03 +00:00
|
|
|
|
2015-01-15 13:47:17 +00:00
|
|
|
exports.rename = permissions.user (params, options, done) ->
|
|
|
|
resin.models.environmentVariables.update(params.id, params.value, done)
|