OCI: Add From/ToProto helpers for Descriptor
Helpers to convert from the OCI image specs [Descriptor] to its protobuf structure for Descriptor and vice-versa appear three times. It seems sane to just expose this facility in /oci. Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
25
oci/spec.go
25
oci/spec.go
@@ -21,8 +21,11 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
|
||||
"github.com/containerd/containerd/api/types"
|
||||
"github.com/containerd/containerd/containers"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
@@ -220,3 +223,25 @@ func populateDefaultDarwinSpec(s *Spec) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DescriptorFromProto converts containerds protobuf [types.Descriptor]
|
||||
// to the OCI image specs [ocispec.Descriptor].
|
||||
func DescriptorFromProto(d *types.Descriptor) ocispec.Descriptor {
|
||||
return ocispec.Descriptor{
|
||||
MediaType: d.MediaType,
|
||||
Digest: digest.Digest(d.Digest),
|
||||
Size: d.Size,
|
||||
Annotations: d.Annotations,
|
||||
}
|
||||
}
|
||||
|
||||
// DescriptorToProto converts the OCI image specs [ocispec.Descriptor]
|
||||
// to containerds protobuf [types.Descriptor].
|
||||
func DescriptorToProto(d ocispec.Descriptor) *types.Descriptor {
|
||||
return &types.Descriptor{
|
||||
MediaType: d.MediaType,
|
||||
Digest: d.Digest.String(),
|
||||
Size: d.Size,
|
||||
Annotations: d.Annotations,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user