-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add basic ldif reader #49
Conversation
// A basic LDIF parser. This one does currently just support LDIFs like | ||
// they're generated by tools like ldapsearch(1) / slapcat(8). Change | ||
// records are not supported. | ||
type LDIF struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixing the parser and the data is unusual... I would expect an LDIFParser that takes a reader and decodes into an LDIF struct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe something along the lines of https://golang.org/pkg/encoding/json/#Unmarshal, e.g.
ldif.Unmarshal(io.Reader, *[]ldap.Entry) error
if you wanted the relaxed parser option, that could be in a decoder modeled after https://golang.org/pkg/encoding/json/#Decoder, e.g.
var r io.Reader = ...
var e *[]ldap.Entry = ...
decoder := ldif.NewDecoder(r)
decoder.RelaxedParsing(true)
err := decoder.Decode(e)
thanks for the PR! |
I'll fix the issues, this may take some time |
pending changes for Marshal() depend on #54 |
Hi I've actually been using this branch even though is hasn't been merged yet, I've noticed that entries must be separated by exactly one line, no more. I'm not sure if this strict whitespacing is intended but the ldapadd utility is not as strict.
I would like to comment that it seems like as well as Modify not yet being supported as in the comments, Add and Delete are also not being parsed for yet as far as I can tell. It's not a huge deal feature wise but the comments should probably add that Add and Delete are also not supported yet (if I'm not mistaken haha). EDIT: I see that @vetinari is still adding features, ignore the above paragraph. |
return nil, errors.New("empty entry?") | ||
} | ||
|
||
if l.Version == 0 && strings.HasPrefix(lines[0], "version:") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like it would be better to make the version parsing an optional thing done on the first line of the file, rather than part of parseEntry. as it is, the first entry could be missing version
line, and the second entry have one, and this would parse it out as the ldif version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed now in 8232180
@johnweldon now there's nothing left... well, except for the mod(r)dn changes, but those depend on #54 |
@enochtsang it's not explicitly stated that Add / Delete and Modify entries are not supported, but the head of ldif/ldif.go states that
|
|
||
|
||
# searches for above empty line for dn but fails and errors out in this PR | ||
# Even though this is a valid LDIF file for ldapadd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looked a little familiar haha, these two comments aren't necessary anymore I don't think. Thanks for the fix!
Can this pull request be merged? |
from my POV, yes. |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe as a future TODO, can we use an io.Writer here, or maybe pass in the log rather than using the static global?
Other than the After addressing the trivial items and maybe filing an issue for the |
I don't object, though I haven't played with the API enough to know if there are improvements we'll want. That makes tagging versions tricky, if there is new, experimentalish code side-by-side with code we want to stay version compatible with. |
I've been thinking about starting a v2 maintenance branch, and working in master to resolve some of the issues tagged for v3 that involve API changes or dropping support for old go versions. How would you feel about this just living in master until that work was done and we reached a v3.0.0 tag? |
After addressing the above issues, what about putting the ldif/ dir as a new repo (https://github.com/go-ldap/ldif) and then maybe make it accessible as gopkg.in/ldif.v0 / v1? |
I like the ability to version the ldif stuff separately, and starting with v0 seems like a good way to clarify the expectations around API stability until we've had more time with it |
That sounds good to me too - @liggitt do you want to make the new repo, or should I? |
created at https://github.com/go-ldap/ldif |
PR done: go-ldap/ldif#3 |
thanks, merged |
No description provided.