58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
|
|
package pipeline
|
||
|
|
|
||
|
|
import (
|
||
|
|
"errors"
|
||
|
|
"path"
|
||
|
|
|
||
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/fileio"
|
||
|
|
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||
|
|
)
|
||
|
|
|
||
|
|
type scopedEvidence struct {
|
||
|
|
writer contracts.EvidenceWriter
|
||
|
|
prefix string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (scope scopedEvidence) WriteJSON(name string, value any) error {
|
||
|
|
return scope.writer.WriteJSON(path.Join(scope.prefix, name), value)
|
||
|
|
}
|
||
|
|
func (scope scopedEvidence) WriteBytes(name string, value []byte) error {
|
||
|
|
return scope.writer.WriteBytes(path.Join(scope.prefix, name), value)
|
||
|
|
}
|
||
|
|
func scopeEvidence(writer contracts.EvidenceWriter, prefix string) contracts.EvidenceWriter {
|
||
|
|
if writer == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return scopedEvidence{writer: writer, prefix: prefix}
|
||
|
|
}
|
||
|
|
|
||
|
|
func operationExecution(input RunInput, origin contracts.DiagnosticOrigin, chunk *source.Chunk) contracts.ExecutionOptions {
|
||
|
|
options := input.Execution
|
||
|
|
writer := options.Capture
|
||
|
|
if writer == nil && input.Debug != nil && input.Debug.Enabled() {
|
||
|
|
writer = input.Debug
|
||
|
|
}
|
||
|
|
prefix := "operations"
|
||
|
|
if origin.StepID != "" {
|
||
|
|
prefix = path.Join(prefix, "steps", fileio.EncodePathComponent(origin.StepID))
|
||
|
|
}
|
||
|
|
prefix = path.Join(prefix, string(origin.Stage))
|
||
|
|
if origin.LaneID != "" {
|
||
|
|
prefix = path.Join(prefix, "lanes", fileio.EncodePathComponent(origin.LaneID))
|
||
|
|
}
|
||
|
|
if chunk != nil {
|
||
|
|
prefix = path.Join(prefix, "chunks", fileio.EncodePathComponent(chunk.ID))
|
||
|
|
}
|
||
|
|
prefix = path.Join(prefix, "modules", fileio.EncodePathComponent(origin.ModuleKey))
|
||
|
|
options.Capture = scopeEvidence(writer, prefix)
|
||
|
|
return options
|
||
|
|
}
|
||
|
|
|
||
|
|
func captureFailure(primary, recording error) error {
|
||
|
|
if recording == nil {
|
||
|
|
return primary
|
||
|
|
}
|
||
|
|
return errors.Join(primary, recording)
|
||
|
|
}
|