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

35 lines
1.0 KiB
CoffeeScript
Raw Normal View History

2014-11-24 16:12:12 +00:00
_ = require('lodash')
table = require('../table/table')
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?
throw new Error('You have to specify an application')
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))
.catch (error) ->
throw error
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)
, (error) ->
throw error if error?