Add namespace filtering

This commit is contained in:
Darren Shepherd
2020-02-27 10:34:51 -07:00
parent ae42b9422b
commit 6b6ff53373
11 changed files with 194 additions and 99 deletions

View File

@@ -2,17 +2,20 @@ package schema
import (
"context"
"net/http"
"strings"
"sync"
"github.com/rancher/steve/pkg/accesscontrol"
"github.com/rancher/steve/pkg/attributes"
"github.com/rancher/steve/pkg/schemaserver/server"
"github.com/rancher/steve/pkg/schemaserver/types"
"github.com/rancher/wrangler/pkg/name"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/cache"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
)
type Factory interface {
@@ -47,6 +50,28 @@ type Template struct {
StoreFactory func(types.Store) types.Store
}
func WrapServer(factory Factory, server *server.Server) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
user, ok := request.UserFrom(req.Context())
if !ok {
return
}
schemas, err := factory.Schemas(user)
if err != nil {
logrus.Errorf("failed to lookup schemas for user %v: %v", user, err)
http.Error(rw, "schemas failed", http.StatusInternalServerError)
return
}
server.Handle(&types.APIRequest{
Request: req,
Response: rw,
Schemas: schemas,
})
})
}
func NewCollection(ctx context.Context, baseSchema *types.APISchemas, access accesscontrol.AccessSetLookup) *Collection {
return &Collection{
baseSchema: baseSchema,