mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Return an error when names are empty
This commit is contained in:
parent
8f6e3607a9
commit
e6fdac1365
@ -44,6 +44,9 @@ type action struct {
|
|||||||
Params []*restful.Parameter // List of parameters associated with the action.
|
Params []*restful.Parameter // List of parameters associated with the action.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// errEmptyName is returned when API requests do not fill the name section of the path.
|
||||||
|
var errEmptyName = fmt.Errorf("name must be provided")
|
||||||
|
|
||||||
// Installs handlers for API resources.
|
// Installs handlers for API resources.
|
||||||
func (a *APIInstaller) Install() (ws *restful.WebService, errors []error) {
|
func (a *APIInstaller) Install() (ws *restful.WebService, errors []error) {
|
||||||
errors = make([]error, 0)
|
errors = make([]error, 0)
|
||||||
@ -161,6 +164,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
|
|||||||
if scope.Name() != meta.RESTScopeNameNamespace {
|
if scope.Name() != meta.RESTScopeNameNamespace {
|
||||||
objNameFn = func(obj runtime.Object) (namespace, name string, err error) {
|
objNameFn = func(obj runtime.Object) (namespace, name string, err error) {
|
||||||
name, err = linker.Name(obj)
|
name, err = linker.Name(obj)
|
||||||
|
if len(name) == 0 {
|
||||||
|
err = errEmptyName
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,6 +182,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
|
|||||||
}
|
}
|
||||||
nameFn = func(req *restful.Request) (namespace, name string, err error) {
|
nameFn = func(req *restful.Request) (namespace, name string, err error) {
|
||||||
name = req.PathParameter("name")
|
name = req.PathParameter("name")
|
||||||
|
if len(name) == 0 {
|
||||||
|
err = errEmptyName
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
generateLinkFn = func(namespace, name string) (path string, query string) {
|
generateLinkFn = func(namespace, name string) (path string, query string) {
|
||||||
@ -223,6 +232,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
|
|||||||
nameFn = func(req *restful.Request) (namespace, name string, err error) {
|
nameFn = func(req *restful.Request) (namespace, name string, err error) {
|
||||||
namespace, _ = namespaceFn(req)
|
namespace, _ = namespaceFn(req)
|
||||||
name = req.PathParameter("name")
|
name = req.PathParameter("name")
|
||||||
|
if len(name) == 0 {
|
||||||
|
err = errEmptyName
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
generateLinkFn = func(namespace, name string) (path string, query string) {
|
generateLinkFn = func(namespace, name string) (path string, query string) {
|
||||||
@ -265,6 +277,9 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage RESTStorage
|
|||||||
nameFn = func(req *restful.Request) (namespace, name string, err error) {
|
nameFn = func(req *restful.Request) (namespace, name string, err error) {
|
||||||
namespace, _ = namespaceFn(req)
|
namespace, _ = namespaceFn(req)
|
||||||
name = req.PathParameter("name")
|
name = req.PathParameter("name")
|
||||||
|
if len(name) == 0 {
|
||||||
|
err = errEmptyName
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
generateLinkFn = func(namespace, name string) (path string, query string) {
|
generateLinkFn = func(namespace, name string) (path string, query string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user