forked from go-ldap/ldap
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Parse() wraps Unmarshal() to parse a string * Apply() sends an *LDIF to the given ldap.Client to modify the server ... changes for go-ldap#54 already included by commented
- Loading branch information
Showing
5 changed files
with
270 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ldif | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"gopkg.in/ldap.v2" | ||
) | ||
|
||
// Apply sends the LDIF entries to the server and does the changes as | ||
// given by the entries. | ||
// | ||
// All *ldap.Entry are converted to an *ldap.AddRequest. | ||
// | ||
// By default, it returns on the first error. To continue with applying the | ||
// LDIF, set the continueOnErr argument to true - in this case the errors | ||
// are logged with log.Printf() | ||
func (l *LDIF) Apply(conn ldap.Client, continueOnErr bool) error { | ||
for _, entry := range l.Entries { | ||
switch { | ||
case entry.Entry != nil: | ||
add := ldap.NewAddRequest(entry.Entry.DN) | ||
for _, attr := range entry.Entry.Attributes { | ||
add.Attribute(attr.Name, attr.Values) | ||
} | ||
entry.Add = add | ||
fallthrough | ||
case entry.Add != nil: | ||
if err := conn.Add(entry.Add); err != nil { | ||
if continueOnErr { | ||
log.Printf("ERROR: Failed to add %s: %s", entry.Add.DN, err) | ||
continue | ||
} | ||
return fmt.Errorf("failed to add %s: %s", entry.Add.DN, err) | ||
} | ||
|
||
case entry.Del != nil: | ||
if err := conn.Del(entry.Del); err != nil { | ||
if continueOnErr { | ||
log.Printf("ERROR: Failed to delete %s: %s", entry.Del.DN, err) | ||
continue | ||
} | ||
return fmt.Errorf("failed to delete %s: %s", entry.Del.DN, err) | ||
} | ||
|
||
case entry.Modify != nil: | ||
if err := conn.Modify(entry.Modify); err != nil { | ||
if continueOnErr { | ||
log.Printf("ERROR: Failed to modify %s: %s", entry.Modify.DN, err) | ||
continue | ||
} | ||
return fmt.Errorf("failed to modify %s: %s", entry.Modify.DN, err) | ||
} | ||
/* | ||
case entry.ModifyDN != nil: | ||
if err := conn.ModifyDN(entry.ModifyDN); err != nil { | ||
if continueOnErr { | ||
log.Printf("ERROR: Failed to modify dn %s: %s", entry.ModifyDN.DN, err) | ||
continue | ||
} | ||
return fmt.Errorf("failed to modify dn %s: %s", entry.ModifyDN.DN, err) | ||
} | ||
*/ | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.