mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-13 21:39:45 +00:00
Add namespace filtering
This commit is contained in:
@@ -7,16 +7,53 @@ import (
|
||||
"github.com/rancher/steve/pkg/schemaserver/types"
|
||||
)
|
||||
|
||||
type Vars struct {
|
||||
Type string
|
||||
Name string
|
||||
Namespace string
|
||||
Link string
|
||||
Prefix string
|
||||
Action string
|
||||
}
|
||||
|
||||
func Set(v Vars) mux.MatcherFunc {
|
||||
return func(request *http.Request, match *mux.RouteMatch) bool {
|
||||
if match.Vars == nil {
|
||||
match.Vars = map[string]string{}
|
||||
}
|
||||
if v.Type != "" {
|
||||
match.Vars["type"] = v.Type
|
||||
}
|
||||
if v.Name != "" {
|
||||
match.Vars["name"] = v.Name
|
||||
}
|
||||
if v.Link != "" {
|
||||
match.Vars["link"] = v.Link
|
||||
}
|
||||
if v.Prefix != "" {
|
||||
match.Vars["prefix"] = v.Prefix
|
||||
}
|
||||
if v.Action != "" {
|
||||
match.Vars["action"] = v.Action
|
||||
}
|
||||
if v.Namespace != "" {
|
||||
match.Vars["namespace"] = v.Namespace
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func MuxURLParser(rw http.ResponseWriter, req *http.Request, schemas *types.APISchemas) (ParsedURL, error) {
|
||||
vars := mux.Vars(req)
|
||||
url := ParsedURL{
|
||||
Type: vars["type"],
|
||||
Name: vars["name"],
|
||||
Link: vars["link"],
|
||||
Prefix: vars["prefix"],
|
||||
Method: req.Method,
|
||||
Action: vars["action"],
|
||||
Query: req.URL.Query(),
|
||||
Type: vars["type"],
|
||||
Name: vars["name"],
|
||||
Namespace: vars["namespace"],
|
||||
Link: vars["link"],
|
||||
Prefix: vars["prefix"],
|
||||
Method: req.Method,
|
||||
Action: vars["action"],
|
||||
Query: req.URL.Query(),
|
||||
}
|
||||
|
||||
return url, nil
|
||||
|
@@ -24,6 +24,7 @@ var (
|
||||
type ParsedURL struct {
|
||||
Type string
|
||||
Name string
|
||||
Namespace string
|
||||
Link string
|
||||
Method string
|
||||
Action string
|
||||
@@ -80,6 +81,9 @@ func Parse(apiOp *types.APIRequest, urlParser URLParser) error {
|
||||
if apiOp.URLPrefix == "" {
|
||||
apiOp.URLPrefix = parsedURL.Prefix
|
||||
}
|
||||
if apiOp.Namespace == "" {
|
||||
apiOp.Namespace = parsedURL.Namespace
|
||||
}
|
||||
|
||||
if apiOp.URLBuilder == nil {
|
||||
// make error local to not override the outer error we have yet to check
|
||||
|
Reference in New Issue
Block a user