github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/pkg/zoci/common.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // SPDX-FileCopyrightText: 2021-Present The Jackal Authors
     3  
     4  // Package zoci contains functions for interacting with Jackal packages stored in OCI registries.
     5  package zoci
     6  
     7  import (
     8  	"log/slog"
     9  
    10  	"github.com/Racer159/jackal/src/config"
    11  	"github.com/Racer159/jackal/src/pkg/message"
    12  	"github.com/defenseunicorns/pkg/oci"
    13  	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
    14  )
    15  
    16  const (
    17  	// JackalConfigMediaType is the media type for the manifest config
    18  	JackalConfigMediaType = "application/vnd.jackal.config.v1+json"
    19  	// JackalLayerMediaTypeBlob is the media type for all Jackal layers due to the range of possible content
    20  	JackalLayerMediaTypeBlob = "application/vnd.jackal.layer.v1.blob"
    21  	// SkeletonArch is the architecture used for skeleton packages
    22  	SkeletonArch = "skeleton"
    23  )
    24  
    25  // Remote is a wrapper around the Oras remote repository with jackal specific functions
    26  type Remote struct {
    27  	*oci.OrasRemote
    28  }
    29  
    30  // NewRemote returns an oras remote repository client and context for the given url
    31  // with jackal opination embedded
    32  func NewRemote(url string, platform ocispec.Platform, mods ...oci.Modifier) (*Remote, error) {
    33  	logger := slog.New(message.JackalHandler{})
    34  	modifiers := append([]oci.Modifier{
    35  		oci.WithPlainHTTP(config.CommonOptions.Insecure),
    36  		oci.WithInsecureSkipVerify(config.CommonOptions.Insecure),
    37  		oci.WithLogger(logger),
    38  		oci.WithUserAgent("jackal/" + config.CLIVersion),
    39  	}, mods...)
    40  	remote, err := oci.NewOrasRemote(url, platform, modifiers...)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	return &Remote{remote}, nil
    45  }
    46  
    47  // PlatformForSkeleton sets the target architecture for the remote to skeleton
    48  func PlatformForSkeleton() ocispec.Platform {
    49  	return ocispec.Platform{
    50  		OS:           oci.MultiOS,
    51  		Architecture: SkeletonArch,
    52  	}
    53  }