Add LDAP_USER_LOGIN_ATTRIBUTE parameter
parent
2159920ec5
commit
ba0245b47c
|
@ -9,8 +9,11 @@ WORKDIR /src/gitea-group-sync
|
||||||
|
|
||||||
RUN go get gopkg.in/ldap.v3 && go get gopkg.in/robfig/cron.v3 && go build
|
RUN go get gopkg.in/ldap.v3 && go get gopkg.in/robfig/cron.v3 && go build
|
||||||
|
|
||||||
|
# Final
|
||||||
FROM alpine:3.10
|
FROM alpine:3.10
|
||||||
|
|
||||||
COPY --from=build-env /src/gitea-group-sync/gitea-group-sync /app/gitea-group-sync/gitea-group-sync
|
COPY --from=build-env /src/gitea-group-sync/gitea-group-sync /app/gitea-group-sync/gitea-group-sync
|
||||||
|
|
||||||
RUN ln -s /app/gitea-group-sync/gitea-group-sync /usr/local/bin/gitea-group-sync
|
RUN ln -s /app/gitea-group-sync/gitea-group-sync /usr/local/bin/gitea-group-sync
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/gitea-group-sync"]
|
ENTRYPOINT ["/usr/local/bin/gitea-group-sync"]
|
||||||
|
|
|
@ -3,7 +3,7 @@ services:
|
||||||
group-sync:
|
group-sync:
|
||||||
container_name: gitea-group-sync
|
container_name: gitea-group-sync
|
||||||
build: .
|
build: .
|
||||||
image: localhost:5000/gitea-group-sync
|
image: gitea-group-sync:latest
|
||||||
environment:
|
environment:
|
||||||
GITEA_TOKEN: c00c810bb668c63ce7cd8057411d2f560eac469c
|
GITEA_TOKEN: c00c810bb668c63ce7cd8057411d2f560eac469c
|
||||||
GITEA_URL: http://192.168.2.2:3000
|
GITEA_URL: http://192.168.2.2:3000
|
||||||
|
@ -13,4 +13,5 @@ services:
|
||||||
BIND_PASSWORD: GoodNewsEveryone
|
BIND_PASSWORD: GoodNewsEveryone
|
||||||
LDAP_FILTER: (&(objectClass=person)(memberOf=cn=%s,ou=people,dc=planetexpress,dc=com))
|
LDAP_FILTER: (&(objectClass=person)(memberOf=cn=%s,ou=people,dc=planetexpress,dc=com))
|
||||||
LDAP_USER_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
|
LDAP_USER_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
|
||||||
|
LDAP_USER_LOGIN_ATTRIBUTE: uid
|
||||||
REP_TIME: '@every 1m'
|
REP_TIME: '@every 1m'
|
||||||
|
|
|
@ -137,6 +137,13 @@ func mainJob() {
|
||||||
ldapUserSearchBase = os.Getenv("LDAP_USER_SEARCH_BASE")
|
ldapUserSearchBase = os.Getenv("LDAP_USER_SEARCH_BASE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ldapUserLoginAttribute string
|
||||||
|
if len(os.Getenv("LDAP_USER_LOGIN_ATTRIBUTE")) == 0 {
|
||||||
|
log.Println("LDAP_USER_LOGIN_ATTRIBUTE is empty")
|
||||||
|
} else {
|
||||||
|
ldapUserLoginAttribute = os.Getenv("LDAP_USER_LOGIN_ATTRIBUTE")
|
||||||
|
}
|
||||||
|
|
||||||
l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort), &tls.Config{InsecureSkipVerify: true})
|
l, err := ldap.DialTLS("tcp", fmt.Sprintf("%s:%d", ldapUrl, ldapPort), &tls.Config{InsecureSkipVerify: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -178,7 +185,7 @@ func mainJob() {
|
||||||
ldapUserSearchBase, // The base dn to search
|
ldapUserSearchBase, // The base dn to search
|
||||||
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
||||||
filter, // The filter to apply
|
filter, // The filter to apply
|
||||||
[]string{"cn", "uid", "mailPrimaryAddress, sn"}, // A list attributes to retrieve
|
[]string{"cn", "uid", "mailPrimaryAddress, sn", ldapUserLoginAttribute}, // A list attributes to retrieve
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
// make request to ldap server
|
// make request to ldap server
|
||||||
|
@ -193,9 +200,9 @@ func mainJob() {
|
||||||
log.Printf("The LDAP %s has %d users corresponding to team %s", ldapUrl, len(sr.Entries), teamList[j].Name)
|
log.Printf("The LDAP %s has %d users corresponding to team %s", ldapUrl, len(sr.Entries), teamList[j].Name)
|
||||||
for _, entry := range sr.Entries {
|
for _, entry := range sr.Entries {
|
||||||
|
|
||||||
AccountsLdap[entry.GetAttributeValue("uid")] = Account{
|
AccountsLdap[entry.GetAttributeValue(ldapUserLoginAttribute)] = Account{
|
||||||
Full_name: entry.GetAttributeValue("sn"), //change to cn if you need it
|
Full_name: entry.GetAttributeValue("sn"), //change to cn if you need it
|
||||||
Login: entry.GetAttributeValue("uid"),
|
Login: entry.GetAttributeValue(ldapUserLoginAttribute),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue