/* global conjur, jQuery, _, async */ (function(conjur, $, _, async, errback) { 'use strict'; var Generic = this.Generic; var Layer = this.Layer = function(args) { if (!(this instanceof Layer)) { return new Layer(args); } var superArguments = Array.prototype.slice.call(arguments); superArguments.unshift('layer'); Generic.apply(this, superArguments); return undefined; }; Layer.prototype = Object.create(Generic.prototype); Layer.prototype.constructor = Layer; Layer.prototype.fetch = function(callback, customErrback) { var id = this.id; if (typeof(customErrback) === 'undefined') { customErrback = errback; // reset to default } function members(role) { return function(cb) { $.ajax({ url: '/api/authz/' + conjur.app.configuration.account + '/roles/' + role + '?members', success: function(result) { cb(null, result); }, error: cb }); }; } async.parallel([ this.attributes.bind(this), this.ownedResources.bind(this), members('@/layer/' + id + '/use_host'), members('@/layer/' + id + '/admin_host'), this.allRoles.bind(this), this.resource.bind(this) ], function(err, results) { if (err) { return customErrback(err.status); } callback({ layer: results[0], owned: results[1], users: _.pluck(results[2], 'member'), admins: _.pluck(results[3], 'member'), roles: results[4], annotations: results[5].annotations }); return undefined; }); }; }).bind(conjur.models.Record) ( conjur, jQuery, _, async, conjur.utils.errback );