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

34 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2014-11-24 16:12:12 +00:00
_ = require('lodash')
table = require('../table/table')
2014-11-24 18:08:58 +00:00
errors = require('../errors/errors')
2014-11-24 17:00:36 +00:00
patterns = require('../patterns/patterns')
2014-11-24 16:12:12 +00:00
log = require('../log/log')
environemtVariablesModel = require('../models/environment-variables')
authHooks = require('../hooks/auth')
SYSTEM_VAR_REGEX = /^RESIN_/
isSystemVariable = (environmentVariable) ->
SYSTEM_VAR_REGEX.test(environmentVariable.name)
2014-11-24 16:12:12 +00:00
exports.list = authHooks.failIfNotLoggedIn (program) ->
applicationId = program.parent.application
if not applicationId?
2014-11-24 18:08:58 +00:00
errors.handle(new Error('You have to specify an application'))
2014-11-24 16:12:12 +00:00
environemtVariablesModel.getAll(applicationId).then (environmentVariables) ->
if not program.parent.verbose?
environmentVariables = _.reject(environmentVariables, isSystemVariable)
2014-11-24 16:12:12 +00:00
log.out(table.horizontal(environmentVariables))
2014-11-24 18:08:58 +00:00
.catch(errors.handle)
2014-11-24 17:00:36 +00:00
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
patterns.remove 'environment variable', program.parent.yes, (callback) ->
environemtVariablesModel.remove(id).then ->
return callback()
.catch(callback)
2014-11-24 18:08:58 +00:00
, errors.handle