distribution_inspect.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package client // import "github.com/docker/docker/client"
  2. import (
  3. "context"
  4. "encoding/json"
  5. "net/http"
  6. "net/url"
  7. "github.com/docker/docker/api/types/registry"
  8. )
  9. // DistributionInspect returns the image digest with the full manifest.
  10. func (cli *Client) DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error) {
  11. // Contact the registry to retrieve digest and platform information
  12. var distributionInspect registry.DistributionInspect
  13. if image == "" {
  14. return distributionInspect, objectNotFoundError{object: "distribution", id: image}
  15. }
  16. if err := cli.NewVersionError(ctx, "1.30", "distribution inspect"); err != nil {
  17. return distributionInspect, err
  18. }
  19. var headers http.Header
  20. if encodedRegistryAuth != "" {
  21. headers = http.Header{
  22. registry.AuthHeader: {encodedRegistryAuth},
  23. }
  24. }
  25. resp, err := cli.get(ctx, "/distribution/"+image+"/json", url.Values{}, headers)
  26. defer ensureReaderClosed(resp)
  27. if err != nil {
  28. return distributionInspect, err
  29. }
  30. err = json.NewDecoder(resp.body).Decode(&distributionInspect)
  31. return distributionInspect, err
  32. }