Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion pkg/connector/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sort"
"strconv"
"strings"

v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
Expand All @@ -14,6 +15,8 @@ import (
"go.uber.org/zap"
)

const defaultGrantPageSize = 1000

type resourceBuilder struct {
cache *syncCache
resourceType *v2.ResourceType
Expand Down Expand Up @@ -156,7 +159,35 @@ func (b *resourceBuilder) Grants(ctx context.Context, resource *v2.Resource,
return allGrants[i].GetEntitlement().GetId() < allGrants[j].GetEntitlement().GetId()
})

return allGrants, &rs.SyncOpResults{}, nil
pageSize := defaultGrantPageSize
if opts.PageToken.Size > 0 {
pageSize = opts.PageToken.Size
}

offset := 0
if opts.PageToken.Token != "" {
var err error
offset, err = strconv.Atoi(opts.PageToken.Token)
if err != nil {
return nil, nil, fmt.Errorf("baton-file: invalid grants page token: %w", err)
}
}

if offset > len(allGrants) {
offset = len(allGrants)
}

end := offset + pageSize
if end > len(allGrants) {
end = len(allGrants)
}

var nextPageToken string
if end < len(allGrants) {
nextPageToken = strconv.Itoa(end)
}

return allGrants[offset:end], &rs.SyncOpResults{NextPageToken: nextPageToken}, nil
}

func buildUserResource(ctx context.Context, userData client.UserData,
Expand Down
Loading