Skip to content

Commit

Permalink
Add v2 events endpoints (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Oct 17, 2023
1 parent 73411ef commit 4467161
Show file tree
Hide file tree
Showing 28 changed files with 1,608 additions and 450 deletions.
7 changes: 6 additions & 1 deletion pkg/authz/objecttype/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,13 @@ func (repo MySQLRepository) List(ctx context.Context, listParams service.ListPar
return models, nil, nil, nil
}

for i := 0; i < len(objectTypes) && i < listParams.Limit; i++ {
i := 0
if listParams.PrevCursor != nil && len(objectTypes) > listParams.Limit {
i = 1
}
for i < len(objectTypes) && len(models) < listParams.Limit {
models = append(models, &objectTypes[i])
i++
}

//nolint:gosec
Expand Down
7 changes: 6 additions & 1 deletion pkg/authz/objecttype/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,13 @@ func (repo PostgresRepository) List(ctx context.Context, listParams service.List
return models, nil, nil, nil
}

for i := 0; i < len(objectTypes) && i < listParams.Limit; i++ {
i := 0
if listParams.PrevCursor != nil && len(objectTypes) > listParams.Limit {
i = 1
}
for i < len(objectTypes) && len(models) < listParams.Limit {
models = append(models, &objectTypes[i])
i++
}

//nolint:gosec
Expand Down
7 changes: 6 additions & 1 deletion pkg/authz/objecttype/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,13 @@ func (repo SQLiteRepository) List(ctx context.Context, listParams service.ListPa
return models, nil, nil, nil
}

for i := 0; i < len(objectTypes) && i < listParams.Limit; i++ {
i := 0
if listParams.PrevCursor != nil && len(objectTypes) > listParams.Limit {
i = 1
}
for i < len(objectTypes) && len(models) < listParams.Limit {
models = append(models, &objectTypes[i])
i++
}

//nolint:gosec
Expand Down
4 changes: 2 additions & 2 deletions pkg/authz/query/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func queryV1(svc QueryService, w http.ResponseWriter, r *http.Request) error {
listParams := service.GetListParamsFromContext[QueryListParamParser](r.Context())
// create next cursor from lastId or afterId param
if r.URL.Query().Has("lastId") {
lastIdCursor, err := service.NewCursorFromBase64String(r.URL.Query().Get("lastId"))
lastIdCursor, err := service.NewCursorFromBase64String(r.URL.Query().Get("lastId"), QueryListParamParser{}, listParams.SortBy)
if err != nil {
return service.NewInvalidParameterError("lastId", "invalid lastId")
}

listParams.NextCursor = lastIdCursor
} else if r.URL.Query().Has("afterId") {
afterIdCursor, err := service.NewCursorFromBase64String(r.URL.Query().Get("afterId"))
afterIdCursor, err := service.NewCursorFromBase64String(r.URL.Query().Get("afterId"), QueryListParamParser{}, listParams.SortBy)
if err != nil {
return service.NewInvalidParameterError("afterId", "invalid afterId")
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/authz/warrant/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,13 @@ func (repo MySQLRepository) List(ctx context.Context, filterParams FilterParams,
return models, nil, nil, nil
}

for i := 0; i < len(warrants) && i < listParams.Limit; i++ {
i := 0
if listParams.PrevCursor != nil && len(warrants) > listParams.Limit {
i = 1
}
for i < len(warrants) && len(models) < listParams.Limit {
models = append(models, &warrants[i])
i++
}

//nolint:gosec
Expand Down
7 changes: 6 additions & 1 deletion pkg/authz/warrant/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,13 @@ func (repo PostgresRepository) List(ctx context.Context, filterParams FilterPara
return models, nil, nil, nil
}

for i := 0; i < len(warrants) && i < listParams.Limit; i++ {
i := 0
if listParams.PrevCursor != nil && len(warrants) > listParams.Limit {
i = 1
}
for i < len(warrants) && len(models) < listParams.Limit {
models = append(models, &warrants[i])
i++
}

//nolint:gosec
Expand Down
7 changes: 6 additions & 1 deletion pkg/authz/warrant/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,13 @@ func (repo SQLiteRepository) List(ctx context.Context, filterParams FilterParams
return models, nil, nil, nil
}

for i := 0; i < len(warrants) && i < listParams.Limit; i++ {
i := 0
if listParams.PrevCursor != nil && len(warrants) > listParams.Limit {
i = 1
}
for i < len(warrants) && len(models) < listParams.Limit {
models = append(models, &warrants[i])
i++
}

//nolint:gosec
Expand Down
Loading

0 comments on commit 4467161

Please sign in to comment.