artifact

package
v1.208.1-test.4 Latest Latest
Warning

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

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

Documentation

Overview

Package artifact is a generated GoMock package.

Package artifact is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTarArchive

func CreateTarArchive(files []FileEntry) ([]byte, error)

CreateTarArchive creates a tar archive from the given file entries. Each entry is read and written into the tar with 0o644 permissions. Returns the tar bytes or an error.

func GetRegisteredTypes

func GetRegisteredTypes() []string

GetRegisteredTypes returns a list of registered store types.

func Register

func Register(storeType string, factory BackendFactory)

Register registers a backend factory for the given type. Both storeType and factory must be non-empty/non-nil.

Types

type ArtifactInfo

type ArtifactInfo struct {
	// Name is the artifact name/key.
	Name string `json:"name"`

	// Size is the total size in bytes.
	Size int64 `json:"size"`

	// LastModified is when the artifact was last modified.
	LastModified time.Time `json:"last_modified"`

	// Metadata contains the artifact metadata if available.
	Metadata *Metadata `json:"metadata,omitempty"`
}

ArtifactInfo contains basic information about a stored artifact.

type Backend

type Backend interface {
	// Name returns the backend type name (e.g., "s3", "local", "github-artifacts").
	Name() string

	// Upload uploads a single data stream with the given name and metadata.
	Upload(ctx context.Context, name string, data io.Reader, size int64, metadata *Metadata) error

	// Download downloads a single data stream by name.
	// Returns the data reader, metadata, and any error.
	// Callers must close the returned io.ReadCloser when done.
	Download(ctx context.Context, name string) (io.ReadCloser, *Metadata, error)

	// Delete deletes an artifact by name.
	Delete(ctx context.Context, name string) error

	// List lists artifacts matching the given query.
	List(ctx context.Context, query Query) ([]ArtifactInfo, error)

	// Exists checks if an artifact exists.
	Exists(ctx context.Context, name string) (bool, error)

	// GetMetadata retrieves metadata for an artifact without downloading the content.
	GetMetadata(ctx context.Context, name string) (*Metadata, error)
}

Backend defines the interface for low-level artifact storage. Backends store a single data stream (typically a tar archive) plus a metadata sidecar. The BundledStore wraps a Backend to provide the higher-level Store interface that handles bundling []FileEntry into a tar archive.

type BackendFactory

type BackendFactory func(opts StoreOptions) (Backend, error)

BackendFactory is a function that creates a Backend from options.

type BundledStore

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

BundledStore implements the Store interface by wrapping a Backend. It handles bundling []FileEntry into a tar archive before delegating to the backend for single-stream storage, and unbundling on download.

func NewBundledStore

func NewBundledStore(backend Backend) *BundledStore

NewBundledStore creates a new BundledStore wrapping the given Backend.

func (*BundledStore) Delete

func (s *BundledStore) Delete(ctx context.Context, name string) error

Delete delegates directly to the backend.

func (*BundledStore) Download

func (s *BundledStore) Download(ctx context.Context, name string) ([]FileResult, *Metadata, error)

Download downloads from the backend and extracts files from the tar archive. If the metadata contains a SHA256 checksum, it verifies the integrity of the downloaded data.

func (*BundledStore) Exists

func (s *BundledStore) Exists(ctx context.Context, name string) (bool, error)

Exists delegates directly to the backend.

func (*BundledStore) GetMetadata

func (s *BundledStore) GetMetadata(ctx context.Context, name string) (*Metadata, error)

GetMetadata delegates directly to the backend.

func (*BundledStore) List

func (s *BundledStore) List(ctx context.Context, query Query) ([]ArtifactInfo, error)

List delegates directly to the backend.

func (*BundledStore) Name

func (s *BundledStore) Name() string

Name returns the backend type name.

func (*BundledStore) Upload

func (s *BundledStore) Upload(ctx context.Context, name string, files []FileEntry, metadata *Metadata) error

Upload bundles files into a tar archive, computes SHA256, and delegates to the backend.

type EnvironmentChecker

type EnvironmentChecker interface {
	// IsAvailable returns true if the backend can be used in the current environment.
	IsAvailable(ctx context.Context) bool
}

EnvironmentChecker determines whether a storage backend is available in the current environment (e.g., AWS credentials present, GitHub token set).

type FileEntry

type FileEntry struct {
	// Name is the filename within the artifact bundle.
	Name string

	// Data is the file content reader.
	Data io.Reader

	// Size is the file size in bytes (-1 if unknown).
	Size int64
}

FileEntry represents a file to be uploaded as part of an artifact bundle.

type FileResult

