resource

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package resource provides abstractions for downloading remote resources from various sources (OCI registries, S3, HTTP/HTTPS).

Index

Constants

View Source
const (
	// SourceTypeHTTPS represents an HTTPS resource source.
	SourceTypeHTTPS = "https"
	// SourceTypeHTTP represents an HTTP resource source.
	SourceTypeHTTP = "http"
)
View Source
const (
	// SourceTypeS3 represents an S3-compatible object storage source.
	SourceTypeS3 = "s3"
	// SourceTypeGCS represents a Google Cloud Storage source.
	SourceTypeGCS = "gcs"
)
View Source
const (
	// SourceTypeOCIImage represents an OCI image resource source.
	SourceTypeOCIImage = "oci-image"
)

Variables

This section is empty.

Functions

func DecryptData

func DecryptData(ciphertext, key []byte) ([]byte, error)

DecryptData decrypts AES-256-GCM encrypted data. The encrypted data format is: nonce (12 bytes) || ciphertext+tag.

func DecryptFile

func DecryptFile(encryptedPath string, key []byte) ([]byte, error)

DecryptFile decrypts an AES-256-GCM encrypted file in place. The encrypted file format is: nonce (12 bytes) || ciphertext+tag. The key must be exactly 32 bytes (AES-256).

Types

type Downloader

type Downloader interface {
	// Download fetches a resource from the given URL and writes it to destPath.
	// For OCI images, destPath is a directory. For S3/HTTP, destPath is a file path.
	Download(ctx context.Context, url string, destPath string) error

	// Type returns the source type identifier (e.g., "oci-image", "s3", "https", "http").
	Type() string
}

Downloader defines the interface for downloading resources from a remote source.

type GCSDownloader

type GCSDownloader struct{}

GCSDownloader downloads resources from Google Cloud Storage.

func NewGCSDownloader

func NewGCSDownloader() *GCSDownloader

NewGCSDownloader creates a new GCS downloader.

func (*GCSDownloader) Download

func (g *GCSDownloader) Download(ctx context.Context, url string, destPath string) error

Download fetches a resource from a GCS URL (gs://bucket/key) and writes it to destPath.

func (*GCSDownloader) Type

func (g *GCSDownloader) Type() string

Type returns the source type identifier.

type HTTPDownloader

type HTTPDownloader struct {
	// contains filtered or unexported fields
}

HTTPDownloader downloads resources via HTTP/HTTPS.

func NewHTTPDownloader

func NewHTTPDownloader() *HTTPDownloader

NewHTTPDownloader creates a new HTTP downloader (insecure, for testing).

func NewHTTPSDownloader

func NewHTTPSDownloader() *HTTPDownloader

NewHTTPSDownloader creates a new HTTPS downloader.

func (*HTTPDownloader) Download

func (h *HTTPDownloader) Download(ctx context.Context, url string, destPath string) error

Download fetches a resource from an HTTP/HTTPS URL and writes it to destPath.

func (*HTTPDownloader) Type

func (h *HTTPDownloader) Type() string

Type returns the source type identifier.

type OCIClient

type OCIClient interface {
	PullAndDecrypt(ctx context.Context, source oci.ResourceSource, destDir string) error
	ToDockerArchive(ctx context.Context, ociDir, destFile string) error
}

OCIClient defines the interface for OCI image operations.

type OCIDownloader

type OCIDownloader struct {
	// contains filtered or unexported fields
}

OCIDownloader adapts OCIClient to the Downloader interface. For OCI images, destPath is a directory where the OCI layout is written.

func NewOCIDownloader

func NewOCIDownloader(client OCIClient) *OCIDownloader

NewOCIDownloader creates a new OCI downloader wrapping an OCI client.

func (*OCIDownloader) Client

func (o *OCIDownloader) Client() OCIClient

Client returns the underlying OCIClient for OCI-specific operations like ToDockerArchive that aren't part of the generic Downloader interface.

func (*OCIDownloader) Download

func (o *OCIDownloader) Download(ctx context.Context, url string, destDir string) error

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 (*OCIDownloader) Type

func (o *OCIDownloader) Type() string

Type returns the source type identifier.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maps source type strings to Downloader implementations.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new empty downloader registry.

func (*Registry) Get

func (r *Registry) Get(sourceType string) (Downloader, error)

Get retrieves a downloader for the given source type.

func (*Registry) Register

func (r *Registry) Register(d Downloader)

Register adds a downloader to the registry for its declared type.

func (*Registry) SupportedTypes

func (r *Registry) SupportedTypes() []string

SupportedTypes returns a list of all registered source types.

type S3Downloader

type S3Downloader struct {
	// contains filtered or unexported fields
}

S3Downloader downloads resources from S3-compatible object storage. It uses the Google Cloud Storage client library with S3-compatible endpoints or can be configured for MinIO/AWS S3 via environment variables.

func NewS3Downloader

func NewS3Downloader(endpoint string) *S3Downloader

NewS3Downloader creates a new S3 downloader. If endpoint is empty, standard AWS S3 environment credentials/config are used.

func (*S3Downloader) Download

func (s *S3Downloader) Download(ctx context.Context, url string, destPath string) error

Download fetches a resource from an S3 URL (s3://bucket/key) and writes it to destPath.

func (*S3Downloader) Type

func (s *S3Downloader) Type() string

Type returns the source type identifier.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL