'How do I add a member into a GroupOfNames using go-ldap module?

The demand is to add an user of ObjectType PosixAccount into a group of ObjectType groupOfNames by adding it as value of attribute member.

I'm using go-ldap module to accomplish that.

Here below is a sample of the code I've written to complete this demand:

    package main

    import (

    "log"

    "github.com/go-ldap/ldap"
    )
    
    func main() {

        // connection code here

        PutOnGroup := ldap.NewModifyRequest("cn=0000-00000-00000f-abc123-app- 
        session,ou=servicesAccounts,dc=example,dc=com", []ldap.Control{})
        PutOnGroup.Replace("member", []string{"cn=1000000-fa00-de00-ac00-f00c00e00d00b00- 
        ingestion-svc"})

        err = conn.Modify(PutOnGroup)

        if err != nil {
            log.Fatalf("error putting user on group %v: %v", PutOnGroup, err)
        }
    }

The thing is by doing that I just replace the user which is already member's attribute of group.

I'd like to input this member into the group alongside with members which is already there.

How could I do that?


I'm not used to ask questions in StackOverflow so if my question is lacking of details I'm looking foward to provide more information.



Solution 1:[1]

This problem was solved by changing the ldap.NewModifyRequest's function Replace to Add.

     PutOnGroup := ldap.NewModifyRequest("cn=0000-00000-00000f-abc123-app- 
        session,ou=servicesAccounts,dc=example,dc=com", []ldap.Control{})
     PutOnGroup.Add("member", []string{"cn=1000000-fa00-de00-ac00-f00c00e00d00b00- 
        ingestion-svc"})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MatRaPy