-
Notifications
You must be signed in to change notification settings - Fork 146
/
common.go
53 lines (46 loc) · 1.75 KB
/
common.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package zoci contains functions for interacting with Zarf packages stored in OCI registries.
package zoci
import (
"log/slog"
"github.com/defenseunicorns/pkg/oci"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/message"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
const (
// ZarfConfigMediaType is the media type for the manifest config
ZarfConfigMediaType = "application/vnd.zarf.config.v1+json"
// ZarfLayerMediaTypeBlob is the media type for all Zarf layers due to the range of possible content
ZarfLayerMediaTypeBlob = "application/vnd.zarf.layer.v1.blob"
// SkeletonArch is the architecture used for skeleton packages
SkeletonArch = "skeleton"
)
// Remote is a wrapper around the Oras remote repository with zarf specific functions
type Remote struct {
*oci.OrasRemote
}
// NewRemote returns an oras remote repository client and context for the given url
// with zarf opination embedded
func NewRemote(url string, platform ocispec.Platform, mods ...oci.Modifier) (*Remote, error) {
logger := slog.New(message.ZarfHandler{})
modifiers := append([]oci.Modifier{
oci.WithPlainHTTP(config.CommonOptions.Insecure),
oci.WithInsecureSkipVerify(config.CommonOptions.Insecure),
oci.WithLogger(logger),
oci.WithUserAgent("zarf/" + config.CLIVersion),
}, mods...)
remote, err := oci.NewOrasRemote(url, platform, modifiers...)
if err != nil {
return nil, err
}
return &Remote{remote}, nil
}
// PlatformForSkeleton sets the target architecture for the remote to skeleton
func PlatformForSkeleton() ocispec.Platform {
return ocispec.Platform{
OS: oci.MultiOS,
Architecture: SkeletonArch,
}
}