2019-08-14 18:08:34 +00:00
|
|
|
package publicapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
2020-01-31 05:01:21 +00:00
|
|
|
"github.com/rancher/norman/v2/pkg/types"
|
2019-09-11 21:05:00 +00:00
|
|
|
"github.com/rancher/steve/pkg/attributes"
|
|
|
|
"github.com/rancher/steve/pkg/resources/schema"
|
2019-08-14 18:08:34 +00:00
|
|
|
runtimeschema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func k8sAPI(sf schema.Factory, apiOp *types.APIRequest) {
|
|
|
|
vars := mux.Vars(apiOp.Request)
|
|
|
|
group := vars["group"]
|
|
|
|
if group == "core" {
|
|
|
|
group = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
apiOp.Name = vars["name"]
|
|
|
|
apiOp.Type = sf.ByGVR(runtimeschema.GroupVersionResource{
|
|
|
|
Version: vars["version"],
|
|
|
|
Group: group,
|
|
|
|
Resource: vars["resource"],
|
|
|
|
})
|
|
|
|
|
|
|
|
nOrN := vars["nameorns"]
|
|
|
|
if nOrN != "" {
|
|
|
|
schema := apiOp.Schemas.Schema(apiOp.Type)
|
|
|
|
if attributes.Namespaced(schema) {
|
|
|
|
vars["namespace"] = nOrN
|
|
|
|
} else {
|
|
|
|
vars["name"] = nOrN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if namespace := vars["namespace"]; namespace != "" {
|
|
|
|
apiOp.Namespaces = []string{namespace}
|
|
|
|
}
|
|
|
|
}
|
2019-08-14 20:39:08 +00:00
|
|
|
|
|
|
|
func apiRoot(sf schema.Factory, apiOp *types.APIRequest) {
|
|
|
|
apiOp.Type = "apiRoot"
|
|
|
|
}
|