(src *pb.SourceOp, dgst digest.Digest)
| 666 | } |
| 667 | |
| 668 | func addPinToImage(src *pb.SourceOp, dgst digest.Digest) (*pb.SourceOp, error) { |
| 669 | id, ok := strings.CutPrefix(src.Identifier, "docker-image://") |
| 670 | if !ok { |
| 671 | return nil, errors.Errorf("cannot pin non-image source: %q", src.Identifier) |
| 672 | } |
| 673 | |
| 674 | ref, err := reference.ParseNormalizedNamed(id) |
| 675 | if err != nil { |
| 676 | return nil, errors.Wrapf(err, "failed parsing image reference %q", id) |
| 677 | } |
| 678 | |
| 679 | newRef, err := reference.WithDigest(ref, dgst) |
| 680 | if err != nil { |
| 681 | return nil, errors.Wrapf(err, "failed adding digest to image reference %q", id) |
| 682 | } |
| 683 | attrs := maps.Clone(src.Attrs) |
| 684 | if attrs == nil { |
| 685 | attrs = make(map[string]string) |
| 686 | } |
| 687 | attrs["image.checksum"] = dgst.String() |
| 688 | |
| 689 | return &pb.SourceOp{ |
| 690 | Identifier: "docker-image://" + newRef.String(), |
| 691 | Attrs: attrs, |
| 692 | }, nil |
| 693 | } |
no test coverage detected
searching dependent graphs…