Browse Source

Add LDAP_USER_LOGIN_ATTRIBUTE parameter

pull/3/head
thoscut 5 years ago committed by Thomas Scheel
parent
commit
ba0245b47c
  1. 3
      Dockerfile
  2. 3
      docker-compose.yml
  3. 13
      gitea-group-sync.go

3
Dockerfile

@ -9,8 +9,11 @@ WORKDIR /src/gitea-group-sync @@ -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

# Final
FROM alpine:3.10

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

ENTRYPOINT ["/usr/local/bin/gitea-group-sync"]

3
docker-compose.yml

@ -3,7 +3,7 @@ services: @@ -3,7 +3,7 @@ services:
group-sync:
container_name: gitea-group-sync
build: .
image: localhost:5000/gitea-group-sync
image: gitea-group-sync:latest
environment:
GITEA_TOKEN: c00c810bb668c63ce7cd8057411d2f560eac469c
GITEA_URL: http://192.168.2.2:3000
@ -13,4 +13,5 @@ services: @@ -13,4 +13,5 @@ services:
BIND_PASSWORD: GoodNewsEveryone
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_LOGIN_ATTRIBUTE: uid
REP_TIME: '@every 1m'

13
gitea-group-sync.go

@ -137,6 +137,13 @@ func mainJob() { @@ -137,6 +137,13 @@ func mainJob() {
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})
if err != nil {
fmt.Println(err)
@ -178,7 +185,7 @@ func mainJob() { @@ -178,7 +185,7 @@ func mainJob() {
ldapUserSearchBase, // The base dn to search
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
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,
)
// make request to ldap server
@ -193,9 +200,9 @@ func mainJob() { @@ -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)
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
Login: entry.GetAttributeValue("uid"),
Login: entry.GetAttributeValue(ldapUserLoginAttribute),
}
}


Loading…
Cancel
Save