英文:
How do I add a member into a GroupOfNames using go-ldap module?
问题
要将ObjectType为PosixAccount
的用户添加到ObjectType为groupOfNames
的组中,需要将其作为属性member
的值添加进去。
我使用go-ldap模块来完成这个需求。
以下是我编写的代码示例:
package main
import (
"log"
"github.com/go-ldap/ldap"
)
func main() {
// 连接代码在这里
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)
}
}
问题是,通过这样做,我只是替换了已经是组成员属性的用户。
我想将这个成员与已经存在的成员一起添加到组中。
我该如何做到这一点?
我不习惯在StackOverflow上提问,所以如果我的问题缺乏细节,我会提供更多信息。
英文:
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.
答案1
得分: 1
这个问题是通过将ldap.NewModifyRequest
函数中的Replace
更改为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"})
英文:
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"})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论