MCPcopy
hub / github.com/containerd/containerd / parseLeaseResource

Function parseLeaseResource

core/metadata/leases.go:531–563  ·  view source on GitHub ↗
(r leases.Resource)

Source from the content-addressed store, hash-verified

529}
530
531func parseLeaseResource(r leases.Resource) ([]string, string, error) {
532 var (
533 ref = r.ID
534 typ = r.Type
535 keys = strings.Split(typ, "/")
536 )
537
538 switch k := keys[0]; k {
539 case string(bucketKeyObjectContent),
540 string(bucketKeyObjectIngests),
541 string(bucketKeyObjectImages):
542
543 if len(keys) != 1 {
544 return nil, "", fmt.Errorf("invalid resource type %s: %w", typ, errdefs.ErrInvalidArgument)
545 }
546
547 if k == string(bucketKeyObjectContent) {
548 dgst, err := digest.Parse(ref)
549 if err != nil {
550 return nil, "", fmt.Errorf("invalid content resource id %s: %v: %w", ref, err, errdefs.ErrInvalidArgument)
551 }
552 ref = dgst.String()
553 }
554 case string(bucketKeyObjectSnapshots):
555 if len(keys) != 2 {
556 return nil, "", fmt.Errorf("invalid snapshot resource type %s: %w", typ, errdefs.ErrInvalidArgument)
557 }
558 default:
559 return nil, "", fmt.Errorf("resource type %s not supported yet: %w", typ, errdefs.ErrNotImplemented)
560 }
561
562 return keys, ref, nil
563}

Callers 2

AddResourceMethod · 0.85
DeleteResourceMethod · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…