-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Expand file tree
/
Copy pathimage_inspect.go
More file actions
62 lines (53 loc) · 1.46 KB
/
image_inspect.go
File metadata and controls
62 lines (53 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package client
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/url"
)
// ImageInspect returns the image information.
func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts ...ImageInspectOption) (ImageInspectResult, error) {
if imageID == "" {
return ImageInspectResult{}, objectNotFoundError{object: "image", id: imageID}
}
var opts imageInspectOpts
for _, opt := range inspectOpts {
if err := opt.Apply(&opts); err != nil {
return ImageInspectResult{}, fmt.Errorf("error applying image inspect option: %w", err)
}
}
query := url.Values{}
if opts.apiOptions.Manifests {
if err := cli.requiresVersion(ctx, "1.48", "manifests"); err != nil {
return ImageInspectResult{}, err
}
query.Set("manifests", "1")
}
if opts.apiOptions.Platform != nil {
if err := cli.requiresVersion(ctx, "1.49", "platform"); err != nil {
return ImageInspectResult{}, err
}
platform, err := encodePlatform(opts.apiOptions.Platform)
if err != nil {
return ImageInspectResult{}, err
}
query.Set("platform", platform)
}
resp, err := cli.get(ctx, "/images/"+imageID+"/json", query, nil)
defer ensureReaderClosed(resp)
if err != nil {
return ImageInspectResult{}, err
}
buf := opts.raw
if buf == nil {
buf = &bytes.Buffer{}
}
if _, err := io.Copy(buf, resp.Body); err != nil {
return ImageInspectResult{}, err
}
var response ImageInspectResult
err = json.Unmarshal(buf.Bytes(), &response)
return response, err
}