objects

package
v2.4.1 Latest Latest
Warning

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

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

Documentation

Overview

Package objects provides storage orchestration layer that combines clientpool provider resolution with objects/storage pure operations to enable multi-tenant file storage management.

Index

Constants

View Source
const (
	// DefaultClientPoolTTL is the default TTL for client pool entries.
	DefaultClientPoolTTL = 15 * time.Minute
	// DefaultDevStorageBucket is used when a development storage bucket is required but not provided.
	DefaultDevStorageBucket = "/tmp/dev-storage"
	// DefaultS3Region is used when no region is specified for S3-compatible providers.
	DefaultS3Region = "us-east-1"
	// DefaultLocalDiskURL is the default local URL for disk storage providers.
	DefaultLocalDiskURL = "http://localhost:17608/files"
)
View Source
const TemplateKindMetadataKey = "template_kind"

Variables

View Source
var (
	// ErrProviderResolutionFailed is returned when storage provider resolution failed
	ErrProviderResolutionFailed = errors.New("storage provider resolution failed")
	// ErrProviderCreationFailed is returned when storage provider creation failed
	ErrProviderCreationFailed = errors.New("storage provider creation failed")
	// ErrInvalidUploadOptions is returned when invalid upload options provided
	ErrInvalidUploadOptions = errors.New("invalid upload options")
	// ErrInvalidIntegration is returned when an invalid integration is provided
	ErrInvalidIntegration = errors.New("invalid integration provided")
	// ErrNoOrganizationID is returned when no organization ID is available
	ErrNoOrganizationID = errors.New("no organization ID available")
	// ErrMissingIntegrationID is returned when integration ID is missing
	ErrMissingIntegrationID = errors.New("integration ID is missing")
	// ErrMissingHushID is returned when hush ID is missing
	ErrMissingHushID = errors.New("hush ID is missing")
	// ErrSystemIntegrationMissingOrgID is returned when system integration is missing organization ID
	ErrSystemIntegrationMissingOrgID = errors.New("system integration missing organization ID")
	// ErrNoIntegrationOrCredentials is returned when no integration or credentials are available
	ErrNoIntegrationOrCredentials = errors.New("no integration or credentials available")
	// ErrNoSystemIntegration is returned when no system integration is found for a provider
	ErrNoSystemIntegration = errors.New("no system integration found")
	// ErrNoIntegrationWithSecrets is returned when an integration lacks associated secrets
	ErrNoIntegrationWithSecrets = errors.New("no active integration with secrets found")
	// ErrMissingFileID is returned when file ID is required but missing
	ErrMissingFileID = errors.New("file id required for presigned URL")
	// ErrMissingFile is returned when the file is nul
	ErrMissingFile = errors.New("file is not set")
)

Functions

func ApplyProviderHints

func ApplyProviderHints(ctx context.Context, hints *storagetypes.ProviderHints) context.Context

ApplyProviderHints injects hint values into the resolution context using typed context values

func PopulateProviderHints

func PopulateProviderHints(file *pkgobjects.File, orgID string)

PopulateProviderHints ensures standard metadata is present on the file's provider hints

func ResolveModuleFromFile

func ResolveModuleFromFile(f pkgobjects.File) (models.OrgModule, bool)

ResolveModuleFromFile attempts to determine the module associated with the upload

func SetTemplateKindHint

func SetTemplateKindHint(file *pkgobjects.File, kind enums.TemplateKind)

SetTemplateKindHint sets the template kind hint on the file's provider hints

func WithBackupSourceHint added in v2.4.1

func WithBackupSourceHint(ctx context.Context, source storagetypes.ProviderType) context.Context

WithBackupSourceHint returns a context that resolves to the backup destination configured for the given source provider.

func WithKnownProviderHint

func WithKnownProviderHint(ctx context.Context, provider storagetypes.ProviderType) context.Context

WithKnownProviderHint returns a context with the known provider hint set.

func WithModuleHint

func WithModuleHint(ctx context.Context, module models.OrgModule) context.Context

WithModuleHint returns a context with the module hint set.

func WithTemplateKindHint

func WithTemplateKindHint(ctx context.Context, kind enums.TemplateKind) context.Context

WithTemplateKindHint returns a context with the template kind hint set.

Types

type BackupResult added in v2.4.1

type BackupResult struct {
	// Provider is the destination provider the file was replicated to
	Provider storage.ProviderType
	// Bucket is the destination bucket the backup was written to
	Bucket string
	// Key is the object key at the destination, which is not guaranteed to match the source
	// key because each provider derives its own
	Key string
	// Region is the destination region, if applicable
	Region string
	// URI is the full URI of the replicated object at the destination
	URI string
	// Bytes is the number of bytes replicated
	Bytes int64
}

BackupResult describes where a file was replicated during a backup operation

type BackupSourceHint added in v2.4.1

type BackupSourceHint storagetypes.ProviderType

BackupSourceHint names the source provider whose backup destination should be resolved, so a write to a backup goes through the same rule chain as any other provider lookup

func BackupSourceHintFromContext added in v2.4.1

func BackupSourceHintFromContext(ctx context.Context) (BackupSourceHint, bool)

BackupSourceHintFromContext returns the backup source hint when present.

type BackupTarget added in v2.4.1

