github.com/moby/docker@v26.1.3+incompatible/api/types/client.go (about)

     1  package types // import "github.com/docker/docker/api/types"
     2  
     3  import (
     4  	"bufio"
     5  	"io"
     6  	"net"
     7  
     8  	"github.com/docker/docker/api/types/container"
     9  	"github.com/docker/docker/api/types/filters"
    10  	"github.com/docker/docker/api/types/registry"
    11  	units "github.com/docker/go-units"
    12  )
    13  
    14  // ContainerExecInspect holds information returned by exec inspect.
    15  type ContainerExecInspect struct {
    16  	ExecID      string `json:"ID"`
    17  	ContainerID string
    18  	Running     bool
    19  	ExitCode    int
    20  	Pid         int
    21  }
    22  
    23  // CopyToContainerOptions holds information
    24  // about files to copy into a container
    25  type CopyToContainerOptions struct {
    26  	AllowOverwriteDirWithFile bool
    27  	CopyUIDGID                bool
    28  }
    29  
    30  // EventsOptions holds parameters to filter events with.
    31  type EventsOptions struct {
    32  	Since   string
    33  	Until   string
    34  	Filters filters.Args
    35  }
    36  
    37  // NetworkListOptions holds parameters to filter the list of networks with.
    38  type NetworkListOptions struct {
    39  	Filters filters.Args
    40  }
    41  
    42  // NewHijackedResponse intializes a HijackedResponse type
    43  func NewHijackedResponse(conn net.Conn, mediaType string) HijackedResponse {
    44  	return HijackedResponse{Conn: conn, Reader: bufio.NewReader(conn), mediaType: mediaType}
    45  }
    46  
    47  // HijackedResponse holds connection information for a hijacked request.
    48  type HijackedResponse struct {
    49  	mediaType string
    50  	Conn      net.Conn
    51  	Reader    *bufio.Reader
    52  }
    53  
    54  // Close closes the hijacked connection and reader.
    55  func (h *HijackedResponse) Close() {
    56  	h.Conn.Close()
    57  }
    58  
    59  // MediaType let client know if HijackedResponse hold a raw or multiplexed stream.
    60  // returns false if HTTP Content-Type is not relevant, and container must be inspected
    61  func (h *HijackedResponse) MediaType() (string, bool) {
    62  	if h.mediaType == "" {
    63  		return "", false
    64  	}
    65  	return h.mediaType, true
    66  }
    67  
    68  // CloseWriter is an interface that implements structs
    69  // that close input streams to prevent from writing.
    70  type CloseWriter interface {
    71  	CloseWrite() error
    72  }
    73  
    74  // CloseWrite closes a readWriter for writing.
    75  func (h *HijackedResponse) CloseWrite() error {
    76  	if conn, ok := h.Conn.(CloseWriter); ok {
    77  		return conn.CloseWrite()
    78  	}
    79  	return nil
    80  }
    81  
    82  // ImageBuildOptions holds the information
    83  // necessary to build images.
    84  type ImageBuildOptions struct {
    85  	Tags           []string
    86  	SuppressOutput bool
    87  	RemoteContext  string
    88  	NoCache        bool
    89  	Remove         bool
    90  	ForceRemove    bool
    91  	PullParent     bool
    92  	Isolation      container.Isolation
    93  	CPUSetCPUs     string
    94  	CPUSetMems     string
    95  	CPUShares      int64
    96  	CPUQuota       int64
    97  	CPUPeriod      int64
    98  	Memory         int64
    99  	MemorySwap     int64
   100  	CgroupParent   string
   101  	NetworkMode    string
   102  	ShmSize        int64
   103  	Dockerfile     string
   104  	Ulimits        []*units.Ulimit
   105  	// BuildArgs needs to be a *string instead of just a string so that
   106  	// we can tell the difference between "" (empty string) and no value
   107  	// at all (nil). See the parsing of buildArgs in
   108  	// api/server/router/build/build_routes.go for even more info.
   109  	BuildArgs   map[string]*string
   110  	AuthConfigs map[string]registry.AuthConfig
   111  	Context     io.Reader
   112  	Labels      map[string]string
   113  	// squash the resulting image's layers to the parent
   114  	// preserves the original image and creates a new one from the parent with all
   115  	// the changes applied to a single layer
   116  	Squash bool
   117  	// CacheFrom specifies images that are used for matching cache. Images
   118  	// specified here do not need to have a valid parent chain to match cache.
   119  	CacheFrom   []string
   120  	SecurityOpt []string
   121  	ExtraHosts  []string // List of extra hosts
   122  	Target      string
   123  	SessionID   string
   124  	Platform    string
   125  	// Version specifies the version of the unerlying builder to use
   126  	Version BuilderVersion
   127  	// BuildID is an optional identifier that can be passed together with the
   128  	// build request. The same identifier can be used to gracefully cancel the
   129  	// build with the cancel request.
   130  	BuildID string
   131  	// Outputs defines configurations for exporting build results. Only supported
   132  	// in BuildKit mode
   133  	Outputs []ImageBuildOutput
   134  }
   135  
   136  // ImageBuildOutput defines configuration for exporting a build result
   137  type ImageBuildOutput struct {
   138  	Type  string
   139  	Attrs map[string]string
   140  }
   141  
   142  // BuilderVersion sets the version of underlying builder to use
   143  type BuilderVersion string
   144  
   145  const (
   146  	// BuilderV1 is the first generation builder in docker daemon
   147  	BuilderV1 BuilderVersion = "1"
   148  	// BuilderBuildKit is builder based on moby/buildkit project
   149  	BuilderBuildKit BuilderVersion = "2"
   150  )
   151  
   152  // ImageBuildResponse holds information
   153  // returned by a server after building
   154  // an image.
   155  type ImageBuildResponse struct {
   156  	Body   io.ReadCloser
   157  	OSType string
   158  }
   159  
   160  // ImageImportSource holds source information for ImageImport
   161  type ImageImportSource struct {
   162  	Source     io.Reader // Source is the data to send to the server to create this image from. You must set SourceName to "-" to leverage this.
   163  	SourceName string    // SourceName is the name of the image to pull. Set to "-" to leverage the Source attribute.
   164  }
   165  
   166  // ImageLoadResponse returns information to the client about a load process.
   167  type ImageLoadResponse struct {
   168  	// Body must be closed to avoid a resource leak
   169  	Body io.ReadCloser
   170  	JSON bool
   171  }
   172  
   173  // RequestPrivilegeFunc is a function interface that
   174  // clients can supply to retry operations after
   175  // getting an authorization error.
   176  // This function returns the registry authentication
   177  // header value in base 64 format, or an error
   178  // if the privilege request fails.
   179  type RequestPrivilegeFunc func() (string, error)
   180  
   181  // ImageSearchOptions holds parameters to search images with.
   182  type ImageSearchOptions struct {
   183  	RegistryAuth  string
   184  	PrivilegeFunc RequestPrivilegeFunc
   185  	Filters       filters.Args
   186  	Limit         int
   187  }
   188  
   189  // NodeListOptions holds parameters to list nodes with.
   190  type NodeListOptions struct {
   191  	Filters filters.Args
   192  }
   193  
   194  // NodeRemoveOptions holds parameters to remove nodes with.
   195  type NodeRemoveOptions struct {
   196  	Force bool
   197  }
   198  
   199  // ServiceCreateOptions contains the options to use when creating a service.
   200  type ServiceCreateOptions struct {
   201  	// EncodedRegistryAuth is the encoded registry authorization credentials to
   202  	// use when updating the service.
   203  	//
   204  	// This field follows the format of the X-Registry-Auth header.
   205  	EncodedRegistryAuth string
   206  
   207  	// QueryRegistry indicates whether the service update requires
   208  	// contacting a registry. A registry may be contacted to retrieve
   209  	// the image digest and manifest, which in turn can be used to update
   210  	// platform or other information about the service.
   211  	QueryRegistry bool
   212  }
   213  
   214  // Values for RegistryAuthFrom in ServiceUpdateOptions
   215  const (
   216  	RegistryAuthFromSpec         = "spec"
   217  	RegistryAuthFromPreviousSpec = "previous-spec"
   218  )
   219  
   220  // ServiceUpdateOptions contains the options to be used for updating services.
   221  type ServiceUpdateOptions struct {
   222  	// EncodedRegistryAuth is the encoded registry authorization credentials to
   223  	// use when updating the service.
   224  	//
   225  	// This field follows the format of the X-Registry-Auth header.
   226  	EncodedRegistryAuth string
   227  
   228  	// TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
   229  	// into this field. While it does open API users up to racy writes, most
   230  	// users may not need that level of consistency in practice.
   231  
   232  	// RegistryAuthFrom specifies where to find the registry authorization
   233  	// credentials if they are not given in EncodedRegistryAuth. Valid
   234  	// values are "spec" and "previous-spec".
   235  	RegistryAuthFrom string
   236  
   237  	// Rollback indicates whether a server-side rollback should be
   238  	// performed. When this is set, the provided spec will be ignored.
   239  	// The valid values are "previous" and "none". An empty value is the
   240  	// same as "none".
   241  	Rollback string
   242  
   243  	// QueryRegistry indicates whether the service update requires
   244  	// contacting a registry. A registry may be contacted to retrieve
   245  	// the image digest and manifest, which in turn can be used to update
   246  	// platform or other information about the service.
   247  	QueryRegistry bool
   248  }
   249  
   250  // ServiceListOptions holds parameters to list services with.
   251  type ServiceListOptions struct {
   252  	Filters filters.Args
   253  
   254  	// Status indicates whether the server should include the service task
   255  	// count of running and desired tasks.
   256  	Status bool
   257  }
   258  
   259  // ServiceInspectOptions holds parameters related to the "service inspect"
   260  // operation.
   261  type ServiceInspectOptions struct {
   262  	InsertDefaults bool
   263  }
   264  
   265  // TaskListOptions holds parameters to list tasks with.
   266  type TaskListOptions struct {
   267  	Filters filters.Args
   268  }
   269  
   270  // PluginRemoveOptions holds parameters to remove plugins.
   271  type PluginRemoveOptions struct {
   272  	Force bool
   273  }
   274  
   275  // PluginEnableOptions holds parameters to enable plugins.
   276  type PluginEnableOptions struct {
   277  	Timeout int
   278  }
   279  
   280  // PluginDisableOptions holds parameters to disable plugins.
   281  type PluginDisableOptions struct {
   282  	Force bool
   283  }
   284  
   285  // PluginInstallOptions holds parameters to install a plugin.
   286  type PluginInstallOptions struct {
   287  	Disabled              bool
   288  	AcceptAllPermissions  bool
   289  	RegistryAuth          string // RegistryAuth is the base64 encoded credentials for the registry
   290  	RemoteRef             string // RemoteRef is the plugin name on the registry
   291  	PrivilegeFunc         RequestPrivilegeFunc
   292  	AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
   293  	Args                  []string
   294  }
   295  
   296  // SwarmUnlockKeyResponse contains the response for Engine API:
   297  // GET /swarm/unlockkey
   298  type SwarmUnlockKeyResponse struct {
   299  	// UnlockKey is the unlock key in ASCII-armored format.
   300  	UnlockKey string
   301  }
   302  
   303  // PluginCreateOptions hold all options to plugin create.
   304  type PluginCreateOptions struct {
   305  	RepoName string
   306  }