mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-24 07:46:39 +00:00
47 lines
1.6 KiB
CoffeeScript
47 lines
1.6 KiB
CoffeeScript
_ = require('lodash')
|
|
resin = require('../resin')
|
|
ui = require('../ui')
|
|
permissions = require('../permissions/permissions')
|
|
log = require('../log/log')
|
|
|
|
SYSTEM_VAR_REGEX = /^RESIN_/
|
|
|
|
isSystemVariable = (environmentVariable) ->
|
|
SYSTEM_VAR_REGEX.test(environmentVariable.name)
|
|
|
|
exports.list = permissions.user (params, options) ->
|
|
if not options.application?
|
|
resin.errors.handle(new Error('You have to specify an application'))
|
|
|
|
resin.models.environmentVariables.getAllByApplication options.application, (error, environmentVariables) ->
|
|
resin.errors.handle(error) if error?
|
|
|
|
if not options.verbose
|
|
environmentVariables = _.reject(environmentVariables, isSystemVariable)
|
|
|
|
log.out(ui.widgets.table.horizontal(environmentVariables))
|
|
|
|
exports.remove = permissions.user (params, options) ->
|
|
ui.patterns.remove 'environment variable', options.yes, (callback) ->
|
|
resin.models.environmentVariables.remove(params.id, callback)
|
|
, resin.errors.handle
|
|
|
|
exports.add = permissions.user (params, options) ->
|
|
if not options.application?
|
|
resin.errors.handle(new Error('You have to specify an application'))
|
|
|
|
if not params.value?
|
|
params.value = process.env[params.key]
|
|
|
|
if not params.value?
|
|
resin.errors.handle(new Error("Environment value not found for key: #{params.key}"))
|
|
else
|
|
log.info("Warning: using #{params.key}=#{params.value} from host environment")
|
|
|
|
resin.models.environmentVariables.create options.application, params.key, params.value, (error) ->
|
|
resin.errors.handle(error) if error?
|
|
|
|
exports.rename = permissions.user (params, options) ->
|
|
resin.models.environmentVariables.update params.id, params.value, (error) ->
|
|
resin.errors.handle(error) if error?
|