Skip to content

Commit dbb48e4

Browse files
committed
api/types/container: create type for changes endpoint
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7103efa commit dbb48e4

12 files changed

Lines changed: 112 additions & 56 deletions

File tree

api/swagger.yaml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,34 @@ definitions:
16101610
"WorkDir": "/var/lib/docker/overlay2/ef749362d13333e65fc95c572eb525abbe0052e16e086cb64bc3b98ae9aa6d74/work"
16111611
}
16121612

1613+
FilesystemChange:
1614+
description: |
1615+
Change in the container's filesystem.
1616+
type: "object"
1617+
required: [Path, Kind]
1618+
properties:
1619+
Path:
1620+
description: |
1621+
Path to file or directory that has changed.
1622+
type: "string"
1623+
x-nullable: false
1624+
Kind:
1625+
$ref: "#/definitions/ChangeType"
1626+
1627+
ChangeType:
1628+
description: |
1629+
Kind of change
1630+
1631+
Can be one of:
1632+
1633+
- `0`: Modified ("C")
1634+
- `1`: Added ("A")
1635+
- `2`: Deleted ("D")
1636+
type: "integer"
1637+
format: "uint8"
1638+
enum: [0, 1, 2]
1639+
x-nullable: false
1640+
16131641
ImageInspect:
16141642
description: |
16151643
Information about an image in the local image cache.
@@ -6876,9 +6904,9 @@ paths:
68766904
Returns which files in a container's filesystem have been added, deleted,
68776905
or modified. The `Kind` of modification can be one of:
68786906
6879-
- `0`: Modified
6880-
- `1`: Added
6881-
- `2`: Deleted
6907+
- `0`: Modified ("C")
6908+
- `1`: Added ("A")
6909+
- `2`: Deleted ("D")
68826910
operationId: "ContainerChanges"
68836911
produces: ["application/json"]
68846912
responses:
@@ -6887,22 +6915,7 @@ paths:
68876915
schema:
68886916
type: "array"
68896917
items:
6890-
type: "object"
6891-
x-go-name: "ContainerChangeResponseItem"
6892-
title: "ContainerChangeResponseItem"
6893-
description: "change item in response to ContainerChanges operation"
6894-
required: [Path, Kind]
6895-
properties:
6896-
Path:
6897-
description: "Path to file that has changed"
6898-
type: "string"
6899-
x-nullable: false
6900-
Kind:
6901-
description: "Kind of change"
6902-
type: "integer"
6903-
format: "uint8"
6904-
enum: [0, 1, 2]
6905-
x-nullable: false
6918+
$ref: "#/definitions/FilesystemChange"
69066919
examples:
69076920
application/json:
69086921
- Path: "/dev"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package container
2+
3+
// ContainerChangeResponseItem change item in response to ContainerChanges operation
4+
//
5+
// Deprecated: use [FilesystemChange].
6+
type ContainerChangeResponseItem = FilesystemChange

api/types/container/change_type.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package container
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
// ChangeType Kind of change
7+
//
8+
// Can be one of:
9+
//
10+
// - `0`: Modified ("C")
11+
// - `1`: Added ("A")
12+
// - `2`: Deleted ("D")
13+
//
14+
// swagger:model ChangeType
15+
type ChangeType uint8
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package container
2+
3+
const (
4+
// ChangeModify represents the modify operation.
5+
ChangeModify ChangeType = 0
6+
// ChangeAdd represents the add operation.
7+
ChangeAdd ChangeType = 1
8+
// ChangeDelete represents the delete operation.
9+
ChangeDelete ChangeType = 2
10+
)
11+
12+
func (ct ChangeType) String() string {
13+
switch ct {
14+
case ChangeModify:
15+
return "C"
16+
case ChangeAdd:
17+
return "A"
18+
case ChangeDelete:
19+
return "D"
20+
default:
21+
return ""
22+
}
23+
}

api/types/container/container_changes.go

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package container
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
// FilesystemChange Change in the container's filesystem.
7+
//
8+
// swagger:model FilesystemChange
9+
type FilesystemChange struct {
10+
11+
// kind
12+
// Required: true
13+
Kind ChangeType `json:"Kind"`
14+
15+
// Path to file or directory that has changed.
16+
//
17+
// Required: true
18+
Path string `json:"Path"`
19+
}

client/container_diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
)
1010

1111
// ContainerDiff shows differences in a container filesystem since it was started.
12-
func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.ContainerChangeResponseItem, error) {
13-
var changes []container.ContainerChangeResponseItem
12+
func (cli *Client) ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error) {
13+
var changes []container.FilesystemChange
1414

1515
serverResp, err := cli.get(ctx, "/containers/"+containerID+"/changes", url.Values{}, nil)
1616
defer ensureReaderClosed(serverResp)

client/container_diff_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ func TestContainerDiff(t *testing.T) {
3131
if !strings.HasPrefix(req.URL.Path, expectedURL) {
3232
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
3333
}
34-
b, err := json.Marshal([]container.ContainerChangeResponseItem{
34+
b, err := json.Marshal([]container.FilesystemChange{
3535
{
36-
Kind: 0,
36+
Kind: container.ChangeModify,
3737
Path: "/path/1",
3838
},
3939
{
40-
Kind: 1,
40+
Kind: container.ChangeAdd,
4141
Path: "/path/2",
4242
},
4343
})

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type ContainerAPIClient interface {
4848
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
4949
ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error)
5050
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.CreateResponse, error)
51-
ContainerDiff(ctx context.Context, container string) ([]container.ContainerChangeResponseItem, error)
51+
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
5252
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
5353
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
5454
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)

hack/generate-swagger-api.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ swagger generate model -f api/swagger.yaml \
2020
-t api -m types/container --skip-validator -C api/swagger-gen.yaml \
2121
-n ContainerCreateResponse \
2222
-n ContainerWaitResponse \
23-
-n ContainerWaitExitError
23+
-n ContainerWaitExitError \
24+
-n ChangeType \
25+
-n FilesystemChange
2426

2527
swagger generate model -f api/swagger.yaml \
2628
-t api -m types/volume --skip-validator -C api/swagger-gen.yaml \
@@ -32,7 +34,6 @@ swagger generate operation -f api/swagger.yaml \
3234
-t api -a types -m types -C api/swagger-gen.yaml \
3335
-T api/templates --skip-responses --skip-parameters --skip-validator \
3436
-n Authenticate \
35-
-n ContainerChanges \
3637
-n ContainerTop \
3738
-n ContainerUpdate \
3839
-n ImageHistory

0 commit comments

Comments
 (0)