service

package
v1.2.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRecordsPerListRequest = 1000
)
View Source
const NewVersionFromAnnotation = "flightctl.io/new-version-from"

NewVersionFromAnnotation is the annotation key set by the newversion endpoint to record lineage.

Variables

View Source
var (
	// Validation errors (4xx)
	ErrImageExportNotReady               = errors.New("imageExport is not ready")
	ErrImageExportStatusNotReady         = errors.New("imageExport status is not ready")
	ErrImageExportReadyConditionNotFound = errors.New("imageExport ready condition not found")
	ErrImageExportManifestDigestNotSet   = errors.New("imageExport manifestDigest is not set")
	ErrInvalidManifestDigest             = errors.New("invalid manifest digest")
	ErrInvalidManifestLayerCount         = errors.New("invalid manifest layer count")
	ErrRepositoryNotFound                = errors.New("repository not found")

	// External service errors (5xx - Service Unavailable)
	ErrExternalServiceUnavailable = errors.New("external service unavailable")
)

Error types for distinguishing between validation and internal errors

View Source
var (
	// ErrNotCancelable indicates the resource is not in a cancelable state
	ErrNotCancelable = errors.New("resource is not in a cancelable state")
)

Sentinel errors for cancellation operations

Functions

func IsStatusOK

func IsStatusOK(status domain.Status) bool

IsStatusOK returns true if the status code is in the 2xx range

func NilOutManagedObjectMetaProperties

func NilOutManagedObjectMetaProperties(om *domain.ObjectMeta)

NilOutManagedObjectMetaProperties clears fields that are managed by the service

func StatusBadRequest

func StatusBadRequest(message string) domain.Status

StatusBadRequest returns a 400 Bad Request status with the given message

func StatusConflict

func StatusConflict(message string) domain.Status

StatusConflict returns a 409 Conflict status with the given message

func StatusCreated

func StatusCreated() domain.Status

StatusCreated returns a 201 Created status

func StatusInternalServerError

func StatusInternalServerError(message string) domain.Status

StatusInternalServerError returns a 500 Internal Server Error status with the given message

func StatusNotFound

func StatusNotFound(message string) domain.Status

StatusNotFound returns a 404 Not Found status with the given message

func StatusOK

func StatusOK() domain.Status

StatusOK returns a 200 OK status

func StatusResourceNotFound

func StatusResourceNotFound(kind string, name string) domain.Status

StatusResourceNotFound returns a 404 status for a specific resource

func StatusServiceUnavailable

func StatusServiceUnavailable(message string) domain.Status

StatusServiceUnavailable returns a 503 Service Unavailable status with the given message

func StoreErrorToApiStatus

func StoreErrorToApiStatus(err error, created bool, kind string, name *string) domain.Status

StoreErrorToApiStatus converts a store error to an API status

func ValidateImageName

func ValidateImageName(imageName *string, path string) []error

ValidateImageName validates an OCI image repository name according to RFC specifications. Repository names must: - Consist of lowercase alphanumeric characters - May contain dots, underscores, and hyphens as separators - Cannot start or end with a separator - Components are separated by forward slashes

func ValidateImageTag

func ValidateImageTag(imageTag *string, path string) []error

ValidateImageTag validates an OCI image tag according to RFC specifications. Tags must: - Start with a word character (letter, digit, or underscore) - May contain word characters, dots, and hyphens - Cannot start with a period or dash - Maximum length is 128 characters

func ValidatePublicKey

func ValidatePublicKey(publicKey *string, path string) []error

ValidatePublicKey validates an SSH public key to prevent Containerfile injection attacks. Public key must: - Be a valid SSH public key format (starts with key type like "ssh-rsa", "ssh-ed25519", etc.) - Not contain dangerous characters that could break out of context - Have reasonable length (max 8192 characters) - Follow SSH public key format: "key-type base64-data [comment]"

func ValidateUsername

func ValidateUsername(username *string, path string) []error

ValidateUsername validates a username to prevent Containerfile injection attacks. Username must follow RHEL/Fedora useradd rules: - First char: letter, digit, underscore, or dot - Subsequent chars: letters, digits, underscore, dot, or hyphen - Optional trailing '$' (for Samba machine accounts) - '@' is NOT allowed (rejected by useradd) - Be reasonable length (max 256 characters) - Not have leading or trailing whitespace

