Prepare normalized processing plans and fixed chunks
This commit is contained in:
@@ -1,92 +1,16 @@
|
||||
// Package preflight checks resolved processing inputs and prepares output resources.
|
||||
// Package preflight prepares provider-independent processing inputs.
|
||||
package preflight
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/diagnostics"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/modulecatalog"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/schema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/contracts"
|
||||
)
|
||||
|
||||
// Input contains already acquired application and transcript inputs.
|
||||
type Input struct {
|
||||
InspectProfile func(context.Context, string) error
|
||||
Config *config.Config
|
||||
Transcript *schema.SourceTranscript
|
||||
Output diagnostics.OutputSelection
|
||||
InitialReports diagnostics.ReportBundle
|
||||
FailedReports diagnostics.ReportRenderer
|
||||
Debug *DebugInput
|
||||
}
|
||||
|
||||
type DebugInput struct {
|
||||
WorkDir string
|
||||
RunID string
|
||||
Metadata diagnostics.InvocationMetadata
|
||||
EffectiveConfig []byte
|
||||
}
|
||||
|
||||
type Prepared struct {
|
||||
Specs []contracts.ModuleRunSpec
|
||||
Output *diagnostics.OutputSession
|
||||
Debug *diagnostics.RunDirectory
|
||||
Warnings []error
|
||||
}
|
||||
|
||||
// Prepare validates invocation inputs and collisions before acquiring outputs.
|
||||
func Prepare(ctx context.Context, input Input) (*Prepared, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if input.Config == nil {
|
||||
return nil, fmt.Errorf("application configuration is required")
|
||||
}
|
||||
if input.Transcript == nil {
|
||||
return nil, fmt.Errorf("transcript is required")
|
||||
}
|
||||
specs, err := ProcessingPlan(ctx, input.Config, input.InspectProfile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
checked, err := diagnostics.CheckOutput(input.Output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
session := diagnostics.NewOutputSession(checked)
|
||||
if err := session.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, errors.Join(err, session.Close())
|
||||
}
|
||||
if err := session.Initialize(ctx, input.InitialReports, input.FailedReports); err != nil {
|
||||
return nil, errors.Join(err, session.Close())
|
||||
}
|
||||
cancelOutput := func(err error) error {
|
||||
return session.Finish(ctx, err, nil, input.FailedReports)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, cancelOutput(err)
|
||||
}
|
||||
result := &Prepared{Specs: specs, Output: session}
|
||||
if input.Debug != nil {
|
||||
result.Debug, result.Warnings = diagnostics.PrepareDebug(input.Debug.WorkDir, input.Debug.RunID, input.Debug.Metadata, input.Debug.EffectiveConfig)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, cancelOutput(err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// SelectionError indicates that resolved operator settings cannot be used for processing.
|
||||
type SelectionError struct{ Cause error }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user