type FileResult struct {
	// Name is the filename within the artifact bundle.
	Name string

	// Data is the file content reader. Callers must close it when done.
	Data io.ReadCloser

	// Size is the file size in bytes (-1 if unknown).
	Size int64
}

FileResult represents a file downloaded from an artifact bundle.

func ExtractTarArchive

func ExtractTarArchive(data io.Reader) ([]FileResult, error)

ExtractTarArchive extracts all file entries from a tar archive. Returns a slice of FileResult with io.NopCloser-wrapped readers for each entry.

type Metadata

type Metadata struct {
	// Stack is the stack name.
	Stack string `json:"stack"`

	// Component is the component name.
	Component string `json:"component"`

	// SHA is the git commit SHA this artifact was generated for.
	SHA string `json:"sha"`

	// BaseSHA is the base commit SHA (target branch) for comparison.
	BaseSHA string `json:"base_sha,omitempty"`

	// Branch is the git branch this artifact was generated from.
	Branch string `json:"branch,omitempty"`

	// PRNumber is the pull request number if applicable.
	PRNumber int `json:"pr_number,omitempty"`

	// RunID is the CI run ID.
	RunID string `json:"run_id,omitempty"`

	// Repository is the repository URL or identifier.
	Repository string `json:"repository,omitempty"`

	// CreatedAt is when the artifact was created.
	CreatedAt time.Time `json:"created_at"`

	// ExpiresAt is when the artifact should be considered expired (optional).
	ExpiresAt *time.Time `json:"expires_at,omitempty"`

	// SHA256 is the SHA-256 checksum of the artifact content.
	SHA256 string `json:"sha256,omitempty"`

	// AtmosVersion is the version of Atmos that created this artifact.
	AtmosVersion string `json:"atmos_version,omitempty"`

	// Custom allows arbitrary key-value pairs for provider-specific metadata.
	Custom map[string]string `json:"custom,omitempty"`
}

Metadata contains metadata about a stored artifact.

func (*Metadata) Validate

func (m *Metadata) Validate() error

Validate checks that required metadata fields are present. Returns ErrArtifactMetadataInvalid if Stack, Component, or SHA is empty.

type MockBackend

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

MockBackend is a mock of Backend interface.

func NewMockBackend

func NewMockBackend(ctrl *gomock.Controller) *MockBackend

NewMockBackend creates a new mock instance.

func (*MockBackend) Delete

func (m *MockBackend) Delete(ctx context.Context, name string) error

Delete mocks base method.

func (*MockBackend) Download

func (m *MockBackend) Download(ctx context.Context, name string) (io.ReadCloser, *Metadata, error)

Download mocks base method.

func (*MockBackend) EXPECT

func (m *MockBackend) EXPECT() *MockBackendMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBackend) Exists

func (m *MockBackend) Exists(ctx context.Context, name string) (bool, error)

Exists mocks base method.

func (*MockBackend) GetMetadata

func (m *MockBackend) GetMetadata(ctx context.Context, name string) (*Metadata, error)

GetMetadata mocks base method.

func (*MockBackend) List

func (m *MockBackend) List(ctx context.Context, query Query) ([]ArtifactInfo, error)

List mocks base method.

func (*MockBackend) Name

func (m *MockBackend) Name() string

Name mocks base method.

func (*MockBackend) Upload

func (m *MockBackend) Upload(ctx context.Context, name string, data io.Reader, size int64, metadata *Metadata) error

Upload mocks base method.

type MockBackendMockRecorder

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

MockBackendMockRecorder is the mock recorder for MockBackend.

func (*MockBackendMockRecorder) Delete

func (mr *MockBackendMockRecorder) Delete(ctx, name any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockBackendMockRecorder) Download

func (mr *MockBackendMockRecorder) Download(ctx, name any) *gomock.Call

Download indicates an expected call of Download.

func (*MockBackendMockRecorder) Exists

func (mr *MockBackendMockRecorder) Exists(ctx, name any) *gomock.Call

Exists indicates an expected call of Exists.

func (*MockBackendMockRecorder) GetMetadata

func (mr *MockBackendMockRecorder) GetMetadata(ctx, name any) *gomock.Call

GetMetadata indicates an expected call of GetMetadata.

func (*MockBackendMockRecorder) List

func (mr *MockBackendMockRecorder) List(ctx, query any) *gomock.Call

List indicates an expected call of List.

func (*MockBackendMockRecorder) Name

