container.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package container
  2. import (
  3. "github.com/docker/docker/api/server/httputils"
  4. "github.com/docker/docker/api/server/router"
  5. )
  6. type validationError struct {
  7. cause error
  8. }
  9. func (e validationError) Error() string {
  10. return e.cause.Error()
  11. }
  12. func (e validationError) Cause() error {
  13. return e.cause
  14. }
  15. func (e validationError) InvalidParameter() {}
  16. // containerRouter is a router to talk with the container controller
  17. type containerRouter struct {
  18. backend Backend
  19. decoder httputils.ContainerDecoder
  20. routes []router.Route
  21. }
  22. // NewRouter initializes a new container router
  23. func NewRouter(b Backend, decoder httputils.ContainerDecoder) router.Router {
  24. r := &containerRouter{
  25. backend: b,
  26. decoder: decoder,
  27. }
  28. r.initRoutes()
  29. return r
  30. }
  31. // Routes returns the available routes to the container controller
  32. func (r *containerRouter) Routes() []router.Route {
  33. return r.routes
  34. }
  35. // initRoutes initializes the routes in container router
  36. func (r *containerRouter) initRoutes() {
  37. r.routes = []router.Route{
  38. // HEAD
  39. router.NewHeadRoute("/containers/{name:.*}/archive", r.headContainersArchive),
  40. // GET
  41. router.NewGetRoute("/containers/json", r.getContainersJSON),
  42. router.NewGetRoute("/containers/{name:.*}/export", r.getContainersExport),
  43. router.NewGetRoute("/containers/{name:.*}/changes", r.getContainersChanges),
  44. router.NewGetRoute("/containers/{name:.*}/json", r.getContainersByName),
  45. router.NewGetRoute("/containers/{name:.*}/top", r.getContainersTop),
  46. router.NewGetRoute("/containers/{name:.*}/logs", r.getContainersLogs, router.WithCancel),
  47. router.NewGetRoute("/containers/{name:.*}/stats", r.getContainersStats, router.WithCancel),
  48. router.NewGetRoute("/containers/{name:.*}/attach/ws", r.wsContainersAttach),
  49. router.NewGetRoute("/exec/{id:.*}/json", r.getExecByID),
  50. router.NewGetRoute("/containers/{name:.*}/archive", r.getContainersArchive),
  51. // POST
  52. router.NewPostRoute("/containers/create", r.postContainersCreate),
  53. router.NewPostRoute("/containers/{name:.*}/kill", r.postContainersKill),
  54. router.NewPostRoute("/containers/{name:.*}/pause", r.postContainersPause),
  55. router.NewPostRoute("/containers/{name:.*}/unpause", r.postContainersUnpause),
  56. router.NewPostRoute("/containers/{name:.*}/restart", r.postContainersRestart),
  57. router.NewPostRoute("/containers/{name:.*}/start", r.postContainersStart),
  58. router.NewPostRoute("/containers/{name:.*}/stop", r.postContainersStop),
  59. router.NewPostRoute("/containers/{name:.*}/wait", r.postContainersWait, router.WithCancel),
  60. router.NewPostRoute("/containers/{name:.*}/resize", r.postContainersResize),
  61. router.NewPostRoute("/containers/{name:.*}/attach", r.postContainersAttach),
  62. router.NewPostRoute("/containers/{name:.*}/copy", r.postContainersCopy), // Deprecated since 1.8, Errors out since 1.12
  63. router.NewPostRoute("/containers/{name:.*}/exec", r.postContainerExecCreate),
  64. router.NewPostRoute("/exec/{name:.*}/start", r.postContainerExecStart),
  65. router.NewPostRoute("/exec/{name:.*}/resize", r.postContainerExecResize),
  66. router.NewPostRoute("/containers/{name:.*}/rename", r.postContainerRename),
  67. router.NewPostRoute("/containers/{name:.*}/update", r.postContainerUpdate),
  68. router.NewPostRoute("/containers/prune", r.postContainersPrune, router.WithCancel),
  69. // PUT
  70. router.NewPutRoute("/containers/{name:.*}/archive", r.putContainersArchive),
  71. // DELETE
  72. router.NewDeleteRoute("/containers/{name:.*}", r.deleteContainers),
  73. }
  74. }