2014-12-09 18:53:57 +00:00
|
|
|
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) ->
|
2014-12-09 18:53:57 +00:00
|
|
|
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?
|
2014-11-26 18:11:02 +00:00
|
|
|
return callback(new errors.NotFound('environment variables'))
|
2014-11-24 17:00:36 +00:00
|
|
|
|
2014-11-26 18:11:02 +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?
|
|
|
|
#
|
2014-11-26 18:11:02 +00:00
|
|
|
exports.remove = (id, callback) ->
|
2014-12-09 18:53:57 +00:00
|
|
|
return pine.delete
|
2014-11-24 17:00:36 +00:00
|
|
|
resource: 'environment_variable'
|
|
|
|
id: id
|
2014-11-26 18:11:02 +00:00
|
|
|
.then ->
|
|
|
|
return callback()
|
|
|
|
.catch (error) ->
|
|
|
|
return callback(error)
|