identity
Version:
Identity client
66 lines (49 loc) • 1.77 kB
JavaScript
module.exports = function(grunt){
grunt.registerTask('identity:sync', 'sync all entities', function(){
var done = this.async();
grunt.startActionhero(function(api){
var config = api.config.identity;
var role_config = config.roles;
var Role = api.identity.store.Model('Role');
api.identity.application('identity').del('application/clear/roles', function(err, resp){
if(err || resp.error){
grunt.log.error(err || resp.error)
return done(false);
}else{
var run = [];
if(typeof role_config === 'object'){
for(var role_id in role_config){
if(role_config.hasOwnProperty(role_id)){
var role = role_config[role_id];
if(typeof role === 'string'){
role = {name: role};
}
if(typeof role === 'object'){
var role_entities = [];
if(role.entities){
for(var entity_id in role.entities){
var tmp = role.entities[entity_id];
tmp.entity_id = entity_id;
role_entities.push(tmp);
}
}
run.push(Role.create({
id: role_id,
name: role.name,
role_entities: role_entities
}));
}
}
}
}
Role.all(run).then(function(){
done();
}).catch(function(err){
grunt.log.error(err);
done(false);
});
}
});
});
});
}