github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/api/server/register_exec.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/hanks177/podman/v4/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 ContainerExec
    12  	// ---
    13  	// tags:
    14  	//   - exec (compat)
    15  	// summary: Create an exec instance
    16  	// description: Create an exec session to run a command inside a running container. Exec sessions will be automatically removed 5 minutes after they exit.
    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/containerNotFound"
    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 ExecStart
    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. Not presently supported.
   101  	//        Tty:
   102  	//          type: boolean
   103  	//          description: Allocate a pseudo-TTY. Presently ignored.
   104  	// produces:
   105  	// - application/octet-stream
   106  	// responses:
   107  	//   200:
   108  	//     description: no error
   109  	//   404:
   110  	//     $ref: "#/responses/execSessionNotFound"
   111  	//   409:
   112  	//	   description: container is not running
   113  	//   500:
   114  	//     $ref: "#/responses/internalError"
   115  	r.Handle(VersionedPath("/exec/{id}/start"), s.APIHandler(compat.ExecStartHandler)).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.ExecStartHandler)).Methods(http.MethodPost)
   118  	// swagger:operation POST /exec/{id}/resize compat ExecResize
   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  	//  - in: query
   140  	//    name: running
   141  	//    type: boolean
   142  	//    required: false
   143  	//    description: Ignore containers not running errors
   144  	// produces:
   145  	// - application/json
   146  	// responses:
   147  	//   201:
   148  	//     description: no error
   149  	//   404:
   150  	//     $ref: "#/responses/execSessionNotFound"
   151  	//   500:
   152  	//     $ref: "#/responses/internalError"
   153  	r.Handle(VersionedPath("/exec/{id}/resize"), s.APIHandler(compat.ResizeTTY)).Methods(http.MethodPost)
   154  	// Added non version path to URI to support docker non versioned paths
   155  	r.Handle("/exec/{id}/resize", s.APIHandler(compat.ResizeTTY)).Methods(http.MethodPost)
   156  	// swagger:operation GET /exec/{id}/json compat ExecInspect
   157  	// ---
   158  	// tags:
   159  	//   - exec (compat)
   160  	// summary: Inspect an exec instance
   161  	// description: Return low-level information about an exec instance.
   162  	// parameters:
   163  	//  - in: path
   164  	//    name: id
   165  	//    type: string
   166  	//    required: true
   167  	//    description: Exec instance ID
   168  	// produces:
   169  	// - application/json
   170  	// responses:
   171  	//   200:
   172  	//     $ref: "#/responses/execSessionInspect"
   173  	//   404:
   174  	//     $ref: "#/responses/execSessionNotFound"
   175  	//   500:
   176  	//     $ref: "#/responses/internalError"
   177  	r.Handle(VersionedPath("/exec/{id}/json"), s.APIHandler(compat.ExecInspectHandler)).Methods(http.MethodGet)
   178  	// Added non version path to URI to support docker non versioned paths
   179  	r.Handle("/exec/{id}/json", s.APIHandler(compat.ExecInspectHandler)).Methods(http.MethodGet)
   180  
   181  	/*
   182  		libpod api follows
   183  	*/
   184  
   185  	// swagger:operation POST /libpod/containers/{name}/exec libpod ContainerExecLibpod
   186  	// ---
   187  	// tags:
   188  	//   - exec
   189  	// summary: Create an exec instance
   190  	// description: Create an exec session to run a command inside a running container. Exec sessions will be automatically removed 5 minutes after they exit.
   191  	// parameters:
   192  	//  - in: path
   193  	//    name: name
   194  	//    type: string
   195  	//    required: true
   196  	//    description: name of container
   197  	//  - in: body
   198  	//    name: control
   199  	//    description: Attributes for create
   200  	//    schema:
   201  	//      type: object
   202  	//      properties:
   203  	//        AttachStdin:
   204  	//          type: boolean
   205  	//          description: Attach to stdin of the exec command
   206  	//        AttachStdout:
   207  	//          type: boolean
   208  	//          description: Attach to stdout of the exec command
   209  	//        AttachStderr:
   210  	//          type: boolean
   211  	//          description: Attach to stderr of the exec command
   212  	//        DetachKeys:
   213  	//          type: string
   214  	//          description: |
   215  	//           "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 _."
   216  	//        Tty:
   217  	//          type: boolean
   218  	//          description: Allocate a pseudo-TTY
   219  	//        Env:
   220  	//          type: array
   221  	//          description: A list of environment variables in the form ["VAR=value", ...]
   222  	//          items:
   223  	//            type: string
   224  	//        Cmd:
   225  	//          type: array
   226  	//          description: Command to run, as a string or array of strings.
   227  	//          items:
   228  	//            type: string
   229  	//        Privileged:
   230  	//          type: boolean
   231  	//          default: false
   232  	//          description: Runs the exec process with extended privileges
   233  	//        User:
   234  	//          type: string
   235  	//          description: |
   236  	//           "The user, and optionally, group to run the exec process inside the container. Format is one of: user, user:group, uid, or uid:gid."
   237  	//        WorkingDir:
   238  	//          type: string
   239  	//          description: The working directory for the exec process inside the container.
   240  	// produces:
   241  	// - application/json
   242  	// responses:
   243  	//   201:
   244  	//     description: no error
   245  	//   404:
   246  	//     $ref: "#/responses/containerNotFound"
   247  	//   409:
   248  	//	   description: container is paused
   249  	//   500:
   250  	//     $ref: "#/responses/internalError"
   251  	r.Handle(VersionedPath("/libpod/containers/{name}/exec"), s.APIHandler(compat.ExecCreateHandler)).Methods(http.MethodPost)
   252  	// swagger:operation POST /libpod/exec/{id}/start libpod ExecStartLibpod
   253  	// ---
   254  	// tags:
   255  	//   - exec
   256  	// summary: Start an exec instance
   257  	// 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.
   258  	// parameters:
   259  	//  - in: path
   260  	//    name: id
   261  	//    type: string
   262  	//    required: true
   263  	//    description: Exec instance ID
   264  	//  - in: body
   265  	//    name: control
   266  	//    description: Attributes for start
   267  	//    schema:
   268  	//      type: object
   269  	//      properties:
   270  	//        Detach:
   271  	//          type: boolean
   272  	//          description: Detach from the command.
   273  	//        Tty:
   274  	//          type: boolean
   275  	//          description: Allocate a pseudo-TTY.
   276  	//        h:
   277  	//          type: integer
   278  	//          description: Height of the TTY session in characters. Tty must be set to true to use it.
   279  	//        w:
   280  	//          type: integer
   281  	//          description: Width of the TTY session in characters. Tty must be set to true to use it.
   282  	// produces:
   283  	// - application/json
   284  	// responses:
   285  	//   200:
   286  	//     description: no error
   287  	//   404:
   288  	//     $ref: "#/responses/execSessionNotFound"
   289  	//   409:
   290  	//	   description: container is not running.
   291  	//   500:
   292  	//     $ref: "#/responses/internalError"
   293  	r.Handle(VersionedPath("/libpod/exec/{id}/start"), s.APIHandler(compat.ExecStartHandler)).Methods(http.MethodPost)
   294  	// swagger:operation POST /libpod/exec/{id}/resize libpod ExecResizeLibpod
   295  	// ---
   296  	// tags:
   297  	//   - exec
   298  	// summary: Resize an exec instance
   299  	// description: |
   300  	//  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.
   301  	// parameters:
   302  	//  - in: path
   303  	//    name: id
   304  	//    type: string
   305  	//    required: true
   306  	//    description: Exec instance ID
   307  	//  - in: query
   308  	//    name: h
   309  	//    type: integer
   310  	//    description: Height of the TTY session in characters
   311  	//  - in: query
   312  	//    name: w
   313  	//    type: integer
   314  	//    description: Width of the TTY session in characters
   315  	// produces:
   316  	// - application/json
   317  	// responses:
   318  	//   201:
   319  	//     description: no error
   320  	//   404:
   321  	//     $ref: "#/responses/execSessionNotFound"
   322  	//   500:
   323  	//     $ref: "#/responses/internalError"
   324  	r.Handle(VersionedPath("/libpod/exec/{id}/resize"), s.APIHandler(compat.ResizeTTY)).Methods(http.MethodPost)
   325  	// swagger:operation GET /libpod/exec/{id}/json libpod ExecInspectLibpod
   326  	// ---
   327  	// tags:
   328  	//   - exec
   329  	// summary: Inspect an exec instance
   330  	// description: Return low-level information about an exec instance.
   331  	// parameters:
   332  	//  - in: path
   333  	//    name: id
   334  	//    type: string
   335  	//    required: true
   336  	//    description: Exec instance ID
   337  	// produces:
   338  	// - application/json
   339  	// responses:
   340  	//   200:
   341  	//     description: no error
   342  	//   404:
   343  	//     $ref: "#/responses/execSessionNotFound"
   344  	//   500:
   345  	//     $ref: "#/responses/internalError"
   346  	r.Handle(VersionedPath("/libpod/exec/{id}/json"), s.APIHandler(compat.ExecInspectHandler)).Methods(http.MethodGet)
   347  	return nil
   348  }