github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/pkg/api/server/register_exec.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/containers/libpod/pkg/api/handlers/compat"
     7  	"github.com/gorilla/mux"
     8  )
     9  
    10  func (s *APIServer) registerExecHandlers(r *mux.Router) error {
    11  	// swagger:operation POST /containers/{name}/exec compat createExec
    12  	// ---
    13  	// tags:
    14  	//   - exec (compat)
    15  	// summary: Create an exec instance
    16  	// description: Run a command inside a running container.
    17  	// parameters:
    18  	//  - in: path
    19  	//    name: name
    20  	//    type: string
    21  	//    required: true
    22  	//    description: name of container
    23  	//  - in: body
    24  	//    name: control
    25  	//    description: Attributes for create
    26  	//    schema:
    27  	//      type: object
    28  	//      properties:
    29  	//        AttachStdin:
    30  	//          type: boolean
    31  	//          description: Attach to stdin of the exec command
    32  	//        AttachStdout:
    33  	//          type: boolean
    34  	//          description: Attach to stdout of the exec command
    35  	//        AttachStderr:
    36  	//          type: boolean
    37  	//          description: Attach to stderr of the exec command
    38  	//        DetachKeys:
    39  	//          type: string
    40  	//          description: |
    41  	//           "Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _."
    42  	//        Tty:
    43  	//          type: boolean
    44  	//          description: Allocate a pseudo-TTY
    45  	//        Env:
    46  	//          type: array
    47  	//          description: A list of environment variables in the form ["VAR=value", ...]
    48  	//          items:
    49  	//            type: string
    50  	//        Cmd:
    51  	//          type: array
    52  	//          description: Command to run, as a string or array of strings.
    53  	//          items:
    54  	//            type: string
    55  	//        Privileged:
    56  	//          type: boolean
    57  	//          default: false
    58  	//          description: Runs the exec process with extended privileges
    59  	//        User:
    60  	//          type: string
    61  	//          description: |
    62  	//           "The user, and optionally, group to run the exec process inside the container. Format is one of: user, user:group, uid, or uid:gid."
    63  	//        WorkingDir:
    64  	//          type: string
    65  	//          description: The working directory for the exec process inside the container.
    66  	// produces:
    67  	// - application/json
    68  	// responses:
    69  	//   201:
    70  	//     description: no error
    71  	//   404:
    72  	//     $ref: "#/responses/NoSuchContainer"
    73  	//   409:
    74  	//	   description: container is paused
    75  	//   500:
    76  	//     $ref: "#/responses/InternalError"
    77  	r.Handle(VersionedPath("/containers/{name}/exec"), s.APIHandler(compat.ExecCreateHandler)).Methods(http.MethodPost)
    78  	// Added non version path to URI to support docker non versioned paths
    79  	r.Handle("/containers/{name}/exec", s.APIHandler(compat.ExecCreateHandler)).Methods(http.MethodPost)
    80  	// swagger:operation POST /exec/{id}/start compat startExec
    81  	// ---
    82  	// tags:
    83  	//   - exec (compat)
    84  	// summary: Start an exec instance
    85  	// description: Starts a previously set up exec instance. If detach is true, this endpoint returns immediately after starting the command. Otherwise, it sets up an interactive session with the command.
    86  	// parameters:
    87  	//  - in: path
    88  	//    name: id
    89  	//    type: string
    90  	//    required: true
    91  	//    description: Exec instance ID
    92  	//  - in: body
    93  	//    name: control
    94  	//    description: Attributes for start
    95  	//    schema:
    96  	//      type: object
    97  	//      properties:
    98  	//        Detach:
    99  	//          type: boolean
   100  	//          description: Detach from the command
   101  	//        Tty:
   102  	//          type: boolean
   103  	//          description: Allocate a pseudo-TTY
   104  	// produces:
   105  	// - application/json
   106  	// responses:
   107  	//   200:
   108  	//     description: no error
   109  	//   404:
   110  	//     $ref: "#/responses/NoSuchExecInstance"
   111  	//   409:
   112  	//	   description: container is stopped or paused
   113  	//   500:
   114  	//     $ref: "#/responses/InternalError"
   115  	r.Handle(VersionedPath("/exec/{id}/start"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
   116  	// Added non version path to URI to support docker non versioned paths
   117  	r.Handle("/exec/{id}/start", s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
   118  	// swagger:operation POST /exec/{id}/resize compat resizeExec
   119  	// ---
   120  	// tags:
   121  	//   - exec (compat)
   122  	// summary: Resize an exec instance
   123  	// description: |
   124  	//  Resize the TTY session used by an exec instance. This endpoint only works if tty was specified as part of creating and starting the exec instance.
   125  	// parameters:
   126  	//  - in: path
   127  	//    name: id
   128  	//    type: string
   129  	//    required: true
   130  	//    description: Exec instance ID
   131  	//  - in: query
   132  	//    name: h
   133  	//    type: integer
   134  	//    description: Height of the TTY session in characters
   135  	//  - in: query
   136  	//    name: w
   137  	//    type: integer
   138  	//    description: Width of the TTY session in characters
   139  	// produces:
   140  	// - application/json
   141  	// responses:
   142  	//   201:
   143  	//     description: no error
   144  	//   404:
   145  	//     $ref: "#/responses/NoSuchExecInstance"
   146  	//   500:
   147  	//     $ref: "#/responses/InternalError"
   148  	r.Handle(VersionedPath("/exec/{id}/resize"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
   149  	// Added non version path to URI to support docker non versioned paths
   150  	r.Handle("/exec/{id}/resize", s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
   151  	// swagger:operation GET /exec/{id}/json compat inspectExec
   152  	// ---
   153  	// tags:
   154  	//   - exec (compat)
   155  	// summary: Inspect an exec instance
   156  	// description: Return low-level information about an exec instance.
   157  	// parameters:
   158  	//  - in: path
   159  	//    name: id
   160  	//    type: string
   161  	//    required: true
   162  	//    description: Exec instance ID
   163  	// produces:
   164  	// - application/json
   165  	// responses:
   166  	//   200:
   167  	//     description: no error
   168  	//   404:
   169  	//     $ref: "#/responses/NoSuchExecInstance"
   170  	//   500:
   171  	//     $ref: "#/responses/InternalError"
   172  	r.Handle(VersionedPath("/exec/{id}/json"), s.APIHandler(compat.ExecInspectHandler)).Methods(http.MethodGet)
   173  	// Added non version path to URI to support docker non versioned paths
   174  	r.Handle("/exec/{id}/json", s.APIHandler(compat.ExecInspectHandler)).Methods(http.MethodGet)
   175  
   176  	/*
   177  		libpod api follows
   178  	*/
   179  
   180  	// swagger:operation POST /libpod/containers/{name}/exec libpod libpodCreateExec
   181  	// ---
   182  	// tags:
   183  	//   - exec
   184  	// summary: Create an exec instance
   185  	// description: Run a command inside a running container.
   186  	// parameters:
   187  	//  - in: path
   188  	//    name: name
   189  	//    type: string
   190  	//    required: true
   191  	//    description: name of container
   192  	//  - in: body
   193  	//    name: control
   194  	//    description: Attributes for create
   195  	//    schema:
   196  	//      type: object
   197  	//      properties:
   198  	//        AttachStdin:
   199  	//          type: boolean
   200  	//          description: Attach to stdin of the exec command
   201  	//        AttachStdout:
   202  	//          type: boolean
   203  	//          description: Attach to stdout of the exec command
   204  	//        AttachStderr:
   205  	//          type: boolean
   206  	//          description: Attach to stderr of the exec command
   207  	//        DetachKeys:
   208  	//          type: string
   209  	//          description: |
   210  	//           "Override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _."
   211  	//        Tty:
   212  	//          type: boolean
   213  	//          description: Allocate a pseudo-TTY
   214  	//        Env:
   215  	//          type: array
   216  	//          description: A list of environment variables in the form ["VAR=value", ...]
   217  	//          items:
   218  	//            type: string
   219  	//        Cmd:
   220  	//          type: array
   221  	//          description: Command to run, as a string or array of strings.
   222  	//          items:
   223  	//            type: string
   224  	//        Privileged:
   225  	//          type: boolean
   226  	//          default: false
   227  	//          description: Runs the exec process with extended privileges
   228  	//        User:
   229  	//          type: string
   230  	//          description: |
   231  	//           "The user, and optionally, group to run the exec process inside the container. Format is one of: user, user:group, uid, or uid:gid."
   232  	//        WorkingDir:
   233  	//          type: string
   234  	//          description: The working directory for the exec process inside the container.
   235  	// produces:
   236  	// - application/json
   237  	// responses:
   238  	//   201:
   239  	//     description: no error
   240  	//   404:
   241  	//     $ref: "#/responses/NoSuchContainer"
   242  	//   409:
   243  	//	   description: container is paused
   244  	//   500:
   245  	//     $ref: "#/responses/InternalError"
   246  	r.Handle(VersionedPath("/libpod/containers/{name}/exec"), s.APIHandler(compat.ExecCreateHandler)).Methods(http.MethodPost)
   247  	// swagger:operation POST /libpod/exec/{id}/start libpod libpodStartExec
   248  	// ---
   249  	// tags:
   250  	//   - exec
   251  	// summary: Start an exec instance
   252  	// description: Starts a previously set up exec instance. If detach is true, this endpoint returns immediately after starting the command. Otherwise, it sets up an interactive session with the command.
   253  	// parameters:
   254  	//  - in: path
   255  	//    name: id
   256  	//    type: string
   257  	//    required: true
   258  	//    description: Exec instance ID
   259  	//  - in: body
   260  	//    name: control
   261  	//    description: Attributes for start
   262  	//    schema:
   263  	//      type: object
   264  	//      properties:
   265  	//        Detach:
   266  	//          type: boolean
   267  	//          description: Detach from the command
   268  	//        Tty:
   269  	//          type: boolean
   270  	//          description: Allocate a pseudo-TTY
   271  	// produces:
   272  	// - application/json
   273  	// responses:
   274  	//   200:
   275  	//     description: no error
   276  	//   404:
   277  	//     $ref: "#/responses/NoSuchExecInstance"
   278  	//   409:
   279  	//	   description: container is stopped or paused
   280  	//   500:
   281  	//     $ref: "#/responses/InternalError"
   282  	r.Handle(VersionedPath("/libpod/exec/{id}/start"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
   283  	// swagger:operation POST /libpod/exec/{id}/resize libpod libpodResizeExec
   284  	// ---
   285  	// tags:
   286  	//   - exec
   287  	// summary: Resize an exec instance
   288  	// description: |
   289  	//  Resize the TTY session used by an exec instance. This endpoint only works if tty was specified as part of creating and starting the exec instance.
   290  	// parameters:
   291  	//  - in: path
   292  	//    name: id
   293  	//    type: string
   294  	//    required: true
   295  	//    description: Exec instance ID
   296  	//  - in: query
   297  	//    name: h
   298  	//    type: integer
   299  	//    description: Height of the TTY session in characters
   300  	//  - in: query
   301  	//    name: w
   302  	//    type: integer
   303  	//    description: Width of the TTY session in characters
   304  	// produces:
   305  	// - application/json
   306  	// responses:
   307  	//   201:
   308  	//     description: no error
   309  	//   404:
   310  	//     $ref: "#/responses/NoSuchExecInstance"
   311  	//   500:
   312  	//     $ref: "#/responses/InternalError"
   313  	r.Handle(VersionedPath("/libpod/exec/{id}/resize"), s.APIHandler(compat.UnsupportedHandler)).Methods(http.MethodPost)
   314  	// swagger:operation GET /libpod/exec/{id}/json libpod libpodInspectExec
   315  	// ---
   316  	// tags:
   317  	//   - exec
   318  	// summary: Inspect an exec instance
   319  	// description: Return low-level information about an exec instance.
   320  	// parameters:
   321  	//  - in: path
   322  	//    name: id
   323  	//    type: string
   324  	//    required: true
   325  	//    description: Exec instance ID
   326  	// produces:
   327  	// - application/json
   328  	// responses:
   329  	//   200:
   330  	//     description: no error
   331  	//   404:
   332  	//     $ref: "#/responses/NoSuchExecInstance"
   333  	//   500:
   334  	//     $ref: "#/responses/InternalError"
   335  	r.Handle(VersionedPath("/libpod/exec/{id}/json"), s.APIHandler(compat.ExecInspectHandler)).Methods(http.MethodGet)
   336  	return nil
   337  }