2014-11-24 16:12:12 +00:00
|
|
|
_ = require('lodash')
|
2014-11-26 17:20:56 +00:00
|
|
|
widgets = require('../widgets/widgets')
|
2014-11-24 17:00:36 +00:00
|
|
|
patterns = require('../patterns/patterns')
|
2014-11-26 16:15:40 +00:00
|
|
|
resin = require('../resin')
|
2014-11-24 16:12:12 +00:00
|
|
|
authHooks = require('../hooks/auth')
|
|
|
|
|
2014-11-24 16:43:37 +00:00
|
|
|
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) ->
|
2014-11-24 18:48:16 +00:00
|
|
|
applicationId = program.parent?.application
|
2014-11-24 16:12:12 +00:00
|
|
|
|
|
|
|
if not applicationId?
|
2014-11-26 16:38:02 +00:00
|
|
|
resin.errors.handle(new Error('You have to specify an application'))
|
2014-11-24 16:12:12 +00:00
|
|
|
|
2014-11-26 16:15:40 +00:00
|
|
|
resin.models.environmentVariables.getAll(applicationId).then (environmentVariables) ->
|
2014-11-24 16:43:37 +00:00
|
|
|
|
|
|
|
if not program.parent.verbose?
|
|
|
|
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
|
|
|
|
2014-11-26 17:20:56 +00:00
|
|
|
resin.log.out(widgets.table.horizontal(environmentVariables))
|
2014-11-26 16:38:02 +00:00
|
|
|
.catch(resin.errors.handle)
|
2014-11-24 17:00:36 +00:00
|
|
|
|
|
|
|
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
|
|
|
|
patterns.remove 'environment variable', program.parent.yes, (callback) ->
|
2014-11-26 16:15:40 +00:00
|
|
|
resin.models.environmentVariables.remove(id).then ->
|
2014-11-24 17:00:36 +00:00
|
|
|
return callback()
|
|
|
|
.catch(callback)
|
2014-11-26 16:38:02 +00:00
|
|
|
, resin.errors.handle
|