2014-08-24 23:00:05 +02:00
|
|
|
var models = require('../../models')
|
2014-08-25 01:02:34 +02:00
|
|
|
var mongoose = require('mongoose')
|
|
|
|
|
|
|
|
var playbook = require('./playbook')
|
2014-08-24 23:00:05 +02:00
|
|
|
|
|
|
|
exports.unauthorized = function (app, template) {
|
|
|
|
template([
|
2014-09-11 19:42:13 +02:00
|
|
|
'add',
|
|
|
|
'list'
|
2014-08-24 23:00:05 +02:00
|
|
|
], {
|
|
|
|
prefix: 'playbook'
|
|
|
|
});
|
2014-08-25 01:02:34 +02:00
|
|
|
|
|
|
|
playbook.unauthorized(app, template);
|
2014-08-24 23:00:05 +02:00
|
|
|
}
|
|
|
|
|
2014-08-25 01:02:34 +02:00
|
|
|
exports.httpRouter = function (app) {
|
|
|
|
playbook.httpRouter(app);
|
2014-08-24 23:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.router = function (app) {
|
|
|
|
app.get('/playbooks', getPlaybooks)
|
2014-08-25 01:02:34 +02:00
|
|
|
.post('/playbooks', addPlaybook)
|
|
|
|
|
|
|
|
playbook.router(app);
|
2014-08-24 23:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPlaybooks (req, res) {
|
|
|
|
models.Playbook.find({
|
2014-08-25 12:35:49 +02:00
|
|
|
}).sort('-created').select('-vault_password').exec(function (err, playbooks) {
|
2014-08-24 23:00:05 +02:00
|
|
|
res.send(playbooks)
|
|
|
|
})
|
2014-08-25 01:02:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addPlaybook (req, res) {
|
|
|
|
var playbook = new models.Playbook({
|
|
|
|
name: req.body.name,
|
|
|
|
location: req.body.location,
|
|
|
|
vault_password: req.body.vault_password
|
|
|
|
})
|
2014-08-25 21:41:05 +02:00
|
|
|
|
|
|
|
if (req.body.credential && req.body.credential.length > 0) {
|
|
|
|
try {
|
|
|
|
playbook.credential = mongoose.Types.ObjectId(req.body.credential)
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
2014-08-25 01:02:34 +02:00
|
|
|
|
|
|
|
playbook.save(function () {
|
2014-08-25 12:35:49 +02:00
|
|
|
res.send(playbook);
|
|
|
|
});
|
2014-08-24 23:00:05 +02:00
|
|
|
}
|