diff --git a/Dockerfile b/Dockerfile index 4bddbe9..cae3f1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml index 3184b8f..e3f6082 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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: 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' diff --git a/gitea-group-sync.go b/gitea-group-sync.go index 24540e3..9cf241b 100644 --- a/gitea-group-sync.go +++ b/gitea-group-sync.go @@ -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() { 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() { 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), } }