Adopt Audita native processing arguments
This commit is contained in:
@@ -26,7 +26,7 @@ type SubprocessRunnerConfig struct {
|
||||
Binary string
|
||||
Timeout time.Duration
|
||||
Credentials []configkit.Secret
|
||||
Modules []string
|
||||
Debug bool
|
||||
Overlay string
|
||||
ProposalProfile string
|
||||
ValidationProfile string
|
||||
@@ -49,11 +49,6 @@ func NewSubprocessRunner(cfg SubprocessRunnerConfig) (*SubprocessRunner, error)
|
||||
if cfg.Timeout <= 0 {
|
||||
return nil, fmt.Errorf("audita timeout must be > 0")
|
||||
}
|
||||
for i, module := range cfg.Modules {
|
||||
if strings.TrimSpace(module) == "" {
|
||||
return nil, fmt.Errorf("audita module at index %d is empty", i)
|
||||
}
|
||||
}
|
||||
switch strings.TrimSpace(cfg.OutputSchema) {
|
||||
case "", "bare-segments", "audita-v1":
|
||||
default:
|
||||
@@ -61,20 +56,9 @@ func NewSubprocessRunner(cfg SubprocessRunnerConfig) (*SubprocessRunner, error)
|
||||
}
|
||||
cfg.Binary = strings.TrimSpace(cfg.Binary)
|
||||
cfg.Credentials = append([]configkit.Secret(nil), cfg.Credentials...)
|
||||
cfg.Modules = cloneModules(cfg.Modules)
|
||||
for i := range cfg.Modules {
|
||||
cfg.Modules[i] = strings.TrimSpace(cfg.Modules[i])
|
||||
}
|
||||
return &SubprocessRunner{cfg: cfg, run: subprocess.Run}, nil
|
||||
}
|
||||
|
||||
func cloneModules(modules []string) []string {
|
||||
if modules == nil {
|
||||
return nil
|
||||
}
|
||||
return append([]string{}, modules...)
|
||||
}
|
||||
|
||||
// Run executes Audita process and validates its corrected transcript.
|
||||
func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishResult, error) {
|
||||
if r == nil {
|
||||
@@ -82,33 +66,24 @@ func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishRe
|
||||
}
|
||||
for _, field := range []struct{ name, value string }{
|
||||
{"merged transcript path", req.MergedTranscriptPath},
|
||||
{"glossary path", req.GlossaryPath},
|
||||
{"output processed path", req.OutputProcessedPath},
|
||||
} {
|
||||
if strings.TrimSpace(field.value) == "" {
|
||||
return PolishResult{}, fmt.Errorf("audita %s is required", field.name)
|
||||
}
|
||||
}
|
||||
modules := req.Modules
|
||||
if modules == nil {
|
||||
modules = r.cfg.Modules
|
||||
}
|
||||
for i, module := range modules {
|
||||
if strings.TrimSpace(module) == "" {
|
||||
return PolishResult{}, fmt.Errorf("audita module at index %d is empty", i)
|
||||
for i, path := range req.GlossaryFiles {
|
||||
if strings.TrimSpace(path) == "" {
|
||||
return PolishResult{}, fmt.Errorf("audita glossary file at index %d is empty", i)
|
||||
}
|
||||
}
|
||||
modules = cloneModules(modules)
|
||||
for i := range modules {
|
||||
modules[i] = strings.TrimSpace(modules[i])
|
||||
}
|
||||
args := r.buildArgs(req, modules)
|
||||
args := r.buildArgs("process", req)
|
||||
env, names, err := subprocess.CredentialEnvironment(r.cfg.Credentials)
|
||||
if err != nil {
|
||||
return PolishResult{}, fmt.Errorf("audita credentials: %w", err)
|
||||
}
|
||||
if req.GeneratedConfigPath != "" {
|
||||
if err := r.writeInvocationConfig(req, args, modules, names); err != nil {
|
||||
if err := r.writeInvocationConfig(req, args, names); err != nil {
|
||||
return PolishResult{}, fmt.Errorf("write audita invocation config %q: %w", req.GeneratedConfigPath, err)
|
||||
}
|
||||
}
|
||||
@@ -121,17 +96,17 @@ func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishRe
|
||||
EnvOverrides: env, SensitiveEnvNames: names, DiagnosticOwner: "audita",
|
||||
StdoutLogPath: req.StdoutLogPath, StderrLogPath: req.StderrLogPath,
|
||||
})
|
||||
result := r.result(req, modules, names, runRes)
|
||||
result := r.result(req, names, runRes)
|
||||
if runErr != nil {
|
||||
result.Reports, _ = discoverReports(req.OutputProcessedPath)
|
||||
result.Reports, _ = discoverReports(reportDirectory(req))
|
||||
return result, fmt.Errorf("run audita process (binary=%q, output_dir=%q, stdout_log=%q, stderr_log=%q): %w",
|
||||
r.cfg.Binary, filepath.Dir(req.OutputProcessedPath), req.StdoutLogPath, req.StderrLogPath, runErr)
|
||||
}
|
||||
if err := validateProcessedOutput(req.OutputProcessedPath); err != nil {
|
||||
result.Reports, _ = discoverReports(req.OutputProcessedPath)
|
||||
result.Reports, _ = discoverReports(reportDirectory(req))
|
||||
return result, fmt.Errorf("validate audita processed output %q: %w", req.OutputProcessedPath, err)
|
||||
}
|
||||
reports, err := discoverReports(req.OutputProcessedPath)
|
||||
reports, err := discoverReports(reportDirectory(req))
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -139,14 +114,14 @@ func (r *SubprocessRunner) Run(ctx context.Context, req PolishRequest) (PolishRe
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *SubprocessRunner) result(req PolishRequest, modules, names []string, runRes subprocess.RunResult) PolishResult {
|
||||
func (r *SubprocessRunner) result(req PolishRequest, names []string, runRes subprocess.RunResult) PolishResult {
|
||||
return PolishResult{
|
||||
ProcessedTranscriptPath: req.OutputProcessedPath,
|
||||
StdoutLogPath: req.StdoutLogPath, StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath, ExitCode: runRes.ExitCode,
|
||||
Duration: runRes.Duration, InvokedBinary: r.cfg.Binary,
|
||||
Metadata: map[string]any{
|
||||
"adapter": "audita_subprocess", "modules": modules,
|
||||
"adapter": "audita_subprocess", "glossary_files": req.GlossaryFiles, "report_dir": req.ReportDir, "work_dir": req.WorkDir, "debug": r.cfg.Debug,
|
||||
"overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile,
|
||||
"validation_profile": r.cfg.ValidationProfile,
|
||||
"transcript_description": r.cfg.TranscriptDescription,
|
||||
@@ -156,37 +131,45 @@ func (r *SubprocessRunner) result(req PolishRequest, modules, names []string, ru
|
||||
}
|
||||
}
|
||||
|
||||
func (r *SubprocessRunner) buildArgs(req PolishRequest, modules []string) []string {
|
||||
args := []string{"process", req.MergedTranscriptPath, "--glossary", req.GlossaryPath, "--output", req.OutputProcessedPath}
|
||||
if modules != nil {
|
||||
args = append(args, "--modules", strings.Join(modules, ","))
|
||||
func (r *SubprocessRunner) buildArgs(command string, req PolishRequest) []string {
|
||||
args := []string{command, req.MergedTranscriptPath, "--output", req.OutputProcessedPath}
|
||||
for _, path := range req.GlossaryFiles {
|
||||
args = append(args, "--glossary-file", path)
|
||||
}
|
||||
for _, setting := range []struct{ flag, value string }{
|
||||
{"--config", r.cfg.ConfigPath}, {"--overlay", r.cfg.Overlay},
|
||||
{"--proposal-profile", r.cfg.ProposalProfile}, {"--validation-profile", r.cfg.ValidationProfile},
|
||||
{"--transcript-description", r.cfg.TranscriptDescription}, {"--output-schema", r.cfg.OutputSchema},
|
||||
{"--report-dir", req.ReportDir}, {"--work-dir", req.WorkDir},
|
||||
} {
|
||||
if setting.value != "" {
|
||||
args = append(args, setting.flag, setting.value)
|
||||
}
|
||||
}
|
||||
if r.cfg.Debug {
|
||||
args = append(args, "--debug")
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
func (r *SubprocessRunner) writeInvocationConfig(req PolishRequest, args, modules, names []string) error {
|
||||
func (r *SubprocessRunner) writeInvocationConfig(req PolishRequest, args, names []string) error {
|
||||
return writeGeneratedYAML(req.GeneratedConfigPath, map[string]any{
|
||||
"schema": "audita.generated.v2", "binary": r.cfg.Binary, "args": args,
|
||||
"timeout": r.cfg.Timeout.String(), "modules": modules,
|
||||
"overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile,
|
||||
"validation_profile": r.cfg.ValidationProfile,
|
||||
"transcript_description": r.cfg.TranscriptDescription,
|
||||
"config_path": r.cfg.ConfigPath, "output_schema": r.cfg.OutputSchema,
|
||||
"merged_transcript_path": req.MergedTranscriptPath, "glossary_path": req.GlossaryPath,
|
||||
"output_path": req.OutputProcessedPath, "credential_names": names,
|
||||
"schema": "audita.generated.v3", "binary": r.cfg.Binary, "args": args, "timeout": r.cfg.Timeout.String(),
|
||||
"glossary_files": req.GlossaryFiles, "report_dir": req.ReportDir, "work_dir": req.WorkDir, "debug": r.cfg.Debug,
|
||||
"overlay": r.cfg.Overlay, "proposal_profile": r.cfg.ProposalProfile, "validation_profile": r.cfg.ValidationProfile,
|
||||
"transcript_description": r.cfg.TranscriptDescription, "config_path": r.cfg.ConfigPath, "output_schema": r.cfg.OutputSchema,
|
||||
"merged_transcript_path": req.MergedTranscriptPath, "output_path": req.OutputProcessedPath, "credential_names": names,
|
||||
})
|
||||
}
|
||||
|
||||
func discoverReports(outputPath string) (ReportBundle, error) {
|
||||
func reportDirectory(req PolishRequest) string {
|
||||
if req.ReportDir != "" {
|
||||
return req.ReportDir
|
||||
}
|
||||
return filepath.Dir(req.OutputProcessedPath)
|
||||
}
|
||||
|
||||
func discoverReports(reportDir string) (ReportBundle, error) {
|
||||
var reports ReportBundle
|
||||
for _, report := range []struct {
|
||||
name string
|
||||
@@ -196,7 +179,7 @@ func discoverReports(outputPath string) (ReportBundle, error) {
|
||||
{"recoveries.yml", &reports.RecoveriesPath},
|
||||
{"report.md", &reports.OverviewPath},
|
||||
} {
|
||||
path := filepath.Join(filepath.Dir(outputPath), report.name)
|
||||
path := filepath.Join(reportDir, report.name)
|
||||
info, err := os.Lstat(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user