mirror of
https://github.com/rancher/steve.git
synced 2025-09-08 02:39:26 +00:00
Full dynamic RBAC and pagination
This commit is contained in:
@@ -3,6 +3,7 @@ package writer
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/rancher/steve/pkg/schemaserver/types"
|
||||
)
|
||||
@@ -99,6 +100,14 @@ func (j *EncodingResponseWriter) addLinks(schema *types.APISchema, context *type
|
||||
}
|
||||
}
|
||||
|
||||
func getLimit(req *http.Request) int {
|
||||
limit, err := strconv.Atoi(req.Header.Get("limit"))
|
||||
if err == nil && limit > 0 {
|
||||
return limit
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func newCollection(apiOp *types.APIRequest, list types.APIObjectList) *types.GenericCollection {
|
||||
result := &types.GenericCollection{
|
||||
Collection: types.Collection{
|
||||
@@ -114,6 +123,18 @@ func newCollection(apiOp *types.APIRequest, list types.APIObjectList) *types.Gen
|
||||
},
|
||||
}
|
||||
|
||||
partial := list.Continue != "" || apiOp.Query.Get("continue") != ""
|
||||
if partial {
|
||||
result.Pagination = &types.Pagination{
|
||||
Limit: getLimit(apiOp.Request),
|
||||
First: apiOp.URLBuilder.Current(),
|
||||
Partial: true,
|
||||
}
|
||||
if list.Continue != "" {
|
||||
result.Pagination.Next = apiOp.URLBuilder.Marker(list.Continue)
|
||||
}
|
||||
}
|
||||
|
||||
if apiOp.Method == http.MethodGet {
|
||||
if apiOp.AccessControl.CanCreate(apiOp, apiOp.Schema) == nil {
|
||||
result.CreateTypes[apiOp.Schema.ID] = apiOp.URLBuilder.Collection(apiOp.Schema)
|
||||
|
Reference in New Issue
Block a user