Files
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

65 lines
1.7 KiB
Go

// Copyright (c) Ultraviolet
// SPDX-License-Identifier: Apache-2.0
// Package resource provides abstractions for downloading remote resources
// from various sources (OCI registries, S3, HTTP/HTTPS).
package resource
import (
"context"
"fmt"
"sync"
)
// Downloader defines the interface for downloading resources from a remote source.
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
}
// Registry maps source type strings to Downloader implementations.
type Registry struct {
mu sync.RWMutex
downloaders map[string]Downloader
}
// NewRegistry creates a new empty downloader registry.
func NewRegistry() *Registry {
return &Registry{
downloaders: make(map[string]Downloader),
}
}
// Register adds a downloader to the registry for its declared type.
func (r *Registry) Register(d Downloader) {
r.mu.Lock()
defer r.mu.Unlock()
r.downloaders[d.Type()] = d
}
// Get retrieves a downloader for the given source type.
func (r *Registry) Get(sourceType string) (Downloader, error) {
r.mu.RLock()
defer r.mu.RUnlock()
d, ok := r.downloaders[sourceType]
if !ok {
return nil, fmt.Errorf("unsupported source type: %s", sourceType)
}
return d, nil
}
// SupportedTypes returns a list of all registered source types.
func (r *Registry) SupportedTypes() []string {
r.mu.RLock()
defer r.mu.RUnlock()
types := make([]string, 0, len(r.downloaders))
for t := range r.downloaders {
types = append(types, t)
}
return types
}