@@ -66,9 +66,12 @@ type Source struct {
6666
6767 useAuthInUrl bool
6868
69- clonePath string
70- noCleanup bool
69+ clonePath string
70+ noCleanup bool
71+
7172 printLegacyJSON bool
73+
74+ projectsPerPage int
7275}
7376
7477// WithCustomContentWriter sets the useCustomContentWriter flag on the source.
@@ -171,6 +174,11 @@ func (s *Source) Init(ctx context.Context, name string, jobId sources.JobID, sou
171174 s .clonePath = conn .GetClonePath ()
172175 s .noCleanup = conn .GetNoCleanup ()
173176 s .printLegacyJSON = conn .GetPrintLegacyJson ()
177+ s .projectsPerPage = int (feature .GitlabProjectsPerPage .Load ())
178+
179+ if s .projectsPerPage > 100 {
180+ return fmt .Errorf ("invalid config: maximum allowed projects per page for gitlab is 100" )
181+ }
174182
175183 // configuration uses the inverse logic of the `useAuthInUrl` flag.
176184 s .useAuthInUrl = ! conn .RemoveAuthInUrl
@@ -546,10 +554,10 @@ func (s *Source) getAllProjectRepos(
546554 }
547555
548556 const (
549- orderBy = "id" // TODO: Use keyset pagination (https://docs.gitlab.com/ee/api/rest/index.html#keyset-based-pagination)
550- paginationLimit = 100 // Default is 20, max is 100.
557+ orderBy = "id"
551558 )
552- listOpts := gitlab.ListOptions {PerPage : paginationLimit }
559+ // Trufflehog default per page 100 unless set to other value through feature flag. If 0 provided in feature flag gitlab default it to 20
560+ listOpts := gitlab.ListOptions {PerPage : s .projectsPerPage }
553561
554562 projectQueryOptions := & gitlab.ListProjectsOptions {OrderBy : gitlab .Ptr (orderBy ), ListOptions : listOpts }
555563 for {
@@ -654,14 +662,13 @@ func (s *Source) getAllProjectReposV2(
654662) error {
655663 gitlabReposEnumerated .WithLabelValues (s .name ).Set (0 )
656664
657- const paginationLimit = 100 // default is 20, max is 100.
658-
659665 // example: https://gitlab.com/gitlab-org/api/client-go/-/blob/main/examples/pagination.go#L55
660666 listOpts := gitlab.ListOptions {
661667 OrderBy : "id" ,
662668 Pagination : "keyset" , // https://docs.gitlab.com/api/rest/#keyset-based-pagination
663- PerPage : paginationLimit ,
664- Sort : "asc" ,
669+ // Trufflehog default per page 100 unless set to other value through feature flag. If 0 provided in feature flag gitlab default it to 20
670+ PerPage : s .projectsPerPage ,
671+ Sort : "asc" ,
665672 }
666673
667674 projectQueryOptions := & gitlab.ListProjectsOptions {
@@ -756,11 +763,10 @@ func (s *Source) getAllProjectReposInGroups(
756763
757764 var projectsWithNamespace []string
758765 const (
759- orderBy = "id"
760- paginationLimit = 100
766+ orderBy = "id"
761767 )
762768
763- listOpts := gitlab.ListOptions {PerPage : paginationLimit }
769+ listOpts := gitlab.ListOptions {PerPage : s . projectsPerPage }
764770 projectOpts := & gitlab.ListGroupProjectsOptions {
765771 ListOptions : listOpts ,
766772 OrderBy : gitlab .Ptr (orderBy ),
0 commit comments