2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2017-04-05 22:43:17 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2017-04-05 22:43:17 +00:00
|
|
|
"encoding/json"
|
2023-07-10 14:44:59 +00:00
|
|
|
"net/http"
|
2017-04-05 22:43:17 +00:00
|
|
|
"net/url"
|
|
|
|
|
2021-08-26 19:08:38 +00:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2017-04-05 22:43:17 +00:00
|
|
|
)
|
|
|
|
|
2021-02-16 15:07:44 +00:00
|
|
|
// DistributionInspect returns the image digest with the full manifest.
|
2024-01-19 11:31:25 +00:00
|
|
|
func (cli *Client) DistributionInspect(ctx context.Context, imageRef, encodedRegistryAuth string) (registry.DistributionInspect, error) {
|
2017-06-07 16:09:07 +00:00
|
|
|
// Contact the registry to retrieve digest and platform information
|
2021-08-26 19:08:38 +00:00
|
|
|
var distributionInspect registry.DistributionInspect
|
2024-01-19 11:31:25 +00:00
|
|
|
if imageRef == "" {
|
|
|
|
return distributionInspect, objectNotFoundError{object: "distribution", id: imageRef}
|
2018-01-30 12:35:22 +00:00
|
|
|
}
|
2017-06-07 16:09:07 +00:00
|
|
|
|
2023-09-12 12:08:54 +00:00
|
|
|
if err := cli.NewVersionError(ctx, "1.30", "distribution inspect"); err != nil {
|
2017-06-07 16:09:07 +00:00
|
|
|
return distributionInspect, err
|
|
|
|
}
|
2017-04-05 22:43:17 +00:00
|
|
|
|
2023-07-10 14:44:59 +00:00
|
|
|
var headers http.Header
|
2017-04-05 22:43:17 +00:00
|
|
|
if encodedRegistryAuth != "" {
|
2023-07-10 14:44:59 +00:00
|
|
|
headers = http.Header{
|
2021-08-26 19:08:38 +00:00
|
|
|
registry.AuthHeader: {encodedRegistryAuth},
|
2017-04-05 22:43:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 11:31:25 +00:00
|
|
|
resp, err := cli.get(ctx, "/distribution/"+imageRef+"/json", url.Values{}, headers)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(resp)
|
2017-04-05 22:43:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return distributionInspect, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.NewDecoder(resp.body).Decode(&distributionInspect)
|
|
|
|
return distributionInspect, err
|
|
|
|
}
|