35 lines
821 B
Go
35 lines
821 B
Go
package debug
|
|
|
|
import (
|
|
"strings"
|
|
|
|
coreworkspace "gitea.maximumdirect.net/eric/notarius/internal/core/workspace"
|
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
|
)
|
|
|
|
type WorkspaceRecorder struct {
|
|
root string
|
|
}
|
|
|
|
func NewWorkspaceRecorder(settings coreworkspace.Settings, runID string) (pipeline.DebugRecorder, error) {
|
|
root, err := settings.DebugRunDirectory(runID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if strings.TrimSpace(root) == "" {
|
|
return pipeline.NoopDebugRecorder(), nil
|
|
}
|
|
return &WorkspaceRecorder{root: root}, nil
|
|
}
|
|
|
|
func (r *WorkspaceRecorder) Enabled() bool {
|
|
return r != nil && strings.TrimSpace(r.root) != ""
|
|
}
|
|
|
|
func (r *WorkspaceRecorder) WriteJSON(name string, payload any) error {
|
|
if !r.Enabled() {
|
|
return nil
|
|
}
|
|
return coreworkspace.WriteJSON(r.root, name, payload)
|
|
}
|