uploader

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package uploader provides file download and extraction functionality for Pages Direct Upload deployments from various sources.

Index

Constants

View Source
const (
	AlgorithmSHA256 = "sha256"
	AlgorithmSHA512 = "sha512"
	AlgorithmMD5    = "md5"
)

Checksum algorithm constants

View Source
const (
	// MaxDownloadSize is the maximum allowed download size (500MB).
	// This aligns with Cloudflare Pages deployment size limits.
	MaxDownloadSize = 500 * 1024 * 1024

	// MaxFileCount is the maximum number of files allowed in an archive.
	MaxFileCount = 20000

	// MaxFileSize is the maximum size of a single file (100MB).
	MaxFileSize = 100 * 1024 * 1024

	// ContentTypeOctetStream is the default content type for binary files.
	ContentTypeOctetStream = "application/octet-stream"
)
View Source
const (
	// DefaultHTTPTimeout is the default timeout for HTTP requests.
	DefaultHTTPTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func ComputeChecksum

func ComputeChecksum(data []byte, algorithm string) (string, error)

ComputeChecksum computes a checksum for the given data.

func VerifyChecksum

func VerifyChecksum(data []byte, cfg *v1alpha2.ChecksumConfig) error

VerifyChecksum verifies the checksum of data against expected value.

Types

type FileManifest

type FileManifest struct {
	// Files maps relative paths to file content.
	Files map[string][]byte

	// TotalSize is the total size of all files in bytes.
	TotalSize int64

	// FileCount is the number of files.
	FileCount int

	// SourceHash is the SHA-256 hash of the original source package file.
	// Used for tracking and identifying deployments from the same source.
	SourceHash string

	// SourceURL is the URL where the source was fetched from (if applicable).
	SourceURL string
}

FileManifest represents the extracted file manifest for Pages upload.

func ExtractArchive

func ExtractArchive(data []byte, cfg *v1alpha2.ArchiveConfig) (*FileManifest, error)

ExtractArchive extracts files from archive data.

func ProcessSource

func ProcessSource(
	ctx context.Context,
	k8sClient client.Client,
	namespace string,
	source *v1alpha2.DirectUploadSource,
	checksum *v1alpha2.ChecksumConfig,
	archive *v1alpha2.ArchiveConfig,
) (*FileManifest, error)

ProcessSource downloads, verifies, and extracts files from source. This is the main entry point for processing direct upload sources.

type HTTPUploader

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

HTTPUploader downloads files from HTTP/HTTPS URLs.

func NewHTTPUploader

func NewHTTPUploader(ctx context.Context, k8sClient client.Client, namespace string, config *v1alpha2.HTTPSource) (*HTTPUploader, error)

NewHTTPUploader creates a new HTTP uploader from configuration.

func (*HTTPUploader) Download

func (u *HTTPUploader) Download(ctx context.Context) (io.ReadCloser, error)

Download fetches the file from the HTTP URL.

func (*HTTPUploader) GetContentType

func (*HTTPUploader) GetContentType() string

GetContentType returns the expected content type.

type OCIUploader

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

OCIUploader downloads files from OCI registries.

func NewOCIUploader

func NewOCIUploader(ctx context.Context, k8sClient client.Client, namespace string, cfg *v1alpha2.OCISource) (*OCIUploader, error)

NewOCIUploader creates a new OCI uploader from configuration.

func (*OCIUploader) Download

func (u *OCIUploader) Download(_ context.Context) (io.ReadCloser, error)

Download fetches the artifact from the OCI registry. For OCI artifacts, this returns the first layer of the image.

func (*OCIUploader) GetContentType

func (*OCIUploader) GetContentType() string

GetContentType returns the expected content type.

type S3Uploader

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

S3Uploader downloads files from S3-compatible storage.

func NewS3Uploader

func NewS3Uploader(ctx context.Context, k8sClient client.Client, namespace string, cfg *v1alpha2.S3Source) (*S3Uploader, error)

NewS3Uploader creates a new S3 uploader from configuration.

func (*S3Uploader) Download

func (u *S3Uploader) Download(ctx context.Context) (io.ReadCloser, error)

Download fetches the file from S3.

func (*S3Uploader) GetContentType

func (*S3Uploader) GetContentType() string

GetContentType returns the expected content type.

type Uploader

type Uploader interface {
	// Download fetches files from the source and returns a reader.
	// The caller is responsible for closing the reader.
	Download(ctx context.Context) (io.ReadCloser, error)

	// GetContentType returns the expected content type (for archive detection).
	GetContentType() string
}

Uploader defines the interface for fetching deployment files from various sources.

func NewUploader

func NewUploader(ctx context.Context, k8sClient client.Client, namespace string, source *v1alpha2.DirectUploadSource) (Uploader, error)

NewUploader creates an Uploader from DirectUploadSource configuration.

Jump to

Keyboard shortcuts

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