Skip to content

Commit 8148892

Browse files
committed
First commit
0 parents  commit 8148892

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+6960
-0
lines changed

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.dll
4+
*.so
5+
*.dylib
6+
binaries/
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
15+
.glide/
16+
17+
# IDE
18+
.idea/
19+
*.iml
20+
# local ldif
21+
_*
22+

LICENSE

+674
Large diffs are not rendered by default.

README.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ldifdiff
2+
ldiffdiff is a fast Go (golang) library and executable that outputs the
3+
difference between two LDIF files (LDAP). Binaries of the command implementation
4+
are provided under [releases](https://github.com/nxadm/ldifdiff/releases).
5+
6+
7+
[![Build Status](https://travis-ci.org/nxadm/ldifdiff.svg?branch=master)](https://travis-ci.org/nxadm/ldifdiff)
8+
9+
## Usage of the ldifdiff command
10+
```
11+
$ ./ldifdiff -h
12+
ldifdiff v0.1.0 (Claudio Ramirez <[email protected]>).
13+
Compare two LDIF files and output the differences as a valid LDIF.
14+
Bugs to https://github.com/nxadm/ldifdiff.
15+
16+
_ _ _ _ _ _ _ _
17+
_-(_)- _-(_)- _-(_)- _-(")- _-(_)- _-(_)- _-(_)- _-(_)-
18+
*(___) *(___) *(___) *%%%%% *(___) *(___) *(___) *(___)
19+
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\
20+
21+
Usage:
22+
ldifdiff <source> <target> [-i <attributes> ...] [-d]
23+
ldifdiff -h
24+
ldifdiff -v
25+
Options:
26+
-d, --dn
27+
Only print DNs instead of a full LDIF.
28+
-i <attributes>, --ignore <attributes>
29+
Comma separated attribute list.
30+
Multiple instances of this switch are allowed.
31+
-h, --help
32+
Show this screen.
33+
-v, --version
34+
Show version
35+
```
36+
37+
## Installation
38+
39+
Download the library using go:
40+
```go get github.com/nxadm/ldifdiff```
41+
42+
Import the library into your project:
43+
```import "github.com/nxadm/ldifdiff"```
44+
45+
Compile the ldiff cmd implementation:
46+
```cd cmd; go build -o ldifdiff ldifdiff.go```
47+
48+
49+
## API ##
50+
51+
The API is simple and provides for functions.
52+
53+
```func Diff(sourceStr, targetStr string, ignoreAttr []string) (string, error)```
54+
55+
Diff compares two LDIF strings (sourceStr and targetStr) and outputs the
56+
differences as a LDIF string. An array of attributes can be supplied.
57+
These attributes will be ignored when comparing the LDIF strings. The
58+
output is a string, a valid LDIF, and can be added to the "target"
59+
database (the one that created targetStr) in order to make it equal to
60+
the *source* database (the one that created sourceStr). In case of
61+
failure, an error is provided.
62+
63+
64+
```func DiffFromFiles(sourceFile, targetFile string, ignoreAttr []string) (string, error)```
65+
66+
DiffFromFiles compares two LDIF files (sourceFile and targetFile) and
67+
outputs the differences as a LDIF string. An array of attributes can be
68+
supplied. These attributes will be ignored when comparing the LDIF
69+
strings. The output is a string, a valid LDIF, and can be added to the
70+
"target" database (the one that created targetFile) in order to make it
71+
equal to the *source* database (the one that created sourceFile). In
72+
case of failure, an error is provided.
73+
74+
```func ListDiffDn(sourceStr, targetStr string, ignoreAttr []string) ([]string, error)```
75+
76+
ListDiffDn compares two LDIF strings (sourceStr and targetStr) and
77+
outputs the differences as a list of affected DNs (Dintinguished Names).
78+
An array of attributes can be supplied. These attributes will be ignored
79+
when comparing the LDIF strings. The output is a string slice. In case
80+
of failure, an error is provided.
81+
82+
```func ListDiffDnFromFiles(sourceFile, targetFile string, ignoreAttr []string) ([]string, error)```
83+
84+
ListDiffDnFromFiles compares two LDIF files (sourceFile and
85+
targetFileStr) and outputs the differences as a list of affected DNs
86+
(Dintinguished Names). An array of attributes can be supplied. These
87+
attributes will be ignored when comparing the LDIF strings. The output
88+
is a string slice. In case of failure, an error is provided.

cmd/Gopkg.lock

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/Gopkg.toml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
## Gopkg.toml example (these lines may be deleted)
3+
4+
## "metadata" defines metadata about the project that could be used by other independent
5+
## systems. The metadata defined here will be ignored by dep.
6+
# [metadata]
7+
# key1 = "value that convey data to other systems"
8+
# system1-data = "value that is used by a system"
9+
# system2-data = "value that is used by another system"
10+
11+
## "required" lists a set of packages (not projects) that must be included in
12+
## Gopkg.lock. This list is merged with the set of packages imported by the current
13+
## project. Use it when your project needs a package it doesn't explicitly import -
14+
## including "main" packages.
15+
# required = ["github.com/user/thing/cmd/thing"]
16+
17+
## "ignored" lists a set of packages (not projects) that are ignored when
18+
## dep statically analyzes source code. Ignored packages can be in this project,
19+
## or in a dependency.
20+
ignored = ["github.com/nxadm/ldifdiff"]
21+
22+
## Constraints are rules for how directly imported projects
23+
## may be incorporated into the depgraph. They are respected by
24+
## dep whether coming from the Gopkg.toml of the current project or a dependency.
25+
# [[constraint]]
26+
## Required: the root import path of the project being constrained.
27+
# name = "github.com/user/project"
28+
#
29+
## Recommended: the version constraint to enforce for the project.
30+
## Only one of "branch", "version" or "revision" can be specified.
31+
# version = "1.0.0"
32+
# branch = "master"
33+
# revision = "abc123"
34+
#
35+
## Optional: an alternate location (URL or import path) for the project's source.
36+
# source = "https://github.com/myfork/package.git"
37+
#
38+
## "metadata" defines metadata about the dependency or override that could be used
39+
## by other independent systems. The metadata defined here will be ignored by dep.
40+
# [metadata]
41+
# key1 = "value that convey data to other systems"
42+
# system1-data = "value that is used by a system"
43+
# system2-data = "value that is used by another system"
44+
45+
## Overrides have the same structure as [[constraint]], but supersede all
46+
## [[constraint]] declarations from all projects. Only [[override]] from
47+
## the current project's are applied.
48+
##
49+
## Overrides are a sledgehammer. Use them only as a last resort.
50+
# [[override]]
51+
## Required: the root import path of the project being constrained.
52+
# name = "github.com/user/project"
53+
#
54+
## Optional: specifying a version constraint override will cause all other
55+
## constraints on this project to be ignored; only the overridden constraint
56+
## need be satisfied.
57+
## Again, only one of "branch", "version" or "revision" can be specified.
58+
# version = "1.0.0"
59+
# branch = "master"
60+
# revision = "abc123"
61+
#
62+
## Optional: specifying an alternate source location as an override will
63+
## enforce that the alternate location is used for that project, regardless of
64+
## what source location any dependent projects specify.
65+
# source = "https://github.com/myfork/package.git"
66+
67+
68+
69+
[[constraint]]
70+
branch = "master"
71+
name = "github.com/docopt/docopt-go"
72+

cmd/ldifdiff.go

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// A simple implementation of the ldifdiff library
2+
package main
3+
4+
import (
5+
"fmt"
6+
docopt "github.com/docopt/docopt-go"
7+
"github.com/nxadm/ldifdiff"
8+
"os"
9+
"strings"
10+
)
11+
12+
type Params struct {
13+
Source, Target string
14+
IgnoreAttr []string
15+
DnOnly bool
16+
}
17+
18+
var versionMsg = "ldifdiff " + ldifdiff.Version + " (" + ldifdiff.Author + ")."
19+
var usage = versionMsg + "\n" +
20+
"Compare two LDIF files and output the differences as a valid LDIF.\n" +
21+
"Bugs to " + ldifdiff.Repo + ".\n" + `
22+
_ _ _ _ _ _ _ _
23+
_-(_)- _-(_)- _-(_)- _-(")- _-(_)- _-(_)- _-(_)- _-(_)-
24+
*(___) *(___) *(___) *%%%%% *(___) *(___) *(___) *(___)
25+
// \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\
26+
27+
Usage:
28+
ldifdiff <source> <target> [-i <attributes> ...] [-d]
29+
ldifdiff -h
30+
ldifdiff -v
31+
Options:
32+
-d, --dn
33+
Only print DNs instead of a full LDIF.
34+
-i <attributes>, --ignore <attributes>
35+
Comma separated attribute list.
36+
Multiple instances of this switch are allowed.
37+
-h, --help
38+
Show this screen.
39+
-v, --version
40+
Show version
41+
`
42+
43+
func main() {
44+
params := Params{}
45+
params.parse()
46+
47+
/* DiffFromFiles the files */
48+
var output string
49+
var err error
50+
switch params.DnOnly {
51+
case true:
52+
var outputList []string
53+
outputList, err = ldifdiff.ListDiffDnFromFiles(params.Source, params.Target, params.IgnoreAttr)
54+
output = strings.Join(outputList, "\n") + "\n"
55+
default:
56+
output, err = ldifdiff.DiffFromFiles(params.Source, params.Target, params.IgnoreAttr)
57+
}
58+
59+
if err != nil {
60+
fmt.Fprintf(os.Stderr, "%s\n", err)
61+
os.Exit(1)
62+
}
63+
64+
fmt.Printf("%s", output)
65+
}
66+
67+
func (params *Params) parse() {
68+
args, err := docopt.Parse(usage, nil, true, versionMsg, false)
69+
70+
switch {
71+
case err != nil:
72+
fmt.Fprintf(os.Stderr, "Error parsing the command line arguments:\n%v\n", err)
73+
os.Exit(1)
74+
case args["--dn"].(bool):
75+
params.DnOnly = true
76+
fallthrough
77+
case args["--ignore"].([]string) != nil:
78+
params.IgnoreAttr = args["--ignore"].([]string)
79+
fallthrough
80+
case args["<source>"].(string) != "":
81+
params.Source = args["<source>"].(string)
82+
fallthrough
83+
case args["<target>"].(string) != "":
84+
params.Target = args["<target>"].(string)
85+
}
86+
87+
errMsgs := []string{}
88+
switch {
89+
case params.Source == params.Target:
90+
fmt.Fprintln(os.Stderr, "Source and target ldif files are the same.")
91+
os.Exit(1)
92+
default:
93+
if _, err := os.Stat(params.Source); err != nil {
94+
errMsgs = append(errMsgs, err.Error())
95+
}
96+
if _, err := os.Stat(params.Target); err != nil {
97+
errMsgs = append(errMsgs, err.Error())
98+
}
99+
}
100+
if len(errMsgs) > 0 {
101+
for _, msg := range errMsgs {
102+
fmt.Fprintf(os.Stderr, "%s\n", msg)
103+
}
104+
os.Exit(1)
105+
}
106+
107+
}

cmd/vendor/github.com/docopt/docopt-go/.gitignore

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/vendor/github.com/docopt/docopt-go/.travis.yml

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/vendor/github.com/docopt/docopt-go/LICENSE

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)