func (mr *MockBackendMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name.

func (*MockBackendMockRecorder) Upload

func (mr *MockBackendMockRecorder) Upload(ctx, name, data, size, metadata any) *gomock.Call

Upload indicates an expected call of Upload.

type MockStore

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

MockStore is a mock of Store interface.

func NewMockStore

func NewMockStore(ctrl *gomock.Controller) *MockStore

NewMockStore creates a new mock instance.

func (*MockStore) Delete

func (m *MockStore) Delete(ctx context.Context, name string) error

Delete mocks base method.

func (*MockStore) Download

func (m *MockStore) Download(ctx context.Context, name string) ([]FileResult, *Metadata, error)

Download mocks base method.

func (*MockStore) EXPECT

func (m *MockStore) EXPECT() *MockStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockStore) Exists

func (m *MockStore) Exists(ctx context.Context, name string) (bool, error)

Exists mocks base method.

func (*MockStore) GetMetadata

func (m *MockStore) GetMetadata(ctx context.Context, name string) (*Metadata, error)

GetMetadata mocks base method.

func (*MockStore) List

func (m *MockStore) List(ctx context.Context, query Query) ([]ArtifactInfo, error)

List mocks base method.

func (*MockStore) Name

func (m *MockStore) Name() string

Name mocks base method.

func (*MockStore) Upload

func (m *MockStore) Upload(ctx context.Context, name string, files []FileEntry, metadata *Metadata) error

Upload mocks base method.

type MockStoreMockRecorder

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

MockStoreMockRecorder is the mock recorder for MockStore.

func (*MockStoreMockRecorder) Delete

func (mr *MockStoreMockRecorder) Delete(ctx, name any) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockStoreMockRecorder) Download

func (mr *MockStoreMockRecorder) Download(ctx, name any) *gomock.Call

Download indicates an expected call of Download.

func (*MockStoreMockRecorder) Exists

func (mr *MockStoreMockRecorder) Exists(ctx, name any) *gomock.Call

Exists indicates an expected call of Exists.

func (*MockStoreMockRecorder) GetMetadata

func (mr *MockStoreMockRecorder) GetMetadata(ctx, name any) *gomock.Call

GetMetadata indicates an expected call of GetMetadata.

func (*MockStoreMockRecorder) List

func (mr *MockStoreMockRecorder) List(ctx, query any) *gomock.Call

List indicates an expected call of List.

func (*MockStoreMockRecorder) Name

func (mr *MockStoreMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name.

func (*MockStoreMockRecorder) Upload

func (mr *MockStoreMockRecorder) Upload(ctx, name, files, metadata any) *gomock.Call

Upload indicates an expected call of Upload.

type Query

type Query struct {
	// Components filters by component names.
	Components []string

	// Stacks filters by stack names.
	Stacks []string

	// SHAs filters by git commit SHAs.
	SHAs []string

	// All returns all artifacts regardless of other filters.
	All bool
}

Query defines filter criteria for listing artifacts.

type Store

type Store interface {
	// Name returns the store type name (e.g., "s3", "azure", "gcs", "github", "local").
	Name() string

	// Upload uploads an artifact bundle to the store.
	Upload(ctx context.Context, name string, files []FileEntry, metadata *Metadata) error

	// Download downloads an artifact bundle from the store.
	Download(ctx context.Context, name string) ([]FileResult, *Metadata, error)

	// Delete deletes an artifact from the store.
	Delete(ctx context.Context, name string) error

	// List lists artifacts matching the given query.
	List(ctx context.Context, query Query) ([]ArtifactInfo, error)

	// Exists checks if an artifact exists.
	Exists(ctx context.Context, name string) (bool, error)

	// GetMetadata retrieves metadata for an artifact without downloading the content.
	GetMetadata(ctx context.Context, name string) (*Metadata, error)
}

Store defines the interface for artifact storage backends. Implementations include S3, Azure Blob, GCS, GitHub Artifacts, and local filesystem.

func NewStore

func NewStore(opts StoreOptions) (Store, error)

NewStore creates a new store from the given options. It creates a Backend via the registered factory and wraps it in a BundledStore.

func SelectStore

func SelectStore(
	ctx context.Context,
	priority []string,
	stores map[string]StoreOptions,
	checkers map[string]EnvironmentChecker,
	storeName string,
	atmosConfig *schema.AtmosConfiguration,
) (Store, error)

SelectStore selects the first available backend from the priority list, or uses the explicit storeName override if provided. Returns the store name and configured Store, or an error if none is available.

type StoreFactory

type StoreFactory func(opts StoreOptions) (Store, error)

StoreFactory is a function that creates a Store from options. Deprecated: Use BackendFactory instead. Backends are wrapped in BundledStore by the registry.

type StoreOptions

type StoreOptions struct {
	// Type is the store type (s3, azure, gcs, github, local).
	Type string

	// Options contains type-specific configuration options.
	Options map[string]any

	// AtmosConfig is the Atmos configuration.
	AtmosConfig *schema.AtmosConfiguration
}

StoreOptions contains options for creating a store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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