github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/cli/api/intercept.go (about)

     1  package api
     2  
     3  import (
     4  	"net/netip"
     5  )
     6  
     7  type InterceptRequest struct {
     8  	// Name of the intercept.
     9  	Name string
    10  
    11  	// Name of the intercepted workload. Will default to intercept name.
    12  	WorkloadName string
    13  
    14  	// Port string. Can contain three fields separated by colon. The interpretation of
    15  	// the fields differ depending on if Docker is true or false.
    16  	//
    17  	//   With Docker == false
    18  	//     <local port number>
    19  	//     <local port number>:<service port identifier>
    20  	//
    21  	//   With Docker == true
    22  	//     <local port number>:<container port number>
    23  	//     <local port number>:<container port number>:<service port identifier>
    24  	Port string
    25  
    26  	// ServiceName is the name of the intercepted service. Only needed to resolve ambiguities in
    27  	// case multiple services use the same workload.
    28  	ServiceName string
    29  
    30  	// Address The local IP address, in case the intercepted traffic should be sent to something other
    31  	// than localhost.
    32  	Address netip.Addr
    33  
    34  	// LocalMountPort is a port where the remote sftp server can be reached. If set, then Telepresence
    35  	// will assume that the caller is responsible for starting the sshfs client that will do the mounting.
    36  	LocalMountPort uint16
    37  
    38  	// Replace indicates that the intercepted container should be replaced by the intercept, and then
    39  	// restored when the intercept ends.
    40  	Replace bool
    41  
    42  	// EnvFile denotes the path to a file that will receive the intercepted containers environment in a
    43  	// Docker Compose format. See https://docs.docker.com/compose/env-file/ for details.
    44  	EnvFile string
    45  
    46  	// EnvJSON denotes the path to a file that will receive the intercepted environment as a JSON object.
    47  	EnvJSON string
    48  
    49  	// ToPod adds additional ports to forward from the intercepted pod, will be made available at localhost:PORT.
    50  	// Use this to, for example, access proxy/helper sidecars in the intercepted pod.
    51  	ToPod []netip.AddrPort
    52  
    53  	// ToPodUDP is like ToPod, but uses UDP protocol.
    54  	ToPodUDP []netip.AddrPort
    55  
    56  	// Silent will silence the intercept information. It will not silence the intercept handler.
    57  	Silent bool
    58  }
    59  
    60  type InterceptHandlerType int
    61  
    62  const (
    63  	CommandHandler InterceptHandlerType = iota
    64  	DockerRunHandler
    65  	DockerBuildHandler
    66  )
    67  
    68  type InterceptHandler interface {
    69  	Type() InterceptHandlerType
    70  }
    71  
    72  type CmdHandler struct {
    73  	// MountPoint is the path to where the remote container's mounts will be mounted. A temporary directory
    74  	// will be used if MountPoint is unset.
    75  	//
    76  	// MountPoint is either a path indicating where to mount the intercepted container's volumes, the string
    77  	// "true", to mount to a generated temporary folder, or empty to disable mounting altogether.
    78  	MountPoint string
    79  
    80  	// CmdLine a command to execute during the time when the intercept is active.
    81  	Cmdline []string
    82  }
    83  
    84  func (CmdHandler) Type() InterceptHandlerType {
    85  	return CommandHandler
    86  }
    87  
    88  type DockerRunInterceptHandler struct {
    89  	// Mount if true, will cause the volumes of the remote container to be mounted using
    90  	// the telemount Docker volume plugin.
    91  	Mount bool
    92  
    93  	// Image is the image tag
    94  	Image string
    95  
    96  	// Options for the docker run command. Must be in the form <key>=<value> or just <key>
    97  	// for boolean options. Short form options are not supported so `-it` must be added as
    98  	// []string{"interactive", "tty"}
    99  	Options []string
   100  
   101  	// Arguments for to pass to the container
   102  	Arguments []string
   103  }
   104  
   105  func (DockerRunInterceptHandler) Type() InterceptHandlerType {
   106  	return DockerRunHandler
   107  }
   108  
   109  type DockerBuildInterceptHandler struct {
   110  	// Mount if true, will cause the volumes of the remote container to be mounted using
   111  	// the telemount Docker volume plugin.
   112  	Mount bool
   113  
   114  	// Context docker context, in the form of a path or a URL.
   115  	Context string
   116  
   117  	// Options for the docker build command. Must be in the form <key>=<value> or just <key>
   118  	// for boolean options. Short form options are not supported.
   119  	BuildOptions []string
   120  
   121  	// Options for the docker run command. Must be in the form <key>=<value> or just <key>
   122  	// for boolean options. Short form options are not supported so `-it` must be added as
   123  	// []string{"interactive", "tty"}
   124  	Options []string
   125  
   126  	// Arguments for to pass to the container
   127  	Arguments []string
   128  
   129  	// Debug uses relaxed security to allow a debugger run in the container.
   130  	// Mutually exclusive to DockerRun and DockerBuild.
   131  	Debug bool
   132  }
   133  
   134  func (DockerBuildInterceptHandler) Type() InterceptHandlerType {
   135  	return DockerBuildHandler
   136  }