-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ldsview | ||
|
||
import ( | ||
hashset "github.com/kgoins/hashset/pkg" | ||
) | ||
|
||
func GetValues(source *LdifParser, attrName string) ([]string, error) { | ||
filterParts := []string{attrName} | ||
filter := BuildAttributeFilter(filterParts) | ||
source.SetAttributeFilter(filter) | ||
|
||
entities, done, cont := make(chan Entity), make(chan bool), make(chan bool) | ||
|
||
valSet := hashset.NewStrHashset() | ||
go func(ents chan Entity, done chan bool, list *hashset.StrHashset) { | ||
for entity := range ents { | ||
if entity.IsEmpty() { | ||
continue | ||
} | ||
|
||
attr, found := entity.GetAttribute(attrName) | ||
if !found { | ||
continue | ||
} | ||
|
||
valSet.Add(attr.Value.Values()...) | ||
} | ||
|
||
done <- true //signals to BuildEntities we're done processing | ||
cont <- true //signals to self we're done processing | ||
|
||
}(entities, done, &valSet) | ||
|
||
err := source.BuildEntities(entities, done) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
<-cont // wait for dnList to be populated | ||
return valSet.Values(), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ldsview | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValueExtractor_GetValues(t *testing.T) { | ||
parser := NewLdifParser(TESTFILE) | ||
|
||
t.Run("parses the ldif objects correctly", func(t *testing.T) { | ||
structure, err := GetValues(&parser, "cn") | ||
assert.Nil(t, err) | ||
assert.Greater(t, len(structure), 0) | ||
}) | ||
} |