feat(salix): refs #5770 move samTool to sambaHelper
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
92287cf7f5
commit
c68c11b638
|
@ -13,7 +13,6 @@ const UserAccountControlFlags = {
|
|||
|
||||
module.exports = Self => {
|
||||
const shouldSync = process.env.NODE_ENV !== 'test';
|
||||
let sambaHandler = null;
|
||||
|
||||
Self.getLinker = async function() {
|
||||
return await Self.findOne({
|
||||
|
@ -57,30 +56,6 @@ module.exports = Self => {
|
|||
await this.adClient.unbind();
|
||||
},
|
||||
|
||||
async sambaTool(command, args = []) {
|
||||
let authArgs = [
|
||||
'--URL', `ldaps://${this.adController}`,
|
||||
'--simple-bind-dn', this.bindDn,
|
||||
'--password', this.adPassword
|
||||
];
|
||||
if (!this.verifyCert)
|
||||
authArgs.push('--option', 'tls verify peer = no_check');
|
||||
|
||||
const allArgs = [command].concat(
|
||||
args, authArgs
|
||||
);
|
||||
|
||||
if (!shouldSync) return;
|
||||
return await new Promise((resolve, reject) => {
|
||||
execFile('samba-tool', allArgs, (err, stdout, stderr) => {
|
||||
if (err)
|
||||
reject(err);
|
||||
else
|
||||
resolve({stdout, stderr});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async getAdUser(userName) {
|
||||
const sambaUser = await this.adClient.searchOne(this.fullUsersDn, {
|
||||
scope: 'sub',
|
||||
|
@ -108,7 +83,7 @@ module.exports = Self => {
|
|||
|
||||
if (info.hasAccount) {
|
||||
if (!sambaUser) {
|
||||
await this.sambaTool('user', [
|
||||
await this.sambaHandler.sambaTool('user', [
|
||||
'create', userName,
|
||||
'--userou', this.userDn,
|
||||
'--random-password'
|
||||
|
@ -116,7 +91,7 @@ module.exports = Self => {
|
|||
sambaUser = await this.getAdUser(userName);
|
||||
}
|
||||
if (password) {
|
||||
await this.sambaTool('user', [
|
||||
await this.sambaHandler.sambaTool('user', [
|
||||
'setpassword', userName,
|
||||
'--newpassword', password
|
||||
]);
|
||||
|
|
|
@ -6,9 +6,34 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
module.exports = class SambaHelper {
|
||||
constructor(ctx) {
|
||||
const {sambaTool, verifyCert, adPassword, adController, groupDn, userDn} = ctx;
|
||||
Object.assign(this, {...ctx, verifyCert, adPassword, adController, groupDn, userDn, sambaTool});
|
||||
const {verifyCert, adPassword, adController, groupDn, userDn} = ctx;
|
||||
Object.assign(this, {...ctx, verifyCert, adPassword, adController, groupDn, userDn});
|
||||
}
|
||||
|
||||
async sambaTool(command, args = []) {
|
||||
let authArgs = [
|
||||
'--URL', `ldaps://${this.adController}`,
|
||||
'--simple-bind-dn', this.bindDn,
|
||||
'--password', this.adPassword
|
||||
];
|
||||
if (!this.verifyCert)
|
||||
authArgs.push('--option', 'tls verify peer = no_check');
|
||||
|
||||
const allArgs = [command].concat(
|
||||
args, authArgs
|
||||
);
|
||||
|
||||
if (!shouldSync) return;
|
||||
return await new Promise((resolve, reject) => {
|
||||
execFile('samba-tool', allArgs, (err, stdout, stderr) => {
|
||||
if (err)
|
||||
reject(err);
|
||||
else
|
||||
resolve({stdout, stderr});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async getRoles() {
|
||||
this.roles = (await app.models.VnRole.find({
|
||||
fields: ['id', 'name', 'description'],
|
||||
|
|
Loading…
Reference in New Issue