@@ -66,9 +66,12 @@ type Source struct {
66
66
67
67
useAuthInUrl bool
68
68
69
- clonePath string
70
- noCleanup bool
69
+ clonePath string
70
+ noCleanup bool
71
+
71
72
printLegacyJSON bool
73
+
74
+ projectsPerPage int
72
75
}
73
76
74
77
// 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
171
174
s .clonePath = conn .GetClonePath ()
172
175
s .noCleanup = conn .GetNoCleanup ()
173
176
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
+ }
174
182
175
183
// configuration uses the inverse logic of the `useAuthInUrl` flag.
176
184
s .useAuthInUrl = ! conn .RemoveAuthInUrl
@@ -546,10 +554,10 @@ func (s *Source) getAllProjectRepos(
546
554
}
547
555
548
556
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"
551
558
)
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 }
553
561
554
562
projectQueryOptions := & gitlab.ListProjectsOptions {OrderBy : gitlab .Ptr (orderBy ), ListOptions : listOpts }
555
563
for {
@@ -654,14 +662,13 @@ func (s *Source) getAllProjectReposV2(
654
662
) error {
655
663
gitlabReposEnumerated .WithLabelValues (s .name ).Set (0 )
656
664
657
- const paginationLimit = 100 // default is 20, max is 100.
658
-
659
665
// example: https://gitlab.com/gitlab-org/api/client-go/-/blob/main/examples/pagination.go#L55
660
666
listOpts := gitlab.ListOptions {
661
667
OrderBy : "id" ,
662
668
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" ,
665
672
}
666
673
667
674
projectQueryOptions := & gitlab.ListProjectsOptions {
@@ -756,11 +763,10 @@ func (s *Source) getAllProjectReposInGroups(
756
763
757
764
var projectsWithNamespace []string
758
765
const (
759
- orderBy = "id"
760
- paginationLimit = 100
766
+ orderBy = "id"
761
767
)
762
768
763
- listOpts := gitlab.ListOptions {PerPage : paginationLimit }
769
+ listOpts := gitlab.ListOptions {PerPage : s . projectsPerPage }
764
770
projectOpts := & gitlab.ListGroupProjectsOptions {
765
771
ListOptions : listOpts ,
766
772
OrderBy : gitlab .Ptr (orderBy ),
0 commit comments