Types

type ImageBuildService

type ImageBuildService interface {
	Create(ctx context.Context, orgId uuid.UUID, imageBuild domain.ImageBuild) (*domain.ImageBuild, domain.Status)
	Get(ctx context.Context, orgId uuid.UUID, name string, withExports bool) (*domain.ImageBuild, domain.Status)
	List(ctx context.Context, orgId uuid.UUID, params domain.ListImageBuildsParams) (*domain.ImageBuildList, domain.Status)
	Delete(ctx context.Context, orgId uuid.UUID, name string) domain.Status
	// NewVersion creates a new ImageBuild derived from an existing one with optional tag overrides.
	NewVersion(ctx context.Context, orgId uuid.UUID, parentName string, req domain.ImageBuildNewVersionRequest) (*domain.ImageBuild, domain.Status)
	// Cancel cancels an ImageBuild. Returns ErrNotCancelable if not in cancelable state.
	Cancel(ctx context.Context, orgId uuid.UUID, name string) (*domain.ImageBuild, error)
	// CancelWithReason cancels an ImageBuild with a custom reason message (e.g., for timeout).
	// Returns ErrNotCancelable if not in cancelable state.
	CancelWithReason(ctx context.Context, orgId uuid.UUID, name string, reason string) (*domain.ImageBuild, error)
	GetLogs(ctx context.Context, orgId uuid.UUID, name string, follow bool) (LogStreamReader, string, domain.Status)
	// Internal methods (not exposed via API)
	UpdateStatus(ctx context.Context, orgId uuid.UUID, imageBuild *domain.ImageBuild) (*domain.ImageBuild, error)
	UpdateLastSeen(ctx context.Context, orgId uuid.UUID, name string, timestamp time.Time) error
	UpdateLogs(ctx context.Context, orgId uuid.UUID, name string, logs string) error
}

ImageBuildService handles business logic for ImageBuild resources

func NewImageBuildService

func NewImageBuildService(s store.ImageBuildStore, repositoryStore mainstore.Repository, imageExportService ImageExportService, imagePromotionService ImagePromotionService, eventHandler *internalservice.EventHandler, queueProducer queues.QueueProducer, kvStore kvstore.KVStore, cfg *config.ImageBuilderServiceConfig, log logrus.FieldLogger) ImageBuildService

NewImageBuildService creates a new ImageBuildService

type ImageExportDownload

type ImageExportDownload struct {
	BlobReader io.ReadCloser
	Headers    http.Header
	StatusCode int
	Filename   string
}

ImageExportDownload contains information for downloading an ImageExport artifact

type ImageExportService

type ImageExportService interface {
	Create(ctx context.Context, orgId uuid.UUID, imageExport domain.ImageExport) (*domain.ImageExport, domain.Status)
	Get(ctx context.Context, orgId uuid.UUID, name string) (*domain.ImageExport, domain.Status)
	List(ctx context.Context, orgId uuid.UUID, params domain.ListImageExportsParams) (*domain.ImageExportList, domain.Status)
	Delete(ctx context.Context, orgId uuid.UUID, name string) domain.Status
	// Cancel cancels an ImageExport. Returns ErrNotCancelable if not in cancelable state.
	Cancel(ctx context.Context, orgId uuid.UUID, name string) (*domain.ImageExport, error)
	// CancelWithReason cancels an ImageExport with a custom reason message (e.g., for timeout).
	// Returns ErrNotCancelable if not in cancelable state.
	CancelWithReason(ctx context.Context, orgId uuid.UUID, name string, reason string) (*domain.ImageExport, error)
	Download(ctx context.Context, orgId uuid.UUID, name string) (*ImageExportDownload, error)
	GetLogs(ctx context.Context, orgId uuid.UUID, name string, follow bool) (LogStreamReader, string, domain.Status)
	// Internal methods (not exposed via API)
	UpdateStatus(ctx context.Context, orgId uuid.UUID, imageExport *domain.ImageExport) (*domain.ImageExport, error)
	UpdateLastSeen(ctx context.Context, orgId uuid.UUID, name string, timestamp time.Time) error
	UpdateLogs(ctx context.Context, orgId uuid.UUID, name string, logs string) error
	// ListCompletedForBuild returns the most recently completed ImageExport for the given
	// imageBuildRef and export format, or nil if none exists yet.
	ListCompletedForBuild(ctx context.Context, orgId uuid.UUID, imageBuildRef string, format domain.ExportFormatType) (*domain.ImageExport, error)
}

