-
Notifications
You must be signed in to change notification settings - Fork 147
/
manifest.go
31 lines (25 loc) · 1.01 KB
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package oci contains functions for interacting with artifacts stored in OCI registries.
package oci
import (
"encoding/json"
"path/filepath"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// Manifest is a wrapper around the OCI manifest
type Manifest struct {
ocispec.Manifest
}
// Locate returns the descriptor for the first layer with the given path or digest.
func (m *Manifest) Locate(pathOrDigest string) ocispec.Descriptor {
return helpers.Find(m.Layers, func(layer ocispec.Descriptor) bool {
// Convert from the OS path separator to the standard '/' for Windows support
return layer.Annotations[ocispec.AnnotationTitle] == filepath.ToSlash(pathOrDigest) || layer.Digest.Encoded() == pathOrDigest
})
}
// MarshalJSON returns the JSON encoding of the manifest.
func (m *Manifest) MarshalJSON() ([]byte, error) {
return json.Marshal(m.Manifest)
}