balena-cli/lib/actions/environment-variables.coffee

37 lines
1.4 KiB
CoffeeScript
Raw Normal View History

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