simple proxmox
This commit is contained in:
@ -27,61 +27,6 @@ async function getGroups(client, member){
|
||||
}
|
||||
}
|
||||
|
||||
async function addGroup(client, data){
|
||||
try{
|
||||
|
||||
await client.add(`cn=${data.name},${conf.groupBase}`, {
|
||||
cn: data.name,
|
||||
member: data.owner,
|
||||
description: data.description,
|
||||
owner: data.owner,
|
||||
objectclass: [ 'groupOfNames', 'top' ]
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function addMember(client, group, user){
|
||||
try{
|
||||
await client.modify(group.dn, [
|
||||
new Change({
|
||||
operation: 'add',
|
||||
modification: new Attribute({
|
||||
type: 'member',
|
||||
values: [user.dn]
|
||||
})
|
||||
}),
|
||||
]);
|
||||
}catch(error){
|
||||
// if(error = "TypeOrValueExistsError"){
|
||||
// console.error('addMember error skipped', error)
|
||||
// return ;
|
||||
// }
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function removeMember(client, group, user){
|
||||
try{
|
||||
await client.modify(group.dn, [
|
||||
new Change({
|
||||
operation: 'delete',
|
||||
modification: new Attribute({
|
||||
type: 'member',
|
||||
values: [user.dn]
|
||||
})}),
|
||||
]);
|
||||
}catch(error){
|
||||
if(error = "TypeOrValueExistsError")return ;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var Group = {};
|
||||
|
||||
Group.list = async function(member){
|
||||
@ -151,63 +96,4 @@ Group.get = async function(data){
|
||||
}
|
||||
}
|
||||
|
||||
Group.add = async function(data){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
await addGroup(client, data);
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return this.get(data);
|
||||
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Group.addMember = async function(user){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
await addMember(client, this, user);
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return this;
|
||||
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Group.removeMember = async function(user){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
await removeMember(client, this, user);
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return this;
|
||||
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Group.remove = async function(){
|
||||
try{
|
||||
await client.bind(conf.bindDN, conf.bindPassword);
|
||||
|
||||
await client.del(this.dn);
|
||||
|
||||
await client.unbind();
|
||||
|
||||
return true;
|
||||
}catch(error){
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {Group};
|
||||
|
Reference in New Issue
Block a user