balena-cli/lib/resin/models/environment-variables.coffee

50 lines
1.3 KiB
CoffeeScript
Raw Normal View History

pine = require('./_pine')
2014-11-26 16:38:02 +00:00
errors = require('../errors/errors')
2014-11-24 16:12:12 +00:00
2014-12-08 12:48:19 +00:00
# Get all environment variables by application
#
# @param {String, Number} applicationId application id
# @param {Function} callback callback(error, environmentVariables)
#
# @throw {NotFound} Will throw if no environment variable was found
#
# @example Get all environment variables by application
# resin.models.environmentVariables.getAll (error, environmentVariables) ->
# throw error if error?
# console.log(environmentVariables)
#
2014-12-08 14:12:42 +00:00
exports.getAllByApplication = (applicationId, callback) ->
return pine.get
2014-11-24 16:12:12 +00:00
resource: 'environment_variable'
options:
filter:
application: applicationId
orderby: 'name asc'
2014-11-24 17:40:56 +00:00
.then (environmentVariables) ->
2014-11-24 16:12:12 +00:00
if not environmentVariables?
return callback(new errors.NotFound('environment variables'))
2014-11-24 17:00:36 +00:00
return callback(null, environmentVariables)
.catch (error) ->
return callback(error)
2014-12-08 12:48:19 +00:00
# Remove environment variable
#
# @param {String, Number} id environment variable id
# @param {Function} callback callback(error)
#
# @example Remove environment variable
# resin.models.environmentVariables.remove 51, (error) ->
# throw error if error?
#
exports.remove = (id, callback) ->
return pine.delete
2014-11-24 17:00:36 +00:00
resource: 'environment_variable'
id: id
.then ->
return callback()
.catch (error) ->
return callback(error)