Skip to content

Commit 51bfa52

Browse files
committed
Alternative client opts !fixup! c8d/inspect: Add Manifests field
Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 4219ce7 commit 51bfa52

2 files changed

Lines changed: 12 additions & 36 deletions

File tree

client/image_inspect.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,21 @@ import (
1010
"github.com/docker/docker/api/types/image"
1111
)
1212

13-
type imageInspectClientOpt struct {
14-
raw *bytes.Buffer
15-
apiOptions image.InspectOptions
16-
}
17-
18-
type ImageInspectOpt func(*imageInspectClientOpt)
19-
20-
// ImageInspectWithRawResponse instructs the client to additionally store the
21-
// raw inspect response in the provided buffer.
22-
func ImageInspectWithRawResponse(raw *bytes.Buffer) ImageInspectOpt {
23-
return func(opts *imageInspectClientOpt) {
24-
opts.raw = raw
25-
}
26-
}
13+
type ImageInspectOpts struct {
14+
image.InspectOptions
2715

28-
// ImageInspectWithOpts sets the API options for the image inspect operation.
29-
func ImageInspectWithOpts(opts image.InspectOptions) ImageInspectOpt {
30-
return func(clientOpts *imageInspectClientOpt) {
31-
clientOpts.apiOptions = opts
32-
}
16+
// Raw is an optional writer to write the raw inspect response to.
17+
Raw io.Writer
3318
}
3419

3520
// ImageInspect returns the image information.
36-
func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts ...ImageInspectOpt) (image.InspectResponse, error) {
21+
func (cli *Client) ImageInspect(ctx context.Context, imageID string, opts ImageInspectOpts) (image.InspectResponse, error) {
3722
if imageID == "" {
3823
return image.InspectResponse{}, objectNotFoundError{object: "image", id: imageID}
3924
}
4025

41-
var opts imageInspectClientOpt
42-
for _, opt := range inspectOpts {
43-
opt(&opts)
44-
}
45-
4626
query := url.Values{}
47-
if opts.apiOptions.Manifests {
27+
if opts.Manifests {
4828
if err := cli.NewVersionError(ctx, "1.48", "manifests"); err != nil {
4929
return image.InspectResponse{}, err
5030
}
@@ -57,17 +37,13 @@ func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts
5737
return image.InspectResponse{}, err
5838
}
5939

60-
buf := opts.raw
61-
if buf == nil {
62-
buf = &bytes.Buffer{}
63-
}
64-
65-
if _, err := io.Copy(buf, serverResp.body); err != nil {
66-
return image.InspectResponse{}, err
40+
var reader io.Reader = serverResp.body
41+
if opts.Raw != nil {
42+
reader = io.TeeReader(serverResp.body, opts.Raw)
6743
}
6844

6945
var response image.InspectResponse
70-
err = json.Unmarshal(buf.Bytes(), &response)
46+
err = json.NewDecoder(reader).Decode(&response)
7147
return response, err
7248
}
7349

@@ -76,7 +52,7 @@ func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts
7652
// TODeprecate: Use [ImageInspect] instead.
7753
func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (image.InspectResponse, []byte, error) {
7854
var buf bytes.Buffer
79-
resp, err := cli.ImageInspect(ctx, imageID, ImageInspectWithRawResponse(&buf))
55+
resp, err := cli.ImageInspect(ctx, imageID, ImageInspectOpts{Raw: &buf})
8056
if err != nil {
8157
return image.InspectResponse{}, nil, err
8258
}

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type ImageAPIClient interface {
9494
ImageHistory(ctx context.Context, image string, opts image.HistoryOptions) ([]image.HistoryResponseItem, error)
9595
ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
9696
ImageInspectWithRaw(ctx context.Context, image string) (image.InspectResponse, []byte, error)
97-
ImageInspect(ctx context.Context, image string, _ ...ImageInspectOpt) (image.InspectResponse, error)
97+
ImageInspect(ctx context.Context, image string, opts ImageInspectOpts) (image.InspectResponse, error)
9898
ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
9999
ImageLoad(ctx context.Context, input io.Reader, opts image.LoadOptions) (image.LoadResponse, error)
100100
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)

0 commit comments

Comments
 (0)