Files
cocos/pkg/resource/oci.go
T
Sammy Kerata Oina c59a413765
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
NOISSUE - Implement extensible resource downloader framework with support for S3, GCS, and OCI sources (#590)
* feat: implement extensible resource downloader framework with support for S3, GCS, and OCI sources

Signed-off-by: SammyOina <sammyoina@gmail.com>

* refactor: improve resource URL parsing and add support for bare OCI image references

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* fix: add empty string check and slash requirement for OCI image inference, and update python unit tests with event mock expectations

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* refactor: introduce OCIClient interface, add test coverage for decryption, and improve resource download error handling

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

* chore: remove trailing whitespace in OCI downloader and HTTP tests

Signed-off-by: Sammy Oina <sammyoina@gmail.com>

---------

Signed-off-by: SammyOina <sammyoina@gmail.com>
Signed-off-by: Sammy Oina <sammyoina@gmail.com>
2026-04-28 11:21:03 +02:00

59 lines
1.7 KiB
Go

// Copyright (c) Ultraviolet
// SPDX-License-Identifier: Apache-2.0
package resource
import (
"context"
"github.com/ultravioletrs/cocos/pkg/oci"
)
const (
// SourceTypeOCIImage represents an OCI image resource source.
SourceTypeOCIImage = "oci-image"
)
// OCIClient defines the interface for OCI image operations.
type OCIClient interface {
PullAndDecrypt(ctx context.Context, source oci.ResourceSource, destDir string) error
ToDockerArchive(ctx context.Context, ociDir, destFile string) error
}
// OCIDownloader adapts OCIClient to the Downloader interface.
// For OCI images, destPath is a directory where the OCI layout is written.
type OCIDownloader struct {
client OCIClient
}
// NewOCIDownloader creates a new OCI downloader wrapping an OCI client.
func NewOCIDownloader(client OCIClient) *OCIDownloader {
return &OCIDownloader{
client: client,
}
}
// Download pulls an OCI image to the destination directory.
// Note: For OCI images, encryption/decryption is handled by Skopeo + CoCo Keyprovider
// transparently via ocicrypt, so this just does the pull.
func (o *OCIDownloader) Download(ctx context.Context, url string, destDir string) error {
source := oci.ResourceSource{
Type: oci.ResourceTypeOCIImage,
URI: url,
// Encryption handled separately by the caller who sets up Skopeo env.
Encrypted: false,
}
return o.client.PullAndDecrypt(ctx, source, destDir)
}
// Type returns the source type identifier.
func (o *OCIDownloader) Type() string {
return SourceTypeOCIImage
}
// Client returns the underlying OCIClient for OCI-specific operations
// like ToDockerArchive that aren't part of the generic Downloader interface.
func (o *OCIDownloader) Client() OCIClient {
return o.client
}