ImageExportService handles business logic for ImageExport resources

func NewImageExportService

func NewImageExportService(imageExportStore store.ImageExportStore, imageBuildStore store.ImageBuildStore, repositoryStore mainstore.Repository, eventHandler *internalservice.EventHandler, queueProducer queues.QueueProducer, kvStore kvstore.KVStore, cfg *config.ImageBuilderServiceConfig, log logrus.FieldLogger) ImageExportService

NewImageExportService creates a new ImageExportService

type ImagePromotionService added in v1.2.0

type ImagePromotionService interface {
	Create(ctx context.Context, orgId uuid.UUID, promotion domain.ImagePromotion) (*domain.ImagePromotion, domain.Status)
	Get(ctx context.Context, orgId uuid.UUID, name string) (*domain.ImagePromotion, domain.Status)
	List(ctx context.Context, orgId uuid.UUID, params domain.ListImagePromotionsParams) (*domain.ImagePromotionList, domain.Status)
	Delete(ctx context.Context, orgId uuid.UUID, name string) domain.Status
	// Replace implements PUT /api/v1/imagepromotions/{name}. Only spec.source.exportFormats
	// (append-only) and metadata.labels may be changed. All other spec fields must be identical.
	Replace(ctx context.Context, orgId uuid.UUID, name string, promotion domain.ImagePromotion) (*domain.ImagePromotion, domain.Status)
	// Patch implements PATCH /api/v1/imagepromotions/{name} using RFC 6902 JSON Patch.
	// Only operations targeting /spec/source/exportFormats or /metadata/labels are accepted.
	Patch(ctx context.Context, orgId uuid.UUID, name string, patch domain.PatchRequest) (*domain.ImagePromotion, domain.Status)
	// Internal methods (not exposed via API)
	UpdateStatus(ctx context.Context, orgId uuid.UUID, promotion *domain.ImagePromotion) (*domain.ImagePromotion, error)
	ListPendingForBuild(ctx context.Context, orgId uuid.UUID, imageBuildRef string) ([]domain.ImagePromotion, error)
}

ImagePromotionService handles CRUD for ImagePromotion resources. State-machine evaluation and catalog publishing are handled asynchronously by the imagebuilder worker in response to events emitted here.

func NewImagePromotionService added in v1.2.0

func NewImagePromotionService(
	store ibstore.ImagePromotionStore,
	imageBuildStore ibstore.ImageBuildStore,
	coreStore mainstore.Store,
	queueProducer queues.QueueProducer,
	log logrus.FieldLogger,
) ImagePromotionService

NewImagePromotionService creates a new ImagePromotionService.

type LogStreamReader

type LogStreamReader interface {
	// ReadAll reads all available logs from Redis and returns them as a string
	ReadAll(ctx context.Context) (string, error)
	// Stream reads logs from Redis and writes them to the provided writer
	// It blocks until the context is cancelled or an error occurs
	Stream(ctx context.Context, w io.Writer) error
}

LogStreamReader provides an interface for reading logs from Redis

type Service

type Service interface {
	ImageBuild() ImageBuildService
	ImageExport() ImageExportService
	ImagePromotion() ImagePromotionService
}

Service is the aggregate service interface for the ImageBuilder API. It provides access to all sub-services (ImageBuild, ImageExport, and future services).

func NewService

func NewService(ctx context.Context, cfg *config.Config, s imagebuilderstore.Store, mainStore mainstore.Store, queueProducer queues.QueueProducer, kvStore kvstore.KVStore, log logrus.FieldLogger) Service

NewService creates a new aggregate Service with all sub-services

Jump to

Keyboard shortcuts

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