distribution_inspect.go 1.1 KB

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