api/types/container: create type for changes endpoint
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
7103efac9d
commit
dbb48e4b29
12 changed files with 112 additions and 56 deletions
|
@ -1610,6 +1610,34 @@ definitions:
|
|||
"WorkDir": "/var/lib/docker/overlay2/ef749362d13333e65fc95c572eb525abbe0052e16e086cb64bc3b98ae9aa6d74/work"
|
||||
}
|
||||
|
||||
FilesystemChange:
|
||||
description: |
|
||||
Change in the container's filesystem.
|
||||
type: "object"
|
||||
required: [Path, Kind]
|
||||
properties:
|
||||
Path:
|
||||
description: |
|
||||
Path to file or directory that has changed.
|
||||
type: "string"
|
||||
x-nullable: false
|
||||
Kind:
|
||||
$ref: "#/definitions/ChangeType"
|
||||
|
||||
ChangeType:
|
||||
description: |
|
||||
Kind of change
|
||||
|
||||
Can be one of:
|
||||
|
||||
- `0`: Modified ("C")
|
||||
- `1`: Added ("A")
|
||||
- `2`: Deleted ("D")
|
||||
type: "integer"
|
||||
format: "uint8"
|
||||
enum: [0, 1, 2]
|
||||
x-nullable: false
|
||||
|
||||
ImageInspect:
|
||||
description: |
|
||||
Information about an image in the local image cache.
|
||||
|
@ -6876,9 +6904,9 @@ paths:
|
|||
Returns which files in a container's filesystem have been added, deleted,
|
||||
or modified. The `Kind` of modification can be one of:
|
||||
|
||||
- `0`: Modified
|
||||
- `1`: Added
|
||||
- `2`: Deleted
|
||||
- `0`: Modified ("C")
|
||||
- `1`: Added ("A")
|
||||
- `2`: Deleted ("D")
|
||||
operationId: "ContainerChanges"
|
||||
produces: ["application/json"]
|
||||
responses:
|
||||
|
@ -6887,22 +6915,7 @@ paths:
|
|||
schema:
|
||||
type: "array"
|
||||
items:
|
||||
type: "object"
|
||||
x-go-name: "ContainerChangeResponseItem"
|
||||
title: "ContainerChangeResponseItem"
|
||||
description: "change item in response to ContainerChanges operation"
|
||||
required: [Path, Kind]
|
||||
properties:
|
||||
Path:
|
||||
description: "Path to file that has changed"
|
||||
type: "string"
|
||||
x-nullable: false
|
||||
Kind:
|
||||
description: "Kind of change"
|
||||
type: "integer"
|
||||
format: "uint8"
|
||||
enum: [0, 1, 2]
|
||||
x-nullable: false
|
||||
$ref: "#/definitions/FilesystemChange"
|
||||
examples:
|
||||
application/json:
|
||||
- Path: "/dev"
|
||||
|
|
6
api/types/container/change_response_deprecated.go
Normal file
6
api/types/container/change_response_deprecated.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package container
|
||||
|
||||
// ContainerChangeResponseItem change item in response to ContainerChanges operation
|
||||
//
|
||||
// Deprecated: use [FilesystemChange].
|
||||
type ContainerChangeResponseItem = FilesystemChange
|
15
api/types/container/change_type.go
Normal file
15
api/types/container/change_type.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// ChangeType Kind of change
|
||||
//
|
||||
// Can be one of:
|
||||
//
|
||||
// - `0`: Modified ("C")
|
||||
// - `1`: Added ("A")
|
||||
// - `2`: Deleted ("D")
|
||||
//
|
||||
// swagger:model ChangeType
|
||||
type ChangeType uint8
|
23
api/types/container/change_types.go
Normal file
23
api/types/container/change_types.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package container
|
||||
|
||||
const (
|
||||
// ChangeModify represents the modify operation.
|
||||
ChangeModify ChangeType = 0
|
||||
// ChangeAdd represents the add operation.
|
||||
ChangeAdd ChangeType = 1
|
||||
// ChangeDelete represents the delete operation.
|
||||
ChangeDelete ChangeType = 2
|
||||
)
|
||||
|
||||
func (ct ChangeType) String() string {
|
||||
switch ct {
|
||||
case ChangeModify:
|
||||
return "C"
|
||||
case ChangeAdd:
|
||||
return "A"
|
||||
case ChangeDelete:
|
||||
return "D"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package container // import "github.com/docker/docker/api/types/container"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Code generated by `swagger generate operation`. DO NOT EDIT.
|
||||
//
|
||||
// See hack/generate-swagger-api.sh
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ContainerChangeResponseItem change item in response to ContainerChanges operation
|
||||
// swagger:model ContainerChangeResponseItem
|
||||
type ContainerChangeResponseItem struct {
|
||||
|
||||
// Kind of change
|
||||
// Required: true
|
||||
Kind uint8 `json:"Kind"`
|
||||
|
||||
// Path to file that has changed
|
||||
// Required: true
|
||||
Path string `json:"Path"`
|
||||
}
|
19
api/types/container/filesystem_change.go
Normal file
19
api/types/container/filesystem_change.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package container
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
// FilesystemChange Change in the container's filesystem.
|
||||
//
|
||||
// swagger:model FilesystemChange
|
||||
type FilesystemChange struct {
|
||||
|
||||
// kind
|
||||
// Required: true
|
||||
Kind ChangeType `json:"Kind"`
|
||||
|
||||
// Path to file or directory that has changed.
|
||||
//
|
||||
// Required: true
|
||||
Path string `json:"Path"`
|
||||
}
|
|
@ -9,8 +9,8 @@ import (
|
|||
)
|
||||
|
||||
// ContainerDiff shows differences in a container filesystem since it was started.
|
||||
func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.ContainerChangeResponseItem, error) {
|
||||
var changes []container.ContainerChangeResponseItem
|
||||
func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error) {
|
||||
var changes []container.FilesystemChange
|
||||
|
||||
serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil)
|
||||
defer ensureReaderClosed(serverResp)
|
||||
|
|
|
@ -31,13 +31,13 @@ func TestContainerDiff(t *testing.T) {
|
|||
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
||||
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
||||
}
|
||||
b, err := json.Marshal([]container.ContainerChangeResponseItem{
|
||||
b, err := json.Marshal([]container.FilesystemChange{
|
||||
{
|
||||
Kind: 0,
|
||||
Kind: container.ChangeModify,
|
||||
Path: "/path/1",
|
||||
},
|
||||
{
|
||||
Kind: 1,
|
||||
Kind: container.ChangeAdd,
|
||||
Path: "/path/2",
|
||||
},
|
||||
})
|
||||
|
|
|
@ -48,7 +48,7 @@ type ContainerAPIClient interface {
|
|||
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
|
||||
ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error)
|
||||
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.CreateResponse, error)
|
||||
ContainerDiff(ctx context.Context, container string) ([]container.ContainerChangeResponseItem, error)
|
||||
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
|
||||
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
|
||||
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
|
||||
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
|
||||
|
|
|
@ -20,7 +20,9 @@ swagger generate model -f api/swagger.yaml \
|
|||
-t api -m types/container --skip-validator -C api/swagger-gen.yaml \
|
||||
-n ContainerCreateResponse \
|
||||
-n ContainerWaitResponse \
|
||||
-n ContainerWaitExitError
|
||||
-n ContainerWaitExitError \
|
||||
-n ChangeType \
|
||||
-n FilesystemChange
|
||||
|
||||
swagger generate model -f api/swagger.yaml \
|
||||
-t api -m types/volume --skip-validator -C api/swagger-gen.yaml \
|
||||
|
@ -32,7 +34,6 @@ swagger generate operation -f api/swagger.yaml \
|
|||
-t api -a types -m types -C api/swagger-gen.yaml \
|
||||
-T api/templates --skip-responses --skip-parameters --skip-validator \
|
||||
-n Authenticate \
|
||||
-n ContainerChanges \
|
||||
-n ContainerTop \
|
||||
-n ContainerUpdate \
|
||||
-n ImageHistory
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/poll"
|
||||
"gotest.tools/v3/skip"
|
||||
|
@ -25,15 +24,15 @@ func TestDiff(t *testing.T) {
|
|||
// it will take a few seconds to exit. Also there's no way in Windows to
|
||||
// differentiate between an Add or a Modify, and all files are under
|
||||
// a "Files/" prefix.
|
||||
expected := []containertypes.ContainerChangeResponseItem{
|
||||
{Kind: archive.ChangeAdd, Path: "/foo"},
|
||||
{Kind: archive.ChangeAdd, Path: "/foo/bar"},
|
||||
expected := []containertypes.FilesystemChange{
|
||||
{Kind: containertypes.ChangeAdd, Path: "/foo"},
|
||||
{Kind: containertypes.ChangeAdd, Path: "/foo/bar"},
|
||||
}
|
||||
if testEnv.OSType == "windows" {
|
||||
poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(60*time.Second))
|
||||
expected = []containertypes.ContainerChangeResponseItem{
|
||||
{Kind: archive.ChangeModify, Path: "Files/foo"},
|
||||
{Kind: archive.ChangeModify, Path: "Files/foo/bar"},
|
||||
expected = []containertypes.FilesystemChange{
|
||||
{Kind: containertypes.ChangeModify, Path: "Files/foo"},
|
||||
{Kind: containertypes.ChangeModify, Path: "Files/foo/bar"},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -450,8 +450,8 @@ func testGraphDriver(ctx context.Context, t *testing.T, c client.APIClient, driv
|
|||
|
||||
diffs, err := c.ContainerDiff(ctx, id)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Contains(diffs, containertypes.ContainerChangeResponseItem{
|
||||
Kind: archive.ChangeAdd,
|
||||
assert.Check(t, is.Contains(diffs, containertypes.FilesystemChange{
|
||||
Kind: containertypes.ChangeAdd,
|
||||
Path: "/hello",
|
||||
}), "diffs: %v", diffs)
|
||||
|
||||
|
|
Loading…
Reference in a new issue