Skip to content

Commit

Permalink
Merge pull request #99 from Ouest-France/groupImport
Browse files Browse the repository at this point in the history
Make OU parsing case insensitive in ldap_group
  • Loading branch information
pablo-ruth authored Jun 20, 2023
2 parents 8e56fcc + 57f221d commit 6e87ed9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ldap/resource_ldap_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"regexp"
"strings"

"github.com/Ouest-France/goldap"
"github.com/go-ldap/ldap/v3"
Expand Down Expand Up @@ -139,9 +138,14 @@ func resourceLDAPGroupRead(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err)
}

// Remove the `CN=<group-name>,` from the DN to get the OU
ou := strings.ReplaceAll(dn, fmt.Sprintf("CN=%s,", attributes["name"][0]), "")
if err := d.Set("ou", ou); err != nil {
// Remove the `CN=<group-name>` from the DN to get the OU
// using the regex `^cn=.*?,(.*)$` in case insensitive mode
reg := regexp.MustCompile(`(?i)^cn=.*?,(.*)$`)
match := reg.FindStringSubmatch(dn)
if len(match) != 2 {
return diag.Errorf("Failed parsing OU from DN (must match regex `^cn=.*?,(.*)$`): %s", dn)
}
if err := d.Set("ou", match[1]); err != nil {
return diag.FromErr(err)
}

Expand Down

0 comments on commit 6e87ed9

Please sign in to comment.