refs #5770 updates with real environment
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-04-01 17:57:51 +02:00
parent 0eb23312a7
commit 64539a4a0d
1 changed files with 18 additions and 6 deletions

View File

@ -1,8 +1,9 @@
const app = require('vn-loopback/server/server');
const ldap = require('../util/ldapjs-extra');
const { differences, handleExecResponse, toMap } = require('../util/helpers');
const { stdout } = require('process');
const execFile = require('child_process').execFile;
const ROLE_PREFIX = 'VN_';
/**
* Summary of userAccountControl flags:
* https://docs.microsoft.com/en-us/troubleshoot/windows-server/identity/useraccountcontrol-manipulate-account-properties
@ -187,10 +188,10 @@ module.exports = Self => {
order: 'modified DESC',
limit: 1
}));
let rolesMap = roles.map(role => role.name);
let rolesMap = roles;//.map(({id, name, description}) => ({id, name, description}));
// OBTENER SAMBA ROLES
let sambaCurrentRoles = handleExecResponse(await this.sambaTool('group', ['list']));
let sambaCurrentRoles = handleExecResponse(await this.sambaTool('group', ['list'])).filter(group => group.startsWith(ROLE_PREFIX));
// Encontrar elementos a eliminar
const rolesToDelete = differences(sambaCurrentRoles, rolesMap);
@ -248,15 +249,26 @@ module.exports = Self => {
if (rolesToInsert.length > 0) {
// PROCEDIMIENTO PARA INSERTAR ROLES
const resultsRoleInsert = await Promise.all(
rolesToInsert.map(role => this.sambaTool('group', ['add', role]))
rolesToInsert.map(({id, description,name}) => this.sambaTool('group', ['add', `${ROLE_PREFIX}${name}`, `--description="${description}"`]))
);
resultsRoleInsert.forEach(({stdout}) => console.log(stdout));
// PROCEDIMIENTO PARA INSERTAR USUARIOS ASOCIADOS AL ROL
let usersToInsert = rolesToInsert.flatMap(role => usersMap.get(role).map(
a => this.sambaTool('group', ['addmembers', role, a])
let usersToInsert = rolesToInsert.flatMap(role => usersMap.get(role.name).map(
a => this.sambaTool('user', ['add', a,
'--random-password', '--must-change-at-next-login'])
)
);
const resultsUserInsert = await Promise.all(usersToInsert);
resultsUserInsert.forEach(({stdout}) => console.log(stdout));
// PROCEDIMIENTO PARA INSERTAR USUARIOS ASOCIADOS AL ROL
let usersToGroup = rolesToInsert.flatMap(role => usersMap.get(role).map(
a => this.sambaTool('group', ['addmembers', `${ROLE_PREFIX}${role}`, a])
)
);
const resultsUserGroup = await Promise.all(usersToGroup);
resultsUserGroup.forEach(({stdout}) => console.log(stdout));
}
if (rolesToUpdate.length > 0) {