type BackupTarget struct {
	// Provider is the backup destination provider
	Provider storage.Provider
	// ReadFromBackup serves reads from this target instead of the source provider
	ReadFromBackup bool
}

BackupTarget pairs a backup destination provider with the behavior configured for it

type Config

type Config struct {
	// Resolver selects the storage provider to use for a given request from context hints
	Resolver *eddy.Resolver[storage.Provider, storage.ProviderCredentials, *storage.ProviderOptions]
	// ClientService caches and returns provider clients built by the resolver
	ClientService *eddy.ClientService[storage.Provider, storage.ProviderCredentials, *storage.ProviderOptions]
	// ValidationFunc validates files before upload
	ValidationFunc storage.ValidationFunc
	// Backups maps a source provider type to its backup destination target
	Backups map[storage.ProviderType]BackupTarget
}

Config holds configuration for creating a new Service

type KnownProviderHint

type KnownProviderHint storagetypes.ProviderType

func KnownProviderHintFromContext

func KnownProviderHintFromContext(ctx context.Context) (KnownProviderHint, bool)

KnownProviderHintFromContext returns the known provider hint when present.

type ModuleHint

type ModuleHint models.OrgModule

Typed context hint strings

func ModuleHintFromContext

func ModuleHintFromContext(ctx context.Context) (ModuleHint, bool)

ModuleHintFromContext returns the module hint when present.

type PreferredProviderHint

type PreferredProviderHint storagetypes.ProviderType

func PreferredProviderHintFromContext

func PreferredProviderHintFromContext(ctx context.Context) (PreferredProviderHint, bool)

PreferredProviderHintFromContext returns the preferred provider hint when present.

type ProviderCacheKey

type ProviderCacheKey struct {
	// TenantID is the organization the cached provider client belongs to
	TenantID string
	// IntegrationType is the provider type the client was built for, e.g. s3
	IntegrationType string
}

ProviderCacheKey implements eddy.CacheKey for provider caching

func (ProviderCacheKey) String

func (k ProviderCacheKey) String() string

String returns the cache key as a string

type Service

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

Service orchestrates storage operations using eddy provider resolution

func NewService

func NewService(cfg Config) *Service

NewService creates a new storage orchestration service

func (*Service) Backup added in v2.4.1

func (s *Service) Backup(ctx context.Context, file *storagetypes.File) (*BackupResult, error)

Backup replicates a file from its source provider to the configured backup destination for that provider no backup provider defined is a no-op

func (*Service) BackupProviderFor added in v2.4.1

func (s *Service) BackupProviderFor(source storage.ProviderType) (storage.Provider, bool)

BackupProviderFor returns the configured backup destination provider for a source provider type, if one is configured. When absent, the source provider has no backup and behaves as today.

func (*Service) BackupSources added in v2.4.1

func (s *Service) BackupSources() []storage.ProviderType

BackupSources returns the source provider types that have a backup destination configured

func (*Service) Delete

Delete deletes a file using provider resolution

func (*Service) DeleteBackup added in v2.4.1

func (s *Service) DeleteBackup(ctx context.Context, file *storagetypes.File, opts *storagetypes.DeleteFileOptions) error

DeleteBackup deletes the replica of a file from its backup provider so the replica shares the lifetime of the object it backs up. Files with no usable replica, or whose source provider has no backup configured, are a no-op

func (*Service) Download

Download downloads a file using provider resolution

func (*Service) ErrorResponseHandler

func (s *Service) ErrorResponseHandler() storage.ErrResponseHandler

ErrorResponseHandler returns the configured error response handler

func (*Service) Exists

func (s *Service) Exists(ctx context.Context, file *storagetypes.File) (bool, error)

Exists checks if a file exists using provider resolution

func (*Service) GetPresignedURL

func (s *Service) GetPresignedURL(ctx context.Context, file *storagetypes.File, duration time.Duration) (string, error)

GetPresignedURL gets a presigned URL for a file using provider resolution

func (*Service) IgnoreNonExistentKeys

func (s *Service) IgnoreNonExistentKeys() bool

IgnoreNonExistentKeys returns whether to ignore non-existent form keys

func (*Service) Keys

func (s *Service) Keys() []string

Keys returns the configured form keys

func (*Service) MaxSize

func (s *Service) MaxSize() int64

MaxSize returns the configured maximum file size

func (*Service) ReadFromBackupFor added in v2.4.1

func (s *Service) ReadFromBackupFor(source storage.ProviderType) (storage.Provider, bool)

ReadFromBackupFor returns the backup destination provider for a source provider when reads are configured to be served from the backup instead of the source

func (*Service) Skipper

func (s *Service) Skipper() storage.SkipperFunc

Skipper returns the configured skipper function

func (*Service) Upload

func (s *Service) Upload(ctx context.Context, reader io.Reader, opts *storage.UploadOptions) (*pkgobjects.File, error)

Upload uploads a file using provider resolution

type SizeBytesHint

type SizeBytesHint int64

func SizeBytesHintFromContext

func SizeBytesHintFromContext(ctx context.Context) (SizeBytesHint, bool)

SizeBytesHintFromContext returns the size hint when present.

type TemplateKindHint

type TemplateKindHint enums.TemplateKind

func TemplateKindHintFromContext

func TemplateKindHintFromContext(ctx context.Context) (TemplateKindHint, bool)

TemplateKindHintFromContext returns the template kind hint when present.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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