Skip to content
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

Closed
wants to merge 17 commits into from
Closed

Conversation

vetinari
Copy link
Contributor

No description provided.

// 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 {
Copy link
Contributor

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

Copy link
Contributor

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)

@liggitt
Copy link
Contributor

liggitt commented Feb 18, 2016

thanks for the PR!

@vetinari
Copy link
Contributor Author

I'll fix the issues, this may take some time

@vetinari
Copy link
Contributor Author

pending changes for Marshal() depend on #54

@enochtsang
Copy link

enochtsang commented Aug 4, 2016

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.

# Organization Units
dn: ou=users,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: users


# 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
dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
objectClass: top
ou: groups

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:") {
Copy link
Contributor

@liggitt liggitt Aug 4, 2016

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now in 8232180

@vetinari
Copy link
Contributor Author

vetinari commented Aug 5, 2016

@johnweldon now there's nothing left... well, except for the mod(r)dn changes, but those depend on #54

@vetinari
Copy link
Contributor Author

vetinari commented Aug 5, 2016

@enochtsang it's not explicitly stated that Add / Delete and Modify entries are not supported, but the head of ldif/ldif.go states that

This one currently just supports LDIFs like they are generated by tools like ldapsearch(1) slapcat(8). Change records are not supported while unmarshalling.



# 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
Copy link

@enochtsang enochtsang Aug 5, 2016

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!

@enochtsang
Copy link

Can this pull request be merged?

@vetinari
Copy link
Contributor Author

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)
Copy link
Member

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?

@johnweldon
Copy link
Member

Other than the ModifyDN commented code (can we remove that or is there a compelling reason to leave that commented code in?), and a couple minor issues, this seems mergeable to me.

After addressing the trivial items and maybe filing an issue for the io.Writer or passed in log to fix in the future, I'm fine with merging this. @liggitt any objections?

@liggitt
Copy link
Contributor

liggitt commented Sep 13, 2016

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.

@liggitt
Copy link
Contributor

liggitt commented Sep 13, 2016

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?

@vetinari
Copy link
Contributor Author

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?

@liggitt
Copy link
Contributor

liggitt commented Sep 13, 2016

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

@johnweldon
Copy link
Member

That sounds good to me too - @liggitt do you want to make the new repo, or should I?

@liggitt
Copy link
Contributor

liggitt commented Sep 13, 2016

created at https://github.com/go-ldap/ldif

@vetinari vetinari mentioned this pull request Sep 18, 2016
@vetinari
Copy link
Contributor Author

PR done: go-ldap/ldif#3

@liggitt
Copy link
Contributor

liggitt commented Sep 21, 2016

thanks, merged

@liggitt liggitt closed this Sep 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants