Skip to content

Commit

Permalink
Merge pull request #33 from ConductorOne/jirwin/user-debug-logging
Browse files Browse the repository at this point in the history
Add debug logs for handling users
  • Loading branch information
jirwin authored Apr 22, 2024
2 parents 38b59e9 + dc44b34 commit b8b5e50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/connector/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"strconv"
"time"

"github.com/conductorone/baton-ldap/pkg/ldap"
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
"github.com/conductorone/baton-sdk/pkg/annotations"
"github.com/conductorone/baton-sdk/pkg/pagination"
rs "github.com/conductorone/baton-sdk/pkg/types/resource"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"go.uber.org/zap"

"github.com/conductorone/baton-ldap/pkg/ldap"
)

// InetOrgPerson resource structure
Expand Down Expand Up @@ -82,6 +85,8 @@ func parseUserStatus(user *ldap.Entry) (v2.UserTrait_Status_Status, error) {

// Create a new connector resource for an LDAP User.
func userResource(ctx context.Context, user *ldap.Entry) (*v2.Resource, error) {
l := ctxzap.Extract(ctx)

firstName, lastName, displayName := parseUserNames(user)
userId := user.GetAttributeValue(attrUserUID)

Expand Down Expand Up @@ -119,6 +124,8 @@ func userResource(ctx context.Context, user *ldap.Entry) (*v2.Resource, error) {
displayName = userId
}

l.Debug("creating user resource", zap.String("display_name", displayName), zap.String("user_id", userId), zap.String("dn", user.DN))

resource, err := rs.NewUserResource(
displayName,
resourceTypeUser,
Expand All @@ -133,6 +140,7 @@ func userResource(ctx context.Context, user *ldap.Entry) (*v2.Resource, error) {
}

func (u *userResourceType) List(ctx context.Context, _ *v2.ResourceId, pt *pagination.Token) ([]*v2.Resource, string, annotations.Annotations, error) {
l := ctxzap.Extract(ctx)
bag, page, err := parsePageToken(pt.Token, &v2.ResourceId{ResourceType: resourceTypeUser.Id})
if err != nil {
return nil, "", nil, err
Expand All @@ -158,7 +166,7 @@ func (u *userResourceType) List(ctx context.Context, _ *v2.ResourceId, pt *pagin
var rv []*v2.Resource
for _, userEntry := range userEntries {
userEntryCopy := userEntry

l.Debug("processing user", zap.String("dn", userEntry.DN))
ur, err := userResource(ctx, userEntryCopy)
if err != nil {
return nil, pageToken, nil, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/ldap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func (c *Client) LdapSearch(ctx context.Context, filter string, attrNames []stri
filter = "(objectClass=*)"
}

l.Debug("searching for ldap entries", zap.String("baseDN", baseDN), zap.String("filter", filter), zap.Strings("attrNames", attrNames))

resp, err := client.conn.Search(&ldap.SearchRequest{
BaseDN: baseDN,
Scope: scope,
Expand Down

0 comments on commit b8b5e50

Please sign